def test_add_1(self): entity = Entity("test") self.assertFalse("foo" in entity.child_dict) child_entity = Entity("foo") entity.add(child_entity) self.assertTrue(child_entity in entity.child_list) self.assertTrue("foo" in entity.child_dict)
def test_add_1(self): entity = Entity('test') self.assertFalse('foo' in entity.child_dict) child_entity = Entity('foo') entity.add(child_entity) self.assertTrue(child_entity in entity.child_list) self.assertTrue('foo' in entity.child_dict)
def test_reversed_1(self): entity = Entity('test') for i in range(10): entity.add(Entity('foo_{0}'.format(i))) rev = list(reversed(list(range(10)))) for i, e in enumerate(reversed(entity)): self.assertNotEqual('foo_{0}'.format(i), e.id) self.assertEqual('foo_{0}'.format(rev[i]), e.id)
def test_deepcopy_2(self): entity = Entity("test") entity.add(Entity("foo")) deep = entity[0].deepcopy() self.assertNotEqual(entity[0], deep) self.assertEqual(entity[0].id, deep.id) self.assertIsNone(deep.parent) self.assertEqual("foo", entity[0].id)
def test_copy_2(self): entity = Entity("test") entity.add(Entity("foo")) shallow = entity[0].copy() self.assertNotEqual(entity[0], shallow) self.assertEqual(entity[0].id, shallow.id) self.assertIsNone(shallow.parent) self.assertEqual("foo", entity[0].id)
def test_getitem_7(self): entity = Entity('test') for i in range(10): entity.add(Entity('foo_{0}'.format(i))) new_entity = entity[1::2] self.assertEqual(type(entity), type(new_entity)) self.assertEqual(5, len(new_entity)) self.assertEqual(['foo_1', 'foo_3', 'foo_5', 'foo_7', 'foo_9'], [e.id for e in new_entity])
def test_copy_2(self): entity = Entity('test') entity.add(Entity('foo')) shallow = entity[0].copy() self.assertNotEqual(entity[0], shallow) self.assertEqual(entity[0].id, shallow.id) self.assertIsNone(shallow.parent) self.assertEqual('foo', entity[0].id)
def test_deepcopy_2(self): entity = Entity('test') entity.add(Entity('foo')) deep = entity[0].deepcopy() self.assertNotEqual(entity[0], deep) self.assertEqual(entity[0].id, deep.id) self.assertIsNone(deep.parent) self.assertEqual('foo', entity[0].id)
def test_remove_2(self): entity = Entity("test") entity.add(Entity("foo")) entity.add(Entity("bar")) entity.remove("foo") self.assertFalse("foo" in entity) self.assertTrue("bar" in entity) entity.remove("bar") self.assertFalse("bar" in entity)
def test_getitem_7(self): entity = Entity("test") for i in range(10): entity.add(Entity("foo_{0}".format(i))) new_entity = entity[1::2] self.assertEqual(type(entity), type(new_entity)) self.assertEqual(5, len(new_entity)) self.assertEqual(["foo_1", "foo_3", "foo_5", "foo_7", "foo_9"], [e.id for e in new_entity])
def test_remove_2(self): entity = Entity('test') entity.add(Entity('foo')) entity.add(Entity('bar')) entity.remove('foo') self.assertFalse('foo' in entity) self.assertTrue('bar' in entity) entity.remove('bar') self.assertFalse('bar' in entity)
def test_parent_1(self): entity = Entity("test") child_entity = Entity("foo") entity.add(child_entity) child_child_entity1 = Entity("bar") child_child_entity2 = Entity("cho") child_entity.add(child_child_entity1) child_entity.add(child_child_entity2) self.assertEqual(entity, entity[0].parent) self.assertEqual(child_entity, entity[0][0].parent) self.assertEqual(child_entity, entity[0][1].parent)
def test_parent_1(self): entity = Entity('test') child_entity = Entity('foo') entity.add(child_entity) child_child_entity1 = Entity('bar') child_child_entity2 = Entity('cho') child_entity.add(child_child_entity1) child_entity.add(child_child_entity2) self.assertEqual(entity, entity[0].parent) self.assertEqual(child_entity, entity[0][0].parent) self.assertEqual(child_entity, entity[0][1].parent)
def test_add_2(self): entity = Entity('test') child_entity = Entity('foo') entity.add(child_entity) self.assertTrue(child_entity in entity.child_list) self.assertTrue('foo' in entity.child_dict) with self.assertRaises(ValueError): entity.add(Entity('foo'))
def test_add_2(self): entity = Entity("test") child_entity = Entity("foo") entity.add(child_entity) self.assertTrue(child_entity in entity.child_list) self.assertTrue("foo" in entity.child_dict) with self.assertRaises(ValueError): entity.add(Entity("foo"))
def test_getitem_5(self): entity = Entity('test') child_entity1 = Entity('foo') child_entity2 = Entity('bar') child_entity3 = Entity('cho') entity.add(child_entity1) entity.add(child_entity2) entity.add(child_entity3) self.assertEqual(child_entity1, entity[0]) self.assertEqual(child_entity2, entity[1]) self.assertEqual(child_entity2, entity[-2]) self.assertEqual(child_entity3, entity[-1])
def test_getitem_5(self): entity = Entity("test") child_entity1 = Entity("foo") child_entity2 = Entity("bar") child_entity3 = Entity("cho") entity.add(child_entity1) entity.add(child_entity2) entity.add(child_entity3) self.assertEqual(child_entity1, entity[0]) self.assertEqual(child_entity2, entity[1]) self.assertEqual(child_entity2, entity[-2]) self.assertEqual(child_entity3, entity[-1])
def test_full_id_4(self): entity = Entity("test") entity.add(Entity("foo")) entity[0].add(Entity("bar")) entity[0].add(Entity("cho")) self.assertEqual(("test", "foo", "bar"), entity[0][0].full_id) self.assertEqual(("test", "foo", "cho"), entity[0][1].full_id)
def test_full_id_4(self): entity = Entity('test') entity.add(Entity('foo')) entity[0].add(Entity('bar')) entity[0].add(Entity('cho')) self.assertEqual(('test', 'foo', 'bar'), entity[0][0].full_id) self.assertEqual(('test', 'foo', 'cho'), entity[0][1].full_id)
def remark(self, remark): """Set the :obj:`~conkit.core.contactfile.ContactFile` remark Parameters ---------- remark : str, list The remark will be added to the list of remarks """ self._remark += Entity.listify(remark)
def method(self, method): """Set the :obj:`~conkit.core.contactfile.ContactFile` method Parameters ---------- method : str, list The method will be added to the list of methods """ self._method += Entity.listify(method)
def test_contains_2(self): entity = Entity("test") entity.add(Entity("foo")) entity.add(Entity("bar")) self.assertTrue("foo" in entity) self.assertTrue("bar" in entity) self.assertFalse("cho" in entity)
def test_child_dict_2(self): entity = Entity('test') child_entity1 = Entity('foo') child_entity2 = Entity('bar') entity.add(child_entity1) entity.add(child_entity2) self.assertDictEqual({'foo': child_entity1, 'bar': child_entity2}, entity.child_dict)
def test_contains_2(self): entity = Entity('test') entity.add(Entity('foo')) entity.add(Entity('bar')) self.assertTrue('foo' in entity) self.assertTrue('bar' in entity) self.assertFalse('cho' in entity)
def test_child_list_2(self): entity = Entity("test") child_entity1 = Entity("foo") child_entity2 = Entity("bar") entity.add(child_entity1) entity.add(child_entity2) self.assertEqual(2, len(entity.child_list)) self.assertEqual([child_entity1, child_entity2], entity.child_list)
def test_getitem_3(self): entity = Entity("test") child_entity1 = Entity("foo") child_entity2 = Entity("bar") entity.add(child_entity1) entity.add(child_entity2) self.assertEqual(child_entity1, entity["foo"]) self.assertEqual(child_entity2, entity["bar"])
def test_child_list_2(self): entity = Entity('test') child_entity1 = Entity('foo') child_entity2 = Entity('bar') entity.add(child_entity1) entity.add(child_entity2) self.assertEqual(2, len(entity.child_list)) self.assertEqual([child_entity1, child_entity2], entity.child_list)
def test_copy_1(self): entity = Entity('test') entity.add(Entity('foo')) shallow = entity.copy() self.assertNotEqual(entity, shallow) self.assertTrue(entity.id, shallow.id) self.assertNotEqual(entity[0], shallow[0]) self.assertEqual(entity[0].id, shallow[0].id)
def test_getitem_3(self): entity = Entity('test') child_entity1 = Entity('foo') child_entity2 = Entity('bar') entity.add(child_entity1) entity.add(child_entity2) self.assertEqual(child_entity1, entity['foo']) self.assertEqual(child_entity2, entity['bar'])
def test_deepcopy_1(self): entity = Entity('test') entity.add(Entity('foo')) deep = entity.deepcopy() self.assertNotEqual(entity, deep) self.assertTrue(entity.id, deep.id) self.assertNotEqual(entity[0], deep[0]) self.assertEqual(entity[0].id, deep[0].id)