class TestOdmlDtypes(unittest.TestCase):
    """
    class to test the other functions of the OdmlDtype-class
    """
    def setUp(self):
        self.test_dtypes = OdmlDtypes()

    def test_defaults(self):
        expected_basedtypes = list(self.test_dtypes.default_basedtypes)
        self.assertListEqual(sorted(expected_basedtypes),
                             sorted(self.test_dtypes.basedtypes))

        expected_synonyms = self.test_dtypes.default_synonyms
        self.assertEqual(expected_synonyms, self.test_dtypes.synonyms)

    def test_valid_dtypes(self):
        expected_dtypes = (list(self.test_dtypes.default_basedtypes) +
                           list(self.test_dtypes.default_synonyms))
        self.assertListEqual(sorted(expected_dtypes),
                             sorted(self.test_dtypes.valid_dtypes))

    def test_synonym_adder(self):
        basedtype, synonym = ('int', 'testsyn1')
        self.test_dtypes.add_synonym(basedtype, synonym)

        expected_synonyms = self.test_dtypes.default_synonyms.copy()
        expected_synonyms.update({synonym: basedtype})
        self.assertEqual(self.test_dtypes.synonyms, expected_synonyms)
 def setUp(self):
     self.test_dtypes = OdmlDtypes()
class TestOdmlDtypes(unittest.TestCase):
    """
    class to test the other functions of the OdmlDtype-class
    """

    def setUp(self):
        self.test_dtypes = OdmlDtypes()

    def test_defaults(self):

        expected_basedtypes = self.test_dtypes.default_basedtypes.keys()
        self.assertItemsEqual(expected_basedtypes,self.test_dtypes.basedtypes)

        expected_synonyms = self.test_dtypes.default_synonyms
        self.assertEqual(expected_synonyms,self.test_dtypes.synonyms)

    def test_valid_dtypes(self):
        expected_dtypes = self.test_dtypes.default_basedtypes.keys() + self.test_dtypes.default_synonyms.keys()
        self.assertItemsEqual(expected_dtypes,self.test_dtypes.valid_dtypes)

    def test_default_values(self):
        basedefaults = self.test_dtypes.default_basedtypes
        syndefaults = dict([(syn,basedefaults[base]) for syn,base in self.test_dtypes.default_synonyms.iteritems()])
        expected_defaults = basedefaults.copy()
        expected_defaults.update(syndefaults)

        self.assertEqual(expected_defaults,self.test_dtypes.default_values)

        for dtype,expected_default in expected_defaults.iteritems():
            self.assertEqual(expected_default,self.test_dtypes.default_value(dtype))

    def test_synonym_adder(self):
        basedtype, synonym = ('int','testsyn1')
        self.test_dtypes.add_synonym(basedtype,synonym)

        expected_synonyms = self.test_dtypes.default_synonyms.copy()
        expected_synonyms.update({synonym:basedtype})
        self.assertEqual(self.test_dtypes.synonyms, expected_synonyms)
        self.assertEqual(self.test_dtypes.default_value('testsyn1'),self.test_dtypes.default_value('int'))

    def test_basedtype_adder(self):
        basedtype, default = 'testbasetype','testdefault'
        self.test_dtypes.add_basedtypes(basedtype,default)

        expected_basedtypes = self.test_dtypes.default_basedtypes.copy()
        expected_basedtypes.update({basedtype:default})
        self.assertItemsEqual(self.test_dtypes.basedtypes,expected_basedtypes)

    def test_default_value_setter(self):
        default_value = 1
        self.test_dtypes.set_default_value('int',default_value)

        self.test_dtypes.default_value('int')

        self.assertEqual(self.test_dtypes.default_value('int'),default_value)
 def setUp(self):
     self.test_dtypes = OdmlDtypes()