<commit_before>import numpy as np
from nose.tools import assert_is_instance, assert_equal
from nose import with_setup

import cfunits

from .utils import setup_func, teardown_func, all_grids, all_names, new_bmi


@with_setup(setup_func, teardown_func)
def test_get_var_grid():
    """Test the grid of the variables."""
    bmi = new_bmi()
    for name in all_grids(bmi):
        gid = bmi.get_var_grid(name)
        def _check_var_grid_is_int(_gid):
            assert_is_instance(_gid, int)
        _check_var_grid_is_int.description = 'Test grid id is int'

        yield _check_var_grid_is_int, gid


@with_setup(setup_func, teardown_func)
def test_get_var_itemsize():
    """Test getting a variable's itemsize"""
    bmi = new_bmi()
    for name in all_names(bmi):
        def _check_var_itemsize(bmi, _name):
            val = bmi.get_value(_name)
            itemsize = val.flatten()[0].nbytes
            np.testing.assert_equal(itemsize, bmi.get_var_itemsize(_name))

        _check_var_itemsize.description = "Test get_var_itemsize for {name}".format(name=name)

        yield _check_var_itemsize, bmi, name


@with_setup(setup_func, teardown_func)
def test_get_var_nbytes():
    """Test getting a variable's nbytes"""
    bmi = new_bmi()<commit_msg>Fix bug in get_var_grid test.<commit_after>import numpy as np
from nose.tools import assert_is_instance, assert_equal
from nose import with_setup

import cfunits

from .utils import setup_func, teardown_func, all_grids, all_names, new_bmi


@with_setup(setup_func, teardown_func)
def test_get_var_grid():
    """Test the grid of the variables."""
    bmi = new_bmi()
    for name in all_names(bmi):
        gid = bmi.get_var_grid(name)
        def _check_var_grid_is_int(_gid):
            assert_is_instance(_gid, int)
        _check_var_grid_is_int.description = 'Test grid id is int'

        yield _check_var_grid_is_int, gid


@with_setup(setup_func, teardown_func)
def test_get_var_itemsize():
    """Test getting a variable's itemsize"""
    bmi = new_bmi()
    for name in all_names(bmi):
        def _check_var_itemsize(bmi, _name):
            val = bmi.get_value(_name)
            itemsize = val.flatten()[0].nbytes
            np.testing.assert_equal(itemsize, bmi.get_var_itemsize(_name))

        _check_var_itemsize.description = "Test get_var_itemsize for {name}".format(name=name)

        yield _check_var_itemsize, bmi, name


@with_setup(setup_func, teardown_func)
def test_get_var_nbytes():
    """Test getting a variable's nbytes"""
    bmi = new_bmi()
{'fraction_non_alphanumeric': 0.09273875295974743, 'fraction_numerical': 0.0007892659826361484, 'mean_word_length': 3.7294776119402986, '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': '2460902', 'n_tokens_mistral': 900, 'n_tokens_neox': 877, 'n_words': 199}