<commit_before>import unittest

import numpy
from numpy.testing import assert_array_equal
from tvtk.api import tvtk

from simphony.core.cuba import CUBA
from simphony.testing.utils import create_data_container, dummy_cuba_value

from simphony_mayavi.core.api import CUBADataAccumulator


class TestCUBADataAccumulator(unittest.TestCase):

    def test_accumulate(self):
        cuds_data = [create_data_container() for i in range(10)]
        accumulator = CUBADataAccumulator()
        for data in cuds_data:
            accumulator.append(data)

        self.assertEqual(len(accumulator), 10)
        self.assertEqual(accumulator.keys, set(CUBA))
        for cuba in CUBA:
            assert_array_equal(
                accumulator[cuba], [dummy_cuba_value(cuba)] * 10)

    def test_accumulate_on_keys(self):
        cuds_data = [create_data_container() for i in range(10)]
        accumulator = CUBADataAccumulator(keys=[CUBA.NAME, CUBA.TEMPERATURE])
        for data in cuds_data:
            accumulator.append(data)

        self.assertEqual(len(accumulator), 10)
        self.assertEqual(accumulator.keys, set([CUBA.NAME, CUBA.TEMPERATURE]))
        for cuba in [CUBA.NAME, CUBA.TEMPERATURE]:
            assert_array_equal(
                accumulator[cuba], [dummy_cuba_value(cuba)] * 10)

    def test_accumulate_with_missing_values(self):
        accumulator = CUBADataAccumulator()
        accumulator.append(create_data_container())
        accumulator.append(
            create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE]))

        self.assertEqual(len(accumulator), 2)
        self.assertEqual(accumulator.keys, set(CUBA))
        for cuba in CUBA:
            if cuba in [CUBA.NAME, CUBA.TEMPERATURE]:
                assert_array_equal(
                    accumulator[cuba], [dummy_cuba_value(cuba)] * 2)
            else:
                assert_array_equal(
                    accumulator[cuba][0], dummy_cuba_value(cuba))
                self.assertIsNone(accumulator[cuba][1])

    def test_accumulate_and_expand(self):
        accumulator = CUBADataAccumulator()
        accumulator.append(create_data_container(restrict=[CUBA.NAME]))
        accumulator.append(
            create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE]))

        self.assertEqual(len(accumulator), 2)
        self.assertEqual(accumulator.keys, set([CUBA.NAME, CUBA.TEMPERATURE]))
        assert_array_equal(
            accumulator[CUBA.TEMPERATURE],
            [None, dummy_cuba_value(CUBA.TEMPERATURE)])
        assert_array_equal(
            accumulator[CUBA.NAME],
            [dummy_cuba_value(CUBA.NAME)] * 2)

    def test_load_scalars_onto_vtk(self):
        accumulator = CUBADataAccumulator()
        accumulator.append(create_data_container(restrict=[CUBA.NAME]))
        accumulator.append(
            create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE]))

        vtk_data = tvtk.PointData()
        accumulator.load_onto_vtk(vtk_data)
        self.assertEqual(vtk_data.number_of_arrays, 1)
        expected = numpy.array(
            [None, dummy_cuba_value(CUBA.TEMPERATURE)], dtype=float)
        assert_array_equal(vtk_data.get_array(0), expected)
        assert_array_equal(vtk_data.get_array(CUBA.TEMPERATURE.name), expected)

    def test_load_vectors_onto_vtk(self):
        accumulator = CUBADataAccumulator()
        accumulator.append(create_data_container(restrict=[CUBA.NAME]))
        accumulator.append(
            create_data_container(restrict=[CUBA.NAME, CUBA.VELOCITY,
                                            CUBA.LATTICE_VECTORS,
                                            CUBA.STRAIN_TENSOR]))

        vtk_data = tvtk.PointData()
        accumulator.load_onto_vtk(vtk_data)
        self.assertEqual(vtk_data.number_of_arrays, 1)
        expected = numpy.array(
            [[None, None, None], dummy_cuba_value(CUBA.VELOCITY)], dtype=float)
        assert_array_equal(vtk_data.get_array(0), expected)
        assert_array_equal(vtk_data.get_array(CUBA.VELOCITY.name), expected)<commit_msg>common 0.3.0 does not have STRAINS_TENSOR yes<commit_after>import unittest

import numpy
from numpy.testing import assert_array_equal
from tvtk.api import tvtk

from simphony.core.cuba import CUBA
from simphony.testing.utils import create_data_container, dummy_cuba_value

from simphony_mayavi.core.api import CUBADataAccumulator


class TestCUBADataAccumulator(unittest.TestCase):

    def test_accumulate(self):
        cuds_data = [create_data_container() for i in range(10)]
        accumulator = CUBADataAccumulator()
        for data in cuds_data:
            accumulator.append(data)

        self.assertEqual(len(accumulator), 10)
        self.assertEqual(accumulator.keys, set(CUBA))
        for cuba in CUBA:
            assert_array_equal(
                accumulator[cuba], [dummy_cuba_value(cuba)] * 10)

    def test_accumulate_on_keys(self):
        cuds_data = [create_data_container() for i in range(10)]
        accumulator = CUBADataAccumulator(keys=[CUBA.NAME, CUBA.TEMPERATURE])
        for data in cuds_data:
            accumulator.append(data)

        self.assertEqual(len(accumulator), 10)
        self.assertEqual(accumulator.keys, set([CUBA.NAME, CUBA.TEMPERATURE]))
        for cuba in [CUBA.NAME, CUBA.TEMPERATURE]:
            assert_array_equal(
                accumulator[cuba], [dummy_cuba_value(cuba)] * 10)

    def test_accumulate_with_missing_values(self):
        accumulator = CUBADataAccumulator()
        accumulator.append(create_data_container())
        accumulator.append(
            create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE]))

        self.assertEqual(len(accumulator), 2)
        self.assertEqual(accumulator.keys, set(CUBA))
        for cuba in CUBA:
            if cuba in [CUBA.NAME, CUBA.TEMPERATURE]:
                assert_array_equal(
                    accumulator[cuba], [dummy_cuba_value(cuba)] * 2)
            else:
                assert_array_equal(
                    accumulator[cuba][0], dummy_cuba_value(cuba))
                self.assertIsNone(accumulator[cuba][1])

    def test_accumulate_and_expand(self):
        accumulator = CUBADataAccumulator()
        accumulator.append(create_data_container(restrict=[CUBA.NAME]))
        accumulator.append(
            create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE]))

        self.assertEqual(len(accumulator), 2)
        self.assertEqual(accumulator.keys, set([CUBA.NAME, CUBA.TEMPERATURE]))
        assert_array_equal(
            accumulator[CUBA.TEMPERATURE],
            [None, dummy_cuba_value(CUBA.TEMPERATURE)])
        assert_array_equal(
            accumulator[CUBA.NAME],
            [dummy_cuba_value(CUBA.NAME)] * 2)

    def test_load_scalars_onto_vtk(self):
        accumulator = CUBADataAccumulator()
        accumulator.append(create_data_container(restrict=[CUBA.NAME]))
        accumulator.append(
            create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE]))

        vtk_data = tvtk.PointData()
        accumulator.load_onto_vtk(vtk_data)
        self.assertEqual(vtk_data.number_of_arrays, 1)
        expected = numpy.array(
            [None, dummy_cuba_value(CUBA.TEMPERATURE)], dtype=float)
        assert_array_equal(vtk_data.get_array(0), expected)
        assert_array_equal(vtk_data.get_array(CUBA.TEMPERATURE.name), expected)

    def test_load_vectors_onto_vtk(self):
        accumulator = CUBADataAccumulator()
        accumulator.append(create_data_container(restrict=[CUBA.NAME]))
        accumulator.append(
            create_data_container(restrict=[CUBA.NAME, CUBA.VELOCITY,
                                            CUBA.LATTICE_VECTORS]))

        vtk_data = tvtk.PointData()
        accumulator.load_onto_vtk(vtk_data)
        self.assertEqual(vtk_data.number_of_arrays, 1)
        expected = numpy.array(
            [[None, None, None], dummy_cuba_value(CUBA.VELOCITY)], dtype=float)
        assert_array_equal(vtk_data.get_array(0), expected)
        assert_array_equal(vtk_data.get_array(CUBA.VELOCITY.name), expected)
{'fraction_non_alphanumeric': 0.09562638991845812, 'fraction_numerical': 0.005806770447244872, 'mean_word_length': 2.8787733588883566, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3831095', 'n_tokens_mistral': 2648, 'n_tokens_neox': 2508, 'n_words': 370}