1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
9 from arvados import api, vocabulary
11 class VocabularyTest(unittest.TestCase):
18 {'label': 'Creature'},
24 {'label': 'Homo sapiens'},
29 {'label': 'Elephant'},
30 {'label': 'Loxodonta'},
38 {'label': 'Importance'},
39 {'label': 'Priority'},
45 {'label': 'High priority'},
51 {'label': 'Medium priority'},
57 {'label': 'Low priority'},
65 def perform_vocabulary_tests(self, voc):
66 self.assertEqual(voc.strict_keys, False)
68 voc.key_aliases.keys(),
69 set(['IDTAGANIMALS', 'creature', 'animal',
70 'IDTAGIMPORTANCE', 'importance', 'priority'])
73 vk = voc.key_aliases['creature']
74 self.assertEqual(vk.strict, False)
75 self.assertEqual(vk.identifier, 'IDTAGANIMALS')
76 self.assertEqual(vk.aliases, ['Animal', 'Creature'])
78 vv = vk.value_aliases['human']
79 self.assertEqual(vv.identifier, 'IDVALANIMAL1')
80 self.assertEqual(vv.aliases, ['Human', 'Homo sapiens'])
82 self.assertEqual(voc['creature']['human'].identifier, vv.identifier)
83 self.assertEqual(voc['Creature']['Human'].identifier, vv.identifier)
84 self.assertEqual(voc['CREATURE']['HUMAN'].identifier, vv.identifier)
86 def test_empty_vocabulary(self):
87 voc = vocabulary.Vocabulary()
88 self.assertEqual(voc.strict_keys, False)
89 self.assertEqual(voc.key_aliases, {})
91 def test_vocabulary_explicit_instantiation(self):
92 voc = vocabulary.Vocabulary(self.EXAMPLE_VOC)
93 self.perform_vocabulary_tests(voc)
95 @mock.patch('arvados.api')
96 def test_load_vocabulary_with_api(self, api_mock):
97 api_mock.return_value = mock.MagicMock()
98 api_mock.return_value.vocabulary.return_value = self.EXAMPLE_VOC
100 voc = vocabulary.load_vocabulary(arvados.api('v1'))
101 self.perform_vocabulary_tests(voc)