X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a480283b6fe33bd0df12d879c835427e1b71489a..8d47832e4637a40710838b9f4dc3353b58a28c93:/sdk/python/tests/test_vocabulary.py diff --git a/sdk/python/tests/test_vocabulary.py b/sdk/python/tests/test_vocabulary.py index 56647e8243..aa2e739e20 100644 --- a/sdk/python/tests/test_vocabulary.py +++ b/sdk/python/tests/test_vocabulary.py @@ -65,6 +65,7 @@ class VocabularyTest(unittest.TestCase): {'label': 'Comment'}, {'label': 'Notes'}, ], + 'values': None, }, }, } @@ -168,18 +169,40 @@ class VocabularyTest(unittest.TestCase): # Strict vocabulary strict_voc = arvados.vocabulary.Vocabulary(self.EXAMPLE_VOC) strict_voc.strict_keys = True - with self.assertRaises(KeyError): + with self.assertRaises(vocabulary.VocabularyKeyError): strict_voc.convert_to_identifiers({'foo': 'bar'}) + def test_convert_to_identifiers_invalid_key(self): + with self.assertRaises(vocabulary.VocabularyKeyError): + self.voc.convert_to_identifiers({42: 'bar'}) + with self.assertRaises(vocabulary.VocabularyKeyError): + self.voc.convert_to_identifiers({None: 'bar'}) + with self.assertRaises(vocabulary.VocabularyKeyError): + self.voc.convert_to_identifiers({('f', 'o', 'o'): 'bar'}) + def test_convert_to_identifiers_unknown_value(self): # Non-strict key self.assertEqual(self.voc['animal'].strict, False) self.assertEqual(self.voc.convert_to_identifiers({'Animal': 'foo'}), {'IDTAGANIMALS': 'foo'}) # Strict key self.assertEqual(self.voc['priority'].strict, True) - with self.assertRaises(ValueError): + with self.assertRaises(vocabulary.VocabularyValueError): self.voc.convert_to_identifiers({'Priority': 'foo'}) + def test_convert_to_identifiers_invalid_value(self): + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_identifiers({'Animal': 42}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_identifiers({'Animal': None}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_identifiers({'Animal': {'hello': 'world'}}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_identifiers({'Animal': [42]}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_identifiers({'Animal': [None]}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_identifiers({'Animal': [{'hello': 'world'}]}) + def test_convert_to_identifiers_unknown_value_list(self): # Non-strict key self.assertEqual(self.voc['animal'].strict, False) @@ -189,7 +212,7 @@ class VocabularyTest(unittest.TestCase): ) # Strict key self.assertEqual(self.voc['priority'].strict, True) - with self.assertRaises(ValueError): + with self.assertRaises(vocabulary.VocabularyValueError): self.voc.convert_to_identifiers({'Priority': ['foo', 'bar']}) def test_convert_to_labels(self): @@ -241,18 +264,42 @@ class VocabularyTest(unittest.TestCase): # Strict vocabulary strict_voc = arvados.vocabulary.Vocabulary(self.EXAMPLE_VOC) strict_voc.strict_keys = True - with self.assertRaises(KeyError): + with self.assertRaises(vocabulary.VocabularyKeyError): strict_voc.convert_to_labels({'foo': 'bar'}) + def test_convert_to_labels_invalid_key(self): + with self.assertRaises(vocabulary.VocabularyKeyError): + self.voc.convert_to_labels({42: 'bar'}) + with self.assertRaises(vocabulary.VocabularyKeyError): + self.voc.convert_to_labels({None: 'bar'}) + with self.assertRaises(vocabulary.VocabularyKeyError): + self.voc.convert_to_labels({('f', 'o', 'o'): 'bar'}) + def test_convert_to_labels_unknown_value(self): # Non-strict key self.assertEqual(self.voc['animal'].strict, False) self.assertEqual(self.voc.convert_to_labels({'IDTAGANIMALS': 'foo'}), {'Animal': 'foo'}) # Strict key self.assertEqual(self.voc['priority'].strict, True) - with self.assertRaises(ValueError): + with self.assertRaises(vocabulary.VocabularyValueError): self.voc.convert_to_labels({'IDTAGIMPORTANCES': 'foo'}) + def test_convert_to_labels_invalid_value(self): + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_labels({'IDTAGIMPORTANCES': {'high': True}}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_labels({'IDTAGIMPORTANCES': None}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_labels({'IDTAGIMPORTANCES': 42}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_labels({'IDTAGIMPORTANCES': False}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_labels({'IDTAGIMPORTANCES': [42]}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_labels({'IDTAGIMPORTANCES': [None]}) + with self.assertRaises(vocabulary.VocabularyValueError): + self.voc.convert_to_labels({'IDTAGIMPORTANCES': [{'high': True}]}) + def test_convert_to_labels_unknown_value_list(self): # Non-strict key self.assertEqual(self.voc['animal'].strict, False) @@ -262,7 +309,7 @@ class VocabularyTest(unittest.TestCase): ) # Strict key self.assertEqual(self.voc['priority'].strict, True) - with self.assertRaises(ValueError): + with self.assertRaises(vocabulary.VocabularyValueError): self.voc.convert_to_labels({'IDTAGIMPORTANCES': ['foo', 'bar']}) def test_convert_roundtrip(self):