<commit_before>"""Tests for CUDS data structure."""
import unittest
import uuid

from simphony import CUDS
from simphony.cuds.particles import Particle, Particles


class CUDSTestCase(unittest.TestCase):
    """CUDS class tests."""
    def setUp(self):
        self.cuds = CUDS()

        # TODO: use generated components
        class DummyComponent(object):
            def __init__(self):
                self.uuid = uuid.uuid4()
                self.name = 'dummyname'
                self.data = {}
        self.dummpy_component1 = DummyComponent()
        self.dummpy_component2 = DummyComponent()

    def test_empty_cuds(self):
        self.assertEqual(len(self.cuds.data), 0)
        self.assertEqual(self.cuds.get('nonexistentkey'), None)
        self.assertEqual(self.cuds.data, {})
        self.assertRaises(KeyError, self.cuds.remove, 'nonexistentkey')

    def test_data(self):
        data = self.cuds.data
        self.assertEqual(self.cuds.data, data)
        self.assertIsNot(self.cuds.data, data)

    def test_get(self):
        self.assertRaises(TypeError,
                          self.cuds.get,
                          42)

    def test_add_get_component(self):
        self.assertRaises(ValueError, self.cuds.add, object())
        self.cuds.add(self.dummpy_component1)
        self.assertEqual(self.cuds.get(self.dummpy_component1.uuid),
                         self.dummpy_component1)

    def test_add_dataset(self):
        p1 = Particle()
        p2 = Particle()
        ps = Particles('my particles')
        ps.add_particles([p1, p2])

        self.cuds.add(ps)
        self.assertEqual(self.cuds.get(ps.name), ps)

    def test_remove_component(self):
        self.cuds.add(self.dummpy_component1)
        self.cuds.remove(self.dummpy_component1.uuid)
        self.assertIsNone(self.cuds.get(self.dummpy_component1.uuid))

    def test_remove_dataset(self):
        p1 = Particle()<commit_msg>added tests<commit_after>"""Tests for CUDS data structure."""
import unittest
import uuid

from simphony import CUDS
from simphony.cuds.particles import Particle, Particles


class CUDSTestCase(unittest.TestCase):
    """CUDS class tests."""
    def setUp(self):
        self.cuds = CUDS()

        # TODO: use generated components
        class DummyComponent(object):
            def __init__(self):
                self.uuid = uuid.uuid4()
                self.name = 'dummyname'
                self.data = {}
        self.dummpy_component1 = DummyComponent()
        self.dummpy_component2 = DummyComponent()

    def test_empty_cuds(self):
        self.assertEqual(len(self.cuds.data), 0)
        self.assertEqual(self.cuds.get('nonexistentkey'), None)
        self.assertEqual(self.cuds.data, {})
        self.assertRaises(KeyError, self.cuds.remove, 'nonexistentkey')

    def test_data(self):
        data = self.cuds.data
        self.assertEqual(self.cuds.data, data)
        self.assertIsNot(self.cuds.data, data)

    def test_add_get_component(self):
        self.assertRaises(TypeError, self.cuds.add, object())
        self.cuds.add(self.dummpy_component1)
        self.assertEqual(self.cuds.get(self.dummpy_component1.uuid),
                         self.dummpy_component1)

    def test_add_component_with_no_uuid(self):
        # Set the uuid to None
        self.dummpy_component1.uuid = None

        self.cuds.add(self.dummpy_component1)

        self.assertIsNotNone(self.dummpy_component1.uuid)
        self.assertEqual(self.cuds.get(self.dummpy_component1.uuid),
                         self.dummpy_component1)

    def test_add_dataset(self):
        p1 = Particle()
        p2 = Particle()
        ps = Particles('my particles')
        ps.add_particles([p1, p2])

        self.cuds.add(ps)
        self.assertEqual(self.cuds.get(ps.name), ps)

    def test_remove_component(self):
        self.cuds.add(self.dummpy_component1)
        self.cuds.remove(self.dummpy_component1.uuid)
        self.assertIsNone(self.cuds.get(self.dummpy_component1.uuid))

    def test_remove_dataset(self):
        p1 = Particle()
{'fraction_non_alphanumeric': 0.11061946902654868, 'fraction_numerical': 0.009095378564405112, 'mean_word_length': 2.477777777777778, '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': '5086992', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1320, 'n_words': 204}