示例#1
0
 def test_translate_struct_dict_nonunique_key(self):
     """Tests if list/dict gets properly converted to NaElements."""
     root = NaElement('root')
     child = [{'e1': 'v1', 'e2': 'v2'}, {'e1': 'v3'}]
     root.translate_struct(child)
     self.assertEqual(len(root.get_children()), 3)
     children = root.get_children()
     for c in children:
         if c.get_name() == 'e1':
             self.assertIn(c.get_content(), ['v1', 'v3'])
         else:
             self.assertEqual(c.get_content(), 'v2')
示例#2
0
 def test_translate_struct_dict_nonunique_key(self):
     """Tests if list/dict gets properly converted to NaElements."""
     root = NaElement('root')
     child = [{'e1': 'v1', 'e2': 'v2'}, {'e1': 'v3'}]
     root.translate_struct(child)
     self.assertEqual(len(root.get_children()), 3)
     children = root.get_children()
     for c in children:
         if c.get_name() == 'e1':
             self.assertIn(c.get_content(), ['v1', 'v3'])
         else:
             self.assertEqual(c.get_content(), 'v2')
示例#3
0
 def test_setter_na_element(self):
     """Tests na_element gets appended as child."""
     root = NaElement('root')
     root['e1'] = NaElement('nested')
     self.assertEqual(len(root.get_children()), 1)
     e1 = root.get_child_by_name('e1')
     self.assertIsInstance(e1, NaElement)
     self.assertIsInstance(e1.get_child_by_name('nested'), NaElement)
示例#4
0
 def test_translate_struct_tuple(self):
     """Tests if tuple gets properly converted to NaElements."""
     root = NaElement('root')
     child = ('e1', 'e2')
     root.translate_struct(child)
     self.assertEqual(len(root.get_children()), 2)
     self.assertIsNone(root.get_child_content('e1'))
     self.assertIsNone(root.get_child_content('e2'))
示例#5
0
 def test_setter_na_element(self):
     """Tests na_element gets appended as child."""
     root = NaElement('root')
     root['e1'] = NaElement('nested')
     self.assertEqual(len(root.get_children()), 1)
     e1 = root.get_child_by_name('e1')
     self.assertIsInstance(e1, NaElement)
     self.assertIsInstance(e1.get_child_by_name('nested'), NaElement)
示例#6
0
 def test_translate_struct_tuple(self):
     """Tests if tuple gets properly converted to NaElements."""
     root = NaElement('root')
     child = ('e1', 'e2')
     root.translate_struct(child)
     self.assertEqual(len(root.get_children()), 2)
     self.assertIsNone(root.get_child_content('e1'))
     self.assertIsNone(root.get_child_content('e2'))
示例#7
0
 def test_translate_struct_dict_unique_key(self):
     """Tests if dict gets properly converted to NaElements."""
     root = NaElement('root')
     child = {'e1': 'v1', 'e2': 'v2', 'e3': 'v3'}
     root.translate_struct(child)
     self.assertEqual(len(root.get_children()), 3)
     self.assertEqual(root.get_child_content('e1'), 'v1')
     self.assertEqual(root.get_child_content('e2'), 'v2')
     self.assertEqual(root.get_child_content('e3'), 'v3')
示例#8
0
 def test_translate_struct_dict_unique_key(self):
     """Tests if dict gets properly converted to NaElements."""
     root = NaElement('root')
     child = {'e1': 'v1', 'e2': 'v2', 'e3': 'v3'}
     root.translate_struct(child)
     self.assertEqual(len(root.get_children()), 3)
     self.assertEqual(root.get_child_content('e1'), 'v1')
     self.assertEqual(root.get_child_content('e2'), 'v2')
     self.assertEqual(root.get_child_content('e3'), 'v3')
示例#9
0
 def test_setter_builtin_types(self):
     """Tests str, int, float get converted to NaElement."""
     root = NaElement('root')
     root['e1'] = 'v1'
     root['e2'] = 1
     root['e3'] = 2.0
     root['e4'] = 8l
     self.assertEqual(len(root.get_children()), 4)
     self.assertEqual(root.get_child_content('e1'), 'v1')
     self.assertEqual(root.get_child_content('e2'), '1')
     self.assertEqual(root.get_child_content('e3'), '2.0')
     self.assertEqual(root.get_child_content('e4'), '8')
示例#10
0
 def test_setter_builtin_types(self):
     """Tests str, int, float get converted to NaElement."""
     root = NaElement('root')
     root['e1'] = 'v1'
     root['e2'] = 1
     root['e3'] = 2.0
     root['e4'] = 8l
     self.assertEqual(len(root.get_children()), 4)
     self.assertEqual(root.get_child_content('e1'), 'v1')
     self.assertEqual(root.get_child_content('e2'), '1')
     self.assertEqual(root.get_child_content('e3'), '2.0')
     self.assertEqual(root.get_child_content('e4'), '8')