def test_escaping(self): texts = [ "Maradona", "El Diego", "El Diego ( el 10 )", "|()|", "æßðæßð", "\ hello \ ", "*", ] gm = GazetteManager() for text in texts: escaped = gm.escape_text(text) self.assertEqual(escaped.count("\Q"), len(text.split())) self.assertEqual(escaped.count("\E"), len(text.split()))
def _test_single_gazette(self, text=None): if text: gazette_item = GazetteItemFactory(text=text) else: gazette_item = GazetteItemFactory() gzmanager = GazetteManager() filepath = gzmanager.generate_stanford_gazettes_file() self.assertNotEqual(filepath, None) data = open(filepath).read().split("\n") self.assertEqual(len(data), 2) data = data[0].split("\t") self.assertEqual(len(data), 3) self.assertEqual(data[0], gzmanager.escape_text(gazette_item.text)) self.assertEqual(data[1], "{}{}".format(gzmanager._PREFIX, gazette_item.kind.name)) gazette_item.delete()
def test_generate_gazettes_several_lines(self): [GazetteItemFactory() for x in range(10)] filepath = GazetteManager().generate_stanford_gazettes_file() self.assertNotEqual(filepath, None) data = open(filepath).read() self.assertEqual(data.count("\n"), 10) for line in data.split("\n")[:-1]: self.assertEqual(line.count("\t"), 2)
def test_generate_gazettes_file_empty(self): self.assertEqual(GazetteManager().generate_stanford_gazettes_file(), None)