

def setUp(self):
    MNIST_IMAGE_MAGIC = 2051
    MNIST_LABEL_MAGIC = 2049
    numpy.random.seed(((9 + 5) + 2015))
    self.train_features_mock = numpy.random.randint(0, 256, (10, 1, 28, 28)).astype('uint8')
    self.train_targets_mock = numpy.random.randint(0, 10, (10, 1)).astype('uint8')
    self.test_features_mock = numpy.random.randint(0, 256, (10, 1, 28, 28)).astype('uint8')
    self.test_targets_mock = numpy.random.randint(0, 10, (10, 1)).astype('uint8')
    self.tempdir = tempfile.mkdtemp()
    self.train_images_path = os.path.join(self.tempdir, 'train-images-idx3-ubyte.gz')
    self.train_labels_path = os.path.join(self.tempdir, 'train-labels-idx1-ubyte.gz')
    self.test_images_path = os.path.join(self.tempdir, 't10k-images-idx3-ubyte.gz')
    self.test_labels_path = os.path.join(self.tempdir, 't10k-labels-idx1-ubyte.gz')
    self.wrong_images_path = os.path.join(self.tempdir, 'wrong_images.gz')
    self.wrong_labels_path = os.path.join(self.tempdir, 'wrong_labels.gz')
    with gzip.open(self.train_images_path, 'wb') as f:
        f.write(struct.pack('>iiii', *(MNIST_IMAGE_MAGIC, 10, 28, 28)))
        f.write(getbuffer(self.train_features_mock.flatten()))
    with gzip.open(self.train_labels_path, 'wb') as f:
        f.write(struct.pack('>ii', *(MNIST_LABEL_MAGIC, 10)))
        f.write(getbuffer(self.train_targets_mock.flatten()))
    with gzip.open(self.test_images_path, 'wb') as f:
        f.write(struct.pack('>iiii', *(MNIST_IMAGE_MAGIC, 10, 28, 28)))
        f.write(getbuffer(self.test_features_mock.flatten()))
    with gzip.open(self.test_labels_path, 'wb') as f:
        f.write(struct.pack('>ii', *(MNIST_LABEL_MAGIC, 10)))
        f.write(getbuffer(self.test_targets_mock.flatten()))
    with gzip.open(self.wrong_images_path, 'wb') as f:
        f.write(struct.pack('>iiii', *(2000, 10, 28, 28)))
    with gzip.open(self.wrong_labels_path, 'wb') as f:
        f.write(struct.pack('>ii', *(2000, 10)))

dataset/ETHPy150Open mila-udem/fuel/tests/test_converters.py TestMNIST.setUp/original