def test_unknown_fields(self): """Verify that unkwown fields raise a validation error.""" # position is required # position must be a list of three floats with self.assertRaises(ValidationError) as exc: Orbital(position=(1, 2, 3), some_strange_key=1) self.assertIn('some_strange_key', str(exc.exception))
def test_required_fields(self): """Verify that required fields are validated.""" # position is required with self.assertRaises(ValidationError): Orbital() # position must be a list of three floats with self.assertRaises(ValidationError): Orbital(position=(1, 2)) with self.assertRaises(ValidationError): Orbital(position=(1, 2, 'a')) orbital = Orbital(position=(1, 2, 3)) self.assertAlmostEqual(orbital.get_orbital_dict()['position'][0], 1.) self.assertAlmostEqual(orbital.get_orbital_dict()['position'][1], 2.) self.assertAlmostEqual(orbital.get_orbital_dict()['position'][2], 3.)
def test_orbital_str(self): """"Test the output of __str__ method""" orbital = Orbital(position=(1, 2, 3)) expected_output = 'Orbital @ 1.0000,2.0000,3.0000' self.assertEqual(str(orbital), expected_output)