コード例 #1
0
 def test_dict_obj_pop(self):
     dict_obj = DictObj(self.entries)
     pop = dict_obj.pop('title')
     self.assertNotIn('title', dict_obj)
     self.assertEqual(pop, 'images')
     pop = dict_obj.pop('random', 'noexist')
     self.assertEqual(pop, 'noexist')
コード例 #2
0
    def test_dict_obj_values(self):
        values = DictObj(self.entries).values()
        self.assertEqual(len(values), 4)
        self.assertIn('images', values)

        
        
         
コード例 #3
0
 def test_dict_obj__setitem__(self):
     dict_obj = DictObj()
     dict_obj['title'] = 'images'
     dict_obj['results'] = [{'path': 'img/'}]
     dict_obj['formats'] = ['.jpg']
     dict_obj['langs'] = {'ES': 'es-ES'}
     self.assertEqual(dict_obj['title'], 'images')
     self.assertEqual(dict_obj['results'][0]['path'], 'img/')
     self.assertEqual(dict_obj['formats'][0], '.jpg')
     self.assertEqual(dict_obj['langs']['ES'], 'es-ES')
コード例 #4
0
 def test_dict_obj_fromkeys(self):
     dict_obj = DictObj().fromkeys({'a','b'})
     self.assertEqual(len(dict_obj), 2)
     self.assertTrue(hasattr(dict_obj, 'a'))
     self.assertTrue(hasattr(dict_obj, 'b'))
     for value in dict_obj.values():
         self.assertIsNone(value)
         
     dict_obj = DictObj().fromkeys({'a','b'}, 1)
     self.assertEqual(len(dict_obj), 2)
     self.assertTrue(hasattr(dict_obj, 'a'))
     self.assertTrue(hasattr(dict_obj, 'b'))
     for value in dict_obj.values():
         self.assertEqual(value, 1)
コード例 #5
0
 def test_dict_obj__init__(self):
     dict_obj = DictObj(self.entries)
     self.assert_attr(dict_obj)
     self.assert_dict(dict_obj)
     self.assert_dict(dict_obj.__dict__)
コード例 #6
0
 def test_dict_obj_update(self):
     dict_obj = DictObj()
     dict_obj.update(self.entries)
     self.assertTrue(hasattr(dict_obj, 'title'))
コード例 #7
0
 def test_dict_obj_setdefault(self):
     dict_obj = DictObj(self.entries)
     self.assertEqual(dict_obj.setdefault('title'), 'images')
     self.assertEqual(dict_obj.setdefault('random', 'modnar'), 'modnar')
コード例 #8
0
 def test_dict_obj_popitem(self):
     popitem = DictObj(self.entries).popitem()
     self.assertIsNotNone(popitem)
コード例 #9
0
 def test_dict_obj__delitem__(self):
     dict_obj = DictObj(self.entries)
     self.assertIn('title', dict_obj)
     del dict_obj['title']
     self.assertNotIn('title', dict_obj)
コード例 #10
0
 def test_dict_obj_items(self):
     items = DictObj(self.entries).items()
     self.assertEqual(len(items), 4)
     self.assertIn(('title', 'images'), items)
コード例 #11
0
 def test_dict_obj_get(self):
     get = DictObj(self.entries).get('title')
     self.assertEqual(get, 'images')
コード例 #12
0
 def test_dict_obj_copy(self):
     dict_obj = DictObj(self.entries)
     dict_obj_copy = dict_obj.copy()
     self.assertTrue(hasattr(dict_obj_copy, 'title'))
     self.assertEqual(dict_obj.__dict__, dict_obj_copy.__dict__)
コード例 #13
0
 def test_dict_obj_clear(self):
     dict_obj = DictObj(self.entries)
     dict_obj.clear()
     self.assertEqual(len(dict_obj), 0)
コード例 #14
0
 def test_dict_obj__reversed__(self):
     if sys.version_info >= (3, 8):
         try:
             reversed(DictObj(self.entries))
         except TypeError as e:
             self.fail('Not reverse iterable')
コード例 #15
0
 def test_dict_obj__iter__(self):
     try:
         iter(DictObj(self.entries))
     except TypeError as e:
         self.fail('Not iterable')
コード例 #16
0
 def test_dict_obj__len__(self):
     self.assertEqual(len(DictObj(self.entries)), 4)
     self.assertEqual(len(DictObj()), 0)
コード例 #17
0
 def test_dict_obj__getitem__(self):
     dict_obj = DictObj(self.entries)
     self.assertEqual(dict_obj['title'], 'images')
     self.assertEqual(dict_obj['results'][0]['path'], 'img/')
     self.assertEqual(dict_obj['formats'][0], '.jpg')
     self.assertEqual(dict_obj['langs']['ES'], 'es-ES')
コード例 #18
0
 def test_dict_obj_keys(self):
     keys = DictObj(self.entries).keys()
     self.assertEqual(len(keys), 4)
     self.assertIn('title', keys)