def import_file(self, file): self.log("Importing ENEM grades from file {}".format(file.name)) count, fail = 0, 0 for result in parse_file(file): try: self.process(result) self.debug( "{} {} {} {} {} {} {}".format( result["state"], result["city"], result["school"], result["nature_science_grade"], result["human_science_grade"], result["languages_grade"], result["math_grade"], ) ) except Exception: self.log("error importing line") fail += 1 count += 1 self.log("{} ENEM grades imported. {} failed.".format(count - fail, fail))
def test_ignores_invalid_lines(self): count = 0 # Second line is invalid with open("./test/ENEM_fixture.txt") as file: for result in parse_file(file): count += 1 # The iterator should only yield data one time self.assertEqual(count, 1)
def test_parses_the_first_line(self): with open("./test/ENEM_fixture.txt") as file: for result in parse_file(file): self.assertIsInstance(result, dict)