def test_cmp(self): place1 = Place(coord_x=12.0, coord_y=42.0) place2 = Place(coord_x=42.0, coord_y=12.0) self.assertNotEqual(place1.coord, place2.coord) place2.coord.x = 12.0 place2.coord.y = 42.0 self.assertEqual(place1.coord, place2.coord)
def test_assign(self): place1 = Place(coord_x=12.0, coord_y=42.0) place2 = Place() place2.coord = place1.coord self.assertEqual(place1.coord, place2.coord) place2 = Place(coord=place1.coord) self.assertEqual(place1.coord, place2.coord)
def test_bool(self): place = Place(name='Answer') self.assertFalse(place.coord) place.coord = {'x': 0.0, 'y': None} self.assertFalse(place.coord) place.coord = {'x': None, 'y': 0.0} self.assertFalse(place.coord) place.coord = {'x': 0.0, 'y': 0.0} self.assertTrue(place.coord)
def test_setattr(self): place = Place() place.coord.x = 12.0 place.coord.y = 42.0 self.assertEqual(place.coord_x, 12.0) self.assertEqual(place.coord_y, 42.0) self.assertEqual(place.coord.x, 12.0) self.assertEqual(place.coord.y, 42.0)
def test_repr(self): place = Place(coord_x=12.0, coord_y=42.0) self.assertEqual(repr(place.coord), 'CoordField(x=12.0, y=42.0)')
def test_assign_incomplete_dict(self): place = Place(name='Answer', coord_x=12.0, coord_y=42.0) with self.assertRaises(KeyError): place.coord = {'x': 0.0}
def test_assign_dict(self): place = Place(name='Answer', coord_x=12.0, coord_y=42.0) place.coord = {'x': 1.0, 'y': 2.0} self.assertEqual(place.coord.x, 1.0) self.assertEqual(place.coord.y, 2.0)
def test_full_clean(self): place = Place(name='Answer', coord_x=12.0, coord_y=42.0) place.full_clean()