def test_is_empty(self): """Ensure that Medication.empty_string() method successfully detects when the Medication object was initialized with an empty string and when not.""" i = 0 for empty_string in self.empty_strings: i += 1 medInstance = medication.Medication(empty_string) self.assertTrue(medInstance.is_empty(), "Failed to detect empty string in example %d" % i) for nonempty_string in self.original_strings: i += 1 medInstance = medication.Medication(nonempty_string) self.assertTrue( not medInstance.is_empty(), "Failed to detect non-empty string in example %d" % i)
def test_normalize_string(self): """Test that .normalize_string() normalizes both test strings to the same test output.""" i = 0 for original_string in self.original_strings: i += 1 medInstance = medication.Medication(original_string) self.assertEqual(self.normalized_string, medInstance.normalized_string, "Failed to normalize example %d" % i)
def setUp(self): self.original_strings = [ 'Mirapex 0.5 MG Tablet;TAKE 1 TABLET 3 TIMES DAILY.; Rx.', '(Mirapex 0.5 MG Tablet;TAKE 1 TABLET 3 TIMES DAILY.; Rx)', ] self.empty_strings = ['', ' ', "\t "] self.normalized_string = 'MIRAPEX 0.5 MG TABLET;TAKE 1 TABLET 3 TIMES DAILY.; RX' self.provenance = 'list1' self.instance = medication.Medication(self.original_strings[0])
def test_original_string(self): """Ensure that .original_string contains the original, unnormalized version of the medication string.""" i = 0 for original_string in self.original_strings: i += 1 medInstance = medication.Medication(original_string) self.assertEqual( medInstance.original_string, original_string, "Failed original string equality in example %d" % i)
def test_no_provenance(self): """Test that a Medication initialized without the provenance parameter has an empty provenance attribute.""" medInstance = medication.Medication(self.original_strings[0]) self.assertEqual(medInstance.provenance, "")
def test_provenance(self): """Test that the optional provenance parameter becomes an attribute of the object.""" medInstance = medication.Medication(self.original_strings[0], provenance=self.provenance) self.assertEqual(medInstance.provenance, self.provenance)