def test2(): # Test for value l = Location('') self.assertEqual(l, l) self.assertNotEqual('', l) self.assertNotEqual('[ ,country = ,]', l) self.assertNotEqual(Location, l) self.assertEqual(Location(''), l) l1 = Location('') self.assertEqual(l1, l) l1._country = 'abc' self.assertNotEqual(l1, l) l1._country = l._country self.assertEqual(l1, l) l1 = Location(state_='') self.assertNotEqual(l1, l) l2 = Location() l2._state = '' self.assertEqual(l1, l2) self.assertNotEqual(l2, l) l2._country = 'abc' self.assertNotEqual(l2, l1) l1._country = 'abc' self.assertEqual(l2, l1) l1._state = 'NY' self.assertNotEqual(l2, l1) self.assertEqual(l1, l1) l2._state = l1._state self.assertEqual(l2, l1) self.assertEqual(Location(country_='abc', state_='NY'), l1) l1._county = 'Rockland' l1._city = 'New City' self.assertNotEqual(l2, l1) self.assertEqual(l1, l1) l2._city = l1._city self.assertNotEqual(l2, l1) l2._state = l1._state self.assertNotEqual(l2, l1) l2._county = l1._county self.assertEqual(l2, l1) l1._country = 'US' self.assertNotEqual(l2, l1) self.assertNotEqual(Location(country_='US', state_='NY'), l1) self.assertNotEqual( Location(country_='US', state_='NY', county_='Rockland'), l1) self.assertEqual( Location(country_='US', state_='NY', county_='Rockland', city_='New City'), l1)
def test1(): h = hash(Location()) self.assertEqual(h, h) l = Location() self.assertEqual(Location(), l) self.assertEqual(h, hash(l)) l._country = None self.assertEqual(h, hash(l)) l1 = Location() h1 = hash(l1) self.assertEqual(h1, h) l1._country = None self.assertEqual(h1, hash(l1)) l1._country = '' self.assertNotEqual(h1, hash(l1)) l1._country = 'abc' self.assertNotEqual(h1, hash(l1)) h1 = hash(l1) self.assertEqual(h1, hash(l1)) l2 = Location(country_='abc') self.assertEqual(h1, hash(l2)) l2._state = 'NY' l2._county = 'Rockland' l2._city = 'New City' self.assertNotEqual(l1, l2) self.assertNotEqual(h1, hash(l2)) self.assertEqual( hash( Location(country_='abc', state_='NY', county_='Rockland', city_='New City')), hash(l2))
def test_city(self): loc = Location() self.assertIsNone(loc._city) loc = Location(None, None, None, 'New City') self.assertEqual('New City', loc._city) self.assertNotEqual('Nanuet', loc._city) loc._city = 'Ramapo' self.assertEqual('Ramapo', loc._city) loc._country = 'US' loc._state = 'NY' loc._county = 'Rockland' self.assertEqual('Ramapo', loc._city) l1 = Location('US', 'NY', 'Rockland', 'Ramapo') self.assertEqual(loc, l1) l1.city = 'Monroe' self.assertNotEqual('Monroe', l1.city) self.assertEqual('Ramapo', l1.city)
def test_county(self): loc = Location() self.assertIsNone(loc._county) loc = Location(None, None, 'Rockland') self.assertEqual('Rockland', loc._county) self.assertNotEqual('Middlesex', loc._county) self.assertEqual('//Rockland', loc.locationAsStr()) loc._county = 'Hudson' self.assertEqual('Hudson', loc._county) self.assertEqual('//Hudson', loc.locationAsStr()) loc._country = 'US' loc._state = 'NY' self.assertEqual('Hudson', loc._county) self.assertEqual('US/NY/Hudson', loc.locationAsStr()) l1 = Location('US', 'NY', 'Hudson') self.assertEqual(loc, l1) l1.county = 'Orange' self.assertNotEqual('Orange', l1.county) self.assertEqual('Hudson', l1.county) self.assertEqual('US/NY/Hudson', loc.locationAsStr())