Esempio n. 1
0
 def test_dict(self):
     pair = to_name_dict_pair('a', parent=dict(a='udu'), default_key='name')
     self.assertEqual(('a', dict(name='udu')), pair)
     pair = to_name_dict_pair('a*',
                              parent={'a*': 'udu'},
                              default_key='name')
     self.assertEqual(('a*', dict(name='udu')), pair)
Esempio n. 2
0
    def test_name_only(self):
        pair = to_name_dict_pair('a', default_key='name')
        self.assertEqual(('a', None), pair)
        pair = to_name_dict_pair('a?', default_key='name')
        self.assertEqual(('a?', None), pair)

        with self.assertRaises(ValueError) as cm:
            to_name_dict_pair(12, default_key='name')
        self.assertEqual('name must be a string', f'{cm.exception}')
Esempio n. 3
0
    def test_tuple(self):
        pair = to_name_dict_pair(('a', 'udu'), default_key='name')
        self.assertEqual(('a', dict(name='udu')), pair)
        pair = to_name_dict_pair(('a*', 'udu'), default_key='name')
        self.assertEqual(('a*', dict(name='udu')), pair)
        pair = to_name_dict_pair(('a*', {'name': 'udu'}))
        self.assertEqual(('a*', dict(name='udu')), pair)
        pair = to_name_dict_pair(('a*', {'marker': True, 'name': 'udu'}))
        self.assertEqual(('a*', dict(marker=True, name='udu')), pair)

        with self.assertRaises(ValueError) as cm:
            to_name_dict_pair(('a', 5))
        self.assertEqual("value of 'a' must be a dictionary", f'{cm.exception}')
Esempio n. 4
0
 def test_mapping(self):
     pair = to_name_dict_pair({'a': 'udu'}, default_key='name')
     self.assertEqual(('a', dict(name='udu')), pair)
     pair = to_name_dict_pair({'a*': dict(name='udu')})
     self.assertEqual(('a*', dict(name='udu')), pair)