def test_RN_Handles_BlankLines(self): # make sure the name lookup initialisers deal well with empty lines self.name_generator = \ WeightedChoice(test_data_input_file("lookupwithgaps.csv"), name_field="Forename") self.assertEqual( len(self.name_generator.items), len(list(csv.DictReader(open(test_data_input_file("lookupwithgaps.csv"))))) )
def test_RN_Handles_BlankLines(self): # make sure the name lookup initialisers deal well with empty lines self.name_generator = \ WeightedChoice(test_data_input_file("lookupwithgaps.csv"), name_field="Forename") self.assertEqual( len(self.name_generator.items), len( list( csv.DictReader( open(test_data_input_file("lookupwithgaps.csv"))))))
def test_RN_Uses_All_Names(self): """ test that RandomNames uses all available options. Method: probabilistic test to make sure no names are excluded from results using small lookup file with just a few items and enough iterations to make all items extremely likely to be chosen at least once """ test_fname = test_data_input_file("minimallookup.csv") # get checklist checklist = list(csv.DictReader(open(test_fname))) # how many samples make it *extremely* unlikely that any item was not selected # at least once? # set up name generator name_generator = WeightedChoice(test_fname, name_field="Forename") # check all names are represented in output for name_check in checklist: for i in range(self.binary_check_sample_size): new_name = name_generator.name() if name_check["Forename"] == new_name: break else: self.fail("Name %s (1 of %d) was not generated even after %d iterations"\ % (name_check["Forename"], len(name_generator.items), self.binary_check_sample_size))
def test_RN_Handles_NonNumPopularity(self): # make sure the name popularity mechanisms deal with empty lines with self.assertRaises(MissingPopularityException): name_generator = WeightedChoice( test_data_input_file("lookupMissingPopularity.csv"), name_field="Forename")