def test_copy(self): """ Tests the creation of a copy """ mock_owner = MockOwner() col = Column(scope='parent').test.field col.set_alias('cheese') col.owner = mock_owner col_copy = copy.copy(col) self.assertNotEqual(id(col), id(col_copy)) self.assertEqual(id(col._owner), id(col_copy._owner))
def test_hash(self): """ Checks to see if the has of two objects with the same options hash to the same value, and that two column objects that do not share all of the same objects hash to different values """ mock_owner = MockOwner() col = Column(scope='parent').test.field col.set_alias('fish') col.owner = mock_owner mock_owner2 = MockOwner() col2 = Column(scope='parent').test.field col2.set_alias('fish') col2.owner = mock_owner2 self.assertEqual(hash(col), hash(col2)) mock_owner3 = MockOwner() col3 = Column(scope='parent').test.field col3.set_alias('cheese') col3.owner = mock_owner self.assertNotEqual(hash(col), hash(col3))
def test_deepcopy(self): """ Tests the creation of a deep copy (which is the same as a copy for column objects, due to the use of weakref.proxy() for the owner). """ mock_owner = MockOwner() col = Column(scope='parent').test.field col.set_alias('cheese') col.owner = mock_owner col_copy = copy.copy(col) self.assertNotEqual(id(col), id(col_copy)) self.assertEqual(id(col._owner), id(col_copy._owner))