18574: Adds remaining invalid key/value test cases.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 3 Mar 2022 14:16:53 +0000 (11:16 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 3 Mar 2022 14:16:53 +0000 (11:16 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

sdk/python/tests/test_vocabulary.py

index 1d3d7b62723f39d4bb959f487293e508a4828265..aa2e739e20d65849c5444471b24c5e34a5f4eac9 100644 (file)
@@ -173,6 +173,10 @@ class VocabularyTest(unittest.TestCase):
             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'})
 
@@ -188,6 +192,16 @@ class VocabularyTest(unittest.TestCase):
     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
@@ -256,6 +270,10 @@ class VocabularyTest(unittest.TestCase):
     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
@@ -269,6 +287,18 @@ class VocabularyTest(unittest.TestCase):
     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