def test_search_reference_filewise(self, filename, content_strs,
                                    true_outputs):
     for content, true_output in zip(content_strs, true_outputs):
         reference = arxiv_latex_cleaner._search_reference(
             filename, content, False)
         matched = reference is not None
         msg_not = ' ' if true_output else ' not '
         msg = '{} should have{}matched {}'.format(filename, msg_not,
                                                   content)
         self.assertEqual(matched, true_output, msg)
    def test_search_reference_strict(self, filenames, contents,
                                     extension_optional, true_outputs):
        cleaner_outputs = []
        for filename in filenames:
            reference = arxiv_latex_cleaner._search_reference(
                filename, contents, extension_optional)
            if reference is not None:
                cleaner_outputs.append(filename)

        # strict check (set of files must match exactly)
        self.assertEqual(cleaner_outputs, true_outputs)
    def test_search_reference_weak(self, filenames, contents, strict,
                                   true_outputs):
        cleaner_outputs = []
        for filename in filenames:
            reference = arxiv_latex_cleaner._search_reference(
                filename, contents, strict)
            if reference is not None:
                cleaner_outputs.append(filename)

        # weak check (passes as long as cleaner includes a superset of the true_output)
        for true_output in true_outputs:
            self.assertIn(true_output, cleaner_outputs)
 def test_search_reference_filewise(self, filename, content_strs, strict,
                                    true_outputs):
     if len(content_strs) != len(true_outputs):
         raise ValueError(
             "number of true_outputs doesn't match number of content strs")
     for content, true_output in zip(content_strs, true_outputs):
         reference = arxiv_latex_cleaner._search_reference(
             filename, content, strict)
         matched = reference is not None
         msg_not = ' ' if true_output else ' not '
         msg_fmt = 'file {} should' + msg_not + 'have matched latex reference {}'
         msg = msg_fmt.format(filename, content)
         self.assertEqual(matched, true_output, msg)
    def test_search_reference_strong(self, filenames, contents, strict,
                                     true_outputs):
        cleaner_outputs = []
        for filename in filenames:
            reference = arxiv_latex_cleaner._search_reference(
                filename, contents, strict)
            if reference is not None:
                cleaner_outputs.append(filename)

        # strong check (set of files must match exactly)
        weak_check_result = set(true_outputs).issubset(cleaner_outputs)
        if weak_check_result:
            msg = 'not fatal, cleaner included more files than necessary'
        else:
            msg = 'fatal, see test_search_reference_weak'
        self.assertEqual(cleaner_outputs, true_outputs, msg)