コード例 #1
0
 def test_get_list(self):
     collection = Collection()
     self.assertEqual([], list(collection.get_list()))
     obj1 = Object(ident='1', name='test1')
     obj2 = Object(ident='2', name='test2')
     collection.add(obj1)
     collection.add(obj2)
     self.assertEqual([obj1, obj2], list(collection.get_list()))
コード例 #2
0
    def test_merge(self):
        obj1 = Object(ident='1', name='test1')
        obj2 = Object(ident='2', name='test2')
        obj3 = Object(ident='2', name='test3')

        collection1 = Collection()
        collection1.add(obj1)
        collection1.add(obj2)

        collection2 = Collection()
        collection2.add(obj3)

        collection1.merge(collection2)
        self.assertEqual({'1': obj1, '2': obj3}, dict(collection1.get_items()))
コード例 #3
0
 def test_add_and_get_items(self):
     collection = Collection()
     obj = Object(ident=1, name='test')
     self.assertEqual(0, collection.get_length())
     self.assertEqual({}, dict(collection.get_items()))
     collection.add(obj)
     self.assertEqual(1, collection.get_length())
     self.assertEqual({1: obj}, dict(collection.get_items()))
コード例 #4
0
 def test_ident(self):
     item = Object()
     self.assertEqual(None, item.ident)
     item.ident = 'ident1'
     self.assertEqual('ident1', item.ident)
コード例 #5
0
 def test_update(self):
     item = Object(ident='ident1')
     self.assertEqual('ident1', item.ident)
コード例 #6
0
 def test_get(self):
     collection = Collection()
     obj = Object(ident='1', name='test')
     self.assertEqual(None, collection.get('1'))
     collection.add(obj)
     self.assertEqual(obj, collection.get('1'))
コード例 #7
0
 def test_get_length(self):
     collection = Collection()
     self.assertEqual(0, collection.get_length())
     collection.add(Object(ident=1, name='test'))
     self.assertEqual(1, collection.get_length())