Esempio n. 1
0
def List(dir):
	filenames = os.listdir(dir)
	for filename in filenames:
		if filename[4:]=='baby' and filename[-4:]=='html':
			names=babynames.extract_names(filename)
			text = '\n'.join(names)
			f = open(filename+'.summary','w')
			f.write(text)
			f.close()	
    def test_extract_names(self):
        """Checking extraction, alphabetizing, de-duping, ranking of names from all html files"""
        # Is the function callable?
        self.assertTrue(callable(babynames.extract_names),
                        msg="The extract_names function is missing")

        # Get list of only html files
        html_file_list = sorted(
            filter(lambda f: f.endswith('.html'), os.listdir('.')))
        # Compare each result (actual) list to expected list.
        for f in html_file_list:
            summary_file = os.path.join('tests', f + '.summary')
            expected_list = self.get_summary_file_as_list(summary_file)
            actual_list = babynames.extract_names(f)
            self.assertIsInstance(actual_list, list)
            # Remove empty strings before comparing
            actual_list = list(filter(None, actual_list))
            # This will perform element-by-element comparison.
            self.assertListEqual(actual_list, expected_list)
Esempio n. 3
0
 def testNamesAreSorted(self):
     result = babynames.extract_names("baby1992.html")
     for idx in range(2, 2001):
         self.assertTrue(result[idx - 1] < result[idx], "Not sorted in alpha order: {} >= {}".format(result[idx - 1], result[idx]))
Esempio n. 4
0
 def testReadNames(self):
     result = babynames.extract_names("baby1990.html")
     self.assertEqual(2001, len(result), "Should find (999 * 2) baby names plus the year, got {}".format(len(result)))
     self.assertEqual("1990", result[0], "First element should be the year")