<commit_before>from numpy.testing import assert_raises

from fuel.datasets import BinarizedMNIST
from tests import skip_if_not_available


def test_binarized_mnist():
    skip_if_not_available(datasets=['binarized_mnist'])

    mnist_train = BinarizedMNIST('train')
    handle = mnist_train.open()
    data = mnist_train.get_data(handle, slice(0, 50000))[0]
    assert data.shape == (50000, 1, 28, 28)
    assert mnist_train.num_examples == 50000
    mnist_train.close(handle)

    mnist_valid = BinarizedMNIST('valid')
    handle = mnist_valid.open()
    data = mnist_valid.get_data(handle, slice(0, 10000))[0]
    assert data.shape == (10000, 1, 28, 28)
    assert mnist_valid.num_examples == 10000
    mnist_valid.close(handle)

    mnist_test = BinarizedMNIST('test')
    handle = mnist_test.open()
    data = mnist_test.get_data(handle, slice(0, 10000))[0]
    assert data.shape == (10000, 1, 28, 28)
    assert mnist_test.num_examples == 10000
    mnist_test.close(handle)

    assert_raises(ValueError, BinarizedMNIST, 'dummy')

    mnist_test_flattened = BinarizedMNIST(
        'test', flatten=['features'], load_in_memory=True)
    handle = mnist_test_flattened.open()
    data = mnist_test_flattened.get_data(handle, slice(0, 10000))[0]
    assert data.shape == (10000, 784)
    mnist_test_flattened.close(handle)<commit_msg>Refactor binarized MNIST tests<commit_after>import os

from numpy.testing import assert_raises

from fuel import config
from fuel.datasets import BinarizedMNIST
from tests import skip_if_not_available


def test_binarized_mnist_train():
    skip_if_not_available(datasets=['binarized_mnist'])

    mnist_train = BinarizedMNIST('train')
    handle = mnist_train.open()
    data = mnist_train.get_data(handle, slice(0, 50000))[0]
    assert data.shape == (50000, 1, 28, 28)
    assert mnist_train.num_examples == 50000
    mnist_train.close(handle)


def test_binarized_mnist_valid():
    skip_if_not_available(datasets=['binarized_mnist'])

    mnist_valid = BinarizedMNIST('valid')
    handle = mnist_valid.open()
    data = mnist_valid.get_data(handle, slice(0, 10000))[0]
    assert data.shape == (10000, 1, 28, 28)
    assert mnist_valid.num_examples == 10000
    mnist_valid.close(handle)


def test_binarized_mnist_test():
    skip_if_not_available(datasets=['binarized_mnist'])

    mnist_test = BinarizedMNIST('test')
    handle = mnist_test.open()
    data = mnist_test.get_data(handle, slice(0, 10000))[0]
    assert data.shape == (10000, 1, 28, 28)
    assert mnist_test.num_examples == 10000
    mnist_test.close(handle)


def test_binarized_mnist_invalid_split():
    assert_raises(ValueError, BinarizedMNIST, 'dummy')


def test_binarized_mnist_data_path():
    assert BinarizedMNIST('train').data_path == os.path.join(
        config.data_path, 'binarized_mnist.hdf5')
{'fraction_non_alphanumeric': 0.11284599006387509, 'fraction_numerical': 0.0525195173882186, 'mean_word_length': 4.729674796747967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2109691', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1019, 'n_words': 183}