class CoverageTest(unittest.TestCase): def setUp(self): self.tokenizer = Tokenizer() self.parser = Parser() self.test_dir = mkdtemp() self.debian_dir = os.path.join(self.test_dir, "debian") self.copyright_file_path = os.path.join(self.debian_dir, "copyright") os.makedirs(self.debian_dir) def fake_file(self, filename, dir=None): if dir is None: dir = self.test_dir with open(os.path.join(dir, filename), 'w'): pass def get_paragraphs(self, txt): open(self.copyright_file_path, 'w').write("".join(txt)) paragraphs = self.tokenizer.get_paragraphs(txt) self.parser._guess_types(paragraphs) self.parser.process(paragraphs) return paragraphs def test_test(self): self.fake_file("foobar.foo") self.fake_file("sara.sa", self.debian_dir) paragraphs = self.get_paragraphs(two_fp_without_header) coverage = Coverage(paragraphs, self.test_dir)
def _test_format_with_initial_null_lines(self): data = "\n\n\nFormat: %s" % self.url dlt_parser = Parser() data_parsed = dlt_parser.parse(data.splitlines(True)) for paragraph in data_parsed: paragraph_content = paragraph["content"] self.assertEqual("header", paragraph["type"]) for field in paragraph_content: field_content = field["content"] self.assertTrue("Format" in field_content) self.assertEqual(field_content["Format"][0].strip(), self.url) self.assertEqual("single_line_values", field["type"])
class RuleTest(unittest.TestCase): def setUp(self): self.tokenizer = Tokenizer() self.parser = Parser() def get_paragraphs(self, txt): paragraphs = self.tokenizer.get_paragraphs(txt) self.parser._guess_types(paragraphs) return paragraphs def print_messages(self, rule): for message in rule.messages: self.parser._print_message(message)
def setUp(self): self.tokenizer = Tokenizer() self.parser = Parser() self.test_dir = mkdtemp() self.debian_dir = os.path.join(self.test_dir, "debian") self.copyright_file_path = os.path.join(self.debian_dir, "copyright") os.makedirs(self.debian_dir)
def setUp(self): self.tokenizer = Tokenizer() self.parser = Parser()
def _test_data_is_empty(self): data = "" dlt_parser = Parser() data_parsed = dlt_parser.parse(data) self.assertEqual(data_parsed, [])
def test_default_init(self): tokenizer = Tokenizer() paragraphs = tokenizer.get_paragraphs(two_fp_with_invalid_field) parser = Parser() self.assertFalse(parser.process(paragraphs))