Exemplo n.º 1
0
 def test_should_not_change_values_by_update(self):
     base = {"eggs": 42, "spam": "ham"}
     my_dict = AttrDict(base)
     new = {"cheese": 10}
     new_dict = AttrDict(new)
     my_dict.update(new_dict)
     self.assertEqual(my_dict.eggs, 42)
     self.assertEqual(my_dict.cheese, 10)
Exemplo n.º 2
0
 def test_should_not_change_values_by_update(self):
     base = {'eggs': 42, 'spam': 'ham'}
     my_dict = AttrDict(base)
     new = {'cheese': 10}
     new_dict = AttrDict(new)
     my_dict.update(new_dict)
     self.assertEqual(my_dict.eggs, 42)
     self.assertEqual(my_dict.cheese, 10)
Exemplo n.º 3
0
 def test_should_not_change_values_by_inited_dict(self):
     base = {'eggs': 42, 'spam': 'ham'}
     my_dict = AttrDict(base)
     base['eggs'] = 123
     self.assertEqual(my_dict.eggs, 42)
     self.assertEqual(my_dict['eggs'], 42)
     self.assertEqual(my_dict.spam, 'ham')
     self.assertEqual(my_dict['spam'], 'ham')
Exemplo n.º 4
0
 def test_should_not_change_values_by_inited_dict(self):
     base = {"eggs": 42, "spam": "ham"}
     my_dict = AttrDict(base)
     base["eggs"] = 123
     self.assertEqual(my_dict.eggs, 42)
     self.assertEqual(my_dict["eggs"], 42)
     self.assertEqual(my_dict.spam, "ham")
     self.assertEqual(my_dict["spam"], "ham")
Exemplo n.º 5
0
 def test_del_attr(self):
     my_dict = AttrDict()
     my_dict['test'] = 123
     my_dict['python'] = 42
     del my_dict['test']
     del my_dict.python
     with self.assertRaises(KeyError):
         temp = my_dict['test']
     with self.assertRaises(AttributeError):
         temp = my_dict.python
Exemplo n.º 6
0
 def test_should_init_with_one_dict(self):
     my_dict = AttrDict({'eggs': 42, 'spam': 'ham'})
     self.assertEqual(my_dict.eggs, 42)
     self.assertEqual(my_dict['eggs'], 42)
     self.assertEqual(my_dict.spam, 'ham')
     self.assertEqual(my_dict['spam'], 'ham')
Exemplo n.º 7
0
 def test_equal(self):
     my_dict = AttrDict({'test': 123})
     my_dict_2 = AttrDict({'test': 123})
     self.assertEqual(my_dict, my_dict_2)
Exemplo n.º 8
0
 def test_repr(self):
     my_dict = AttrDict()
     my_dict['test'] = 123
     my_dict.python = 42
     self.assertEqual(repr(my_dict), "{'test': 123, 'python': 42}")
Exemplo n.º 9
0
 def test_len_should_work_like_in_dict(self):
     my_dict = AttrDict()
     my_dict['test'] = 123
     my_dict.python = 42
     self.assertEqual(len(my_dict), 2)
Exemplo n.º 10
0
 def test_in_should_work_like_in_dict(self):
     my_dict = AttrDict()
     my_dict['test'] = 123
     self.assertIn('test', my_dict)
     self.assertNotIn('bla', my_dict)
Exemplo n.º 11
0
 def test_set_item(self):
     my_dict = AttrDict()
     my_dict['test'] = 123
     self.assertEqual(my_dict['test'], 123)
     self.assertEqual(my_dict.test, 123)
Exemplo n.º 12
0
 def test_should_init_with_another_attrdict(self):
     one_dict = AttrDict({'eggs': 42, 'spam': 'ham'})
     another_dict = AttrDict(one_dict)
     self.assertEqual(one_dict, another_dict)
Exemplo n.º 13
0
 def test_should_init_with_one_dict(self):
     my_dict = AttrDict({"eggs": 42, "spam": "ham"})
     self.assertEqual(my_dict.eggs, 42)
     self.assertEqual(my_dict["eggs"], 42)
     self.assertEqual(my_dict.spam, "ham")
     self.assertEqual(my_dict["spam"], "ham")
Exemplo n.º 14
0
 def test_in_should_work_like_in_dict(self):
     my_dict = AttrDict()
     my_dict["test"] = 123
     self.assertIn("test", my_dict)
     self.assertNotIn("bla", my_dict)
Exemplo n.º 15
0
 def test_get_item(self):
     my_dict = AttrDict()
     my_dict.test = 123
     self.assertEqual(my_dict.test, 123)
     self.assertEqual(my_dict["test"], 123)
Exemplo n.º 16
0
 def test_should_init_with_another_attrdict(self):
     one_dict = AttrDict({"eggs": 42, "spam": "ham"})
     another_dict = AttrDict(one_dict)
     self.assertEqual(one_dict, another_dict)