def test_formulas(self):
     test_inputs = [
         "Formula (e.g. $\sqrt[5]{8547799037)}$.",
         "$$ blok formula [no] [detection](test) \n nor [ref]:abc.com $$",
         "\$ there is [formula] \$",
         "\$ not even in [link \$ test]: reference",
     ]
     test_outputs = [
         [],
         [],
         [
             Reference(Reference.Type.IMPLICIT, False, "formula", "", False,
                       1)
         ],
         [
             Reference(
                 Reference.Type.EXPLICIT,
                 False,
                 "link \$ test",
                 "reference",
                 False,
                 1,
             )
         ],
     ]
     self.make_comparison(test_inputs, test_outputs, "Formula links")
 def test_labeled_links(self):
     test_inputs = [
         "[I'm a reference-style link][Case-insensitive text]",
         "![You can use numbers for reference - style link definitions][1]",
     ]
     test_outputs = [
         [
             Reference(
                 Reference.Type.IMPLICIT,
                 False,
                 "Case-insensitive text",
                 is_footnote=False,
                 line_number=1,
             )
         ],
         [
             Reference(
                 Reference.Type.IMPLICIT,
                 True,
                 "1",
                 is_footnote=False,
                 line_number=1,
             )
         ],
     ]
     self.make_comparison(test_inputs, test_outputs, "Labeled links")
 def test_parsing_inline_links(self):
     test_inputs = [
         "\nThis is an [inline link](/url), \n and here's [one with \n a "
         'title](http://fsf.org "click here for a good time!").',
         "[Write me!](mailto:[email protected])",
         "[I'm an inline link](https://www.google.com)",
         "[I'm inline with title](https://www.google.com"
         ' "Google\'s Homepage")',
     ]
     test_outputs = [
         [
             Reference(
                 Reference.Type.INLINE,
                 False,
                 "inline link",
                 "/url",
                 False,
                 2,
             ),
             Reference(
                 Reference.Type.INLINE,
                 False,
                 "one with \n a title",
                 "http://fsf.org",
                 False,
                 3,
             ),
         ],
         [
             Reference(
                 Reference.Type.INLINE,
                 False,
                 "Write me!",
                 "mailto:[email protected]",
                 False,
                 1,
             )
         ],
         [
             Reference(
                 Reference.Type.INLINE,
                 False,
                 "I'm an inline link",
                 "https://www.google.com",
                 False,
                 1,
             )
         ],
         [
             Reference(
                 Reference.Type.INLINE,
                 False,
                 "I'm inline with title",
                 "https://www.google.com",
                 False,
                 1,
             )
         ],
     ]
     self.make_comparison(test_inputs, test_outputs, "Inline links")
 def test_line_nums(self):
     test_inputs = [
         "\n[second]\n![third][]\n\n[fif\nth](k01.md)\nab [second]: k07.md"]
     test_outputs = [
         [Reference(Reference.Type.IMPLICIT, False, "second", "", False, 2),
          Reference(Reference.Type.IMPLICIT, True, "third", "", False, 3),
          Reference(Reference.Type.INLINE, False, "fif\nth", "k01.md",
                    False, 5),
          Reference(Reference.Type.EXPLICIT, False, "second", "k07.md",
                    False, 7)]]
     self.make_comparison(test_inputs, test_outputs, "Line numbers")
    def test_www_unchecked(self):
        ref_1 = Reference(Reference.Type.INLINE, False, identifier="link_1",
                          link="WWW.google.de", line_number=1)
        ref_2 = Reference(Reference.Type.INLINE, False, identifier="link_2",
                          link="www.google.cz", line_number=2)
        for ref in [ref_1, ref_2]:
            ref.file_path = "path"

        checker = linkchecker.LinkChecker([ref_1, ref_2], {})
        checker.run_checks()

        self.assertEqual(checker.errors, [])
 def test_reference_footnotes(self):
     test_inputs = [
         "[^1]: [k05025](k0502.html#head-1) asdsad\nasdsad\n\nabc",
         "[^2]: not to be tested",
         "[^3]: test\n",
         "![^extended]: http://fsf.org \n(Foundation)\n\nabc",
     ]
     test_outputs = [
         [
             Reference(
                 Reference.Type.EXPLICIT,
                 False,
                 "^1",
                 "[k05025](k0502.html#head-1) asdsad\nasdsad",
                 True,
                 1,
             ),
             Reference(
                 Reference.Type.INLINE,
                 False,
                 "k05025",
                 "k0502.html#head-1",
                 False,
                 1,
             ),
         ],
         [
             Reference(
                 Reference.Type.EXPLICIT,
                 False,
                 "^2",
                 "not to be tested",
                 True,
                 1,
             )
         ],
         [
             Reference(Reference.Type.EXPLICIT, False, "^3", "test\n", True,
                       1)
         ],
         [
             Reference(
                 Reference.Type.EXPLICIT,
                 True,
                 "^extended",
                 "http://fsf.org \n(Foundation)",
                 True,
                 1,
             )
         ],
     ]
     self.make_comparison(test_inputs, test_outputs, "Footnote links")
 def test_standalone_links(self):
     # standalone links are specific types of labeled links
     test_inputs = [
         "See [my website][].",
         "[1]\n\![test][]\nabc ![test2] def"]
     test_outputs = [
         [Reference(Reference.Type.IMPLICIT, False, "my website",
                    is_footnote=False, line_number=1)],
         [Reference(Reference.Type.IMPLICIT, False, "1", is_footnote=False,
                    line_number=1),
          Reference(Reference.Type.IMPLICIT, False, "test",
                    is_footnote=False, line_number=2),
          Reference(Reference.Type.IMPLICIT, True, "test2",
                    is_footnote=False, line_number=3)]
     ]
     self.make_comparison(test_inputs, test_outputs, "Standalone links")
 def test_nested_inlines(self):
     test_inputs = ["[![Bildbeschreibung](bilder/test.jpg)](bild.html#"
                    "title-of-the-graphic)",
                    "[ ![Bildbeschreib](bilder/bild1.PNG) ]"
                    "(bilder.html#bildb)\n\n|| - Seite 4 - \nabc"
                    "[www.schattauer.de](www.schatt.de)",
                    "[^1]: [k05025](bilder.html#heading-1) asdsad"]
     test_outputs = [
         [Reference(Reference.Type.INLINE, False,
                    "![Bildbeschreibung](bilder/test.jpg)",
                    "bild.html#title-of-the-graphic", False, 1),
          Reference(Reference.Type.INLINE, True, "Bildbeschreibung",
                    "bilder/test.jpg", False, 1)],
         [Reference(Reference.Type.INLINE, False,
                    " ![Bildbeschreib](bilder/bild1.PNG) ",
                    "bilder.html#bildb", False, 1),
          Reference(Reference.Type.INLINE, True, "Bildbeschreib",
                    "bilder/bild1.PNG", False, 1),
          Reference(Reference.Type.INLINE, False, "www.schattauer.de",
                    "www.schatt.de", False, 4)],
         [Reference(Reference.Type.EXPLICIT, False, "^1",
                    "[k05025](bilder.html#heading-1) asdsad", True, 1),
          Reference(Reference.Type.INLINE, False,
                    "k05025", "bilder.html#heading-1", False, 1)]
     ]
     self.make_comparison(test_inputs, test_outputs, "Inline nested")
Beispiel #9
0
    def test_duplicities(self):
        ref_1 = Reference(
            Reference.Type.EXPLICIT,
            False,
            identifier="link_1",
            link="k01.html",
            line_number=1,
        )
        ref_2 = Reference(
            Reference.Type.EXPLICIT,
            False,
            identifier="link_2",
            link="k01.html",
            line_number=2,
        )

        checker = linkchecker.LinkChecker([ref_1, ref_2], {})
        checker.find_label_duplicates()
        self.assertEqual(checker.errors, [])

        ref_3 = Reference(
            Reference.Type.EXPLICIT,
            False,
            identifier="link_1",
            link="k01.html",
            line_number=1,
        )
        ref_4 = Reference(
            Reference.Type.EXPLICIT,
            False,
            identifier="link_2",
            link="k01.html",
            line_number=2,
        )

        checker = linkchecker.LinkChecker([ref_1, ref_2, ref_3], {})
        checker.find_label_duplicates()
        self.assertEqual(len(checker.errors), 1)
        self.assertTrue(checker.errors[0].lineno, 1)

        checker = linkchecker.LinkChecker([ref_1, ref_2, ref_3, ref_4], {})
        checker.find_label_duplicates()
        self.assertTrue(checker.errors[0].lineno, 1)
        self.assertTrue(checker.errors[1].lineno, 2)
    def test_target_exist(self):
        # add testing of hand-made temp file existence
        ref_1 = Reference(Reference.Type.EXPLICIT, False, identifier="link_1",
                          link="nonsense path with space", line_number=1)

        checker = linkchecker.LinkChecker([], {})
        checker.target_exists(self.get_path(ref_1), ref_1,
                              "nonsenspath with space")
        self.assertEqual(len(checker.errors), 1)
        self.assertEqual(checker.errors[0].lineno, 1)
    def test_coupling_references(self):
        reference_1 = Reference(Reference.Type.EXPLICIT, False,
                                link="k01.html", identifier="1", line_number=1)
        reference_2 = Reference(Reference.Type.IMPLICIT, False, identifier="2",
                                line_number=2)

        reference_expl_ok = Reference(Reference.Type.EXPLICIT, False,
                                      identifier="2", link="k01.html")
        reference_expl_nok = Reference(Reference.Type.EXPLICIT, False,
                                       identifier="non-existing-link",
                                       link="k01.html", line_number=8)
        reference_impl_ok = Reference(Reference.Type.IMPLICIT, False,
                                      identifier="1", link="k01.html",
                                      line_number=10)
        reference_impl_nok = Reference(Reference.Type.IMPLICIT, False,
                                       identifier="incorrect", line_number=12)

        checker = linkchecker.LinkChecker([reference_2], {})
        checker.find_link_for_identifier(reference_expl_ok)
        self.assertEqual(checker.errors, [])
        checker.find_link_for_identifier(reference_expl_nok)
        self.assertEqual(len(checker.errors), 1)
        self.assertEqual(checker.errors[0].lineno, 8)

        checker = linkchecker.LinkChecker([reference_1], {})
        checker.find_label_for_link(reference_impl_ok)
        self.assertEqual(checker.errors, [])
        checker.find_label_for_link(reference_impl_nok)
        self.assertEqual(len(checker.errors), 1)
        self.assertEqual(checker.errors[0].lineno, 12)
    def test_correct_extension(self):
        correct_ref = Reference(Reference.Type.EXPLICIT, False,
                                link="k01.html", line_number=10)
        html_instead_img = Reference(Reference.Type.EXPLICIT, True,
                                     link="k01.html", line_number=1)
        jpq_instead_html = Reference(Reference.Type.EXPLICIT, False,
                                     link="k01.jpg", line_number=2)
        md_instead_html = Reference(Reference.Type.EXPLICIT, False,
                                    link="k01.md", line_number=3)

        checker = linkchecker.LinkChecker([], {})
        checker.is_correct_extension(self.get_path(correct_ref), correct_ref)
        self.assertEqual(checker.errors, [])
        checker.is_correct_extension(self.get_path(html_instead_img),
                                     html_instead_img)
        checker.is_correct_extension(self.get_path(jpq_instead_html),
                                     jpq_instead_html)
        checker.is_correct_extension(self.get_path(md_instead_html),
                                     md_instead_html)
        self.assertEqual(len(checker.errors), 3)
        for i in range(len(checker.errors)):
            self.assertEqual(checker.errors[i].lineno, i + 1)
 def test_reference_links(self):
     test_inputs = [
         "[my label 1]: /foo/bar.html  \"My title, optional\"",
         "[my label 2]: /foo",
         "[my label 3]: http://fsf.org (The free software foundation)",
         "[my label 4]: /bar#Special  'A title in single quotes'",
         "[my label 5]: <http://foo.bar.baz>",
         "\n[my label 6]: http://fsf.org \n\t\"The free sw foundation\""]
     test_outputs = [
         [Reference(Reference.Type.EXPLICIT, False, "my label 1",
                    "/foo/bar.html", False, 1)],
         [Reference(Reference.Type.EXPLICIT, False, "my label 2", "/foo",
                    False, 1)],
         [Reference(Reference.Type.EXPLICIT, False, "my label 3",
                    "http://fsf.org", False, 1)],
         [Reference(Reference.Type.EXPLICIT, False, "my label 4",
                    "/bar#Special", False, 1)],
         [Reference(Reference.Type.EXPLICIT, False, "my label 5",
                    "http://foo.bar.baz", False, 1)],
         [Reference(Reference.Type.EXPLICIT, False, "my label 6",
                    "http://fsf.org", False, 2)]
     ]
     self.make_comparison(test_inputs, test_outputs, "Reference links")
 def test_other_links(self):
     test_inputs = [
         "- [x] Finish changes\n[ ] Push my commits to GitHub",
         "<div><div id=\"my_ID\"/><span></span></div><span/>"
         "<DiV><DIV id=\"my_id2\"><SPAN>[tEst](#TesT)</SPAN></DiV><SPAN/>",
         "Seiten: [[15]](#seite-15--),\n [[20]](#seite-20--)",
         " \[RT\], errors) or biological (electromyographic \[EMG\]",
         "[a\[], [\]], [\[\]] and \n[](\])",
         "[po\\\[abc\\\][d]kus\](normal)",
         "\![image](google.jpg)",
         r"\\[this\\\[this not\]\\]"
         ]
     test_outputs = [
         [],
         [Reference(Reference.Type.INLINE, False, "tEst", "#TesT", False,
                    1)],
         [Reference(Reference.Type.INLINE, False, "[15]", "#seite-15--",
                    False, 1),
          Reference(Reference.Type.IMPLICIT, False, "15", None, False, 1),
          Reference(Reference.Type.INLINE, False, "[20]", "#seite-20--",
                    False, 2),
          Reference(Reference.Type.IMPLICIT, False, "20", None, False, 2)],
         [],
         [Reference(Reference.Type.IMPLICIT, False, "a\[", None, False, 1),
          Reference(Reference.Type.IMPLICIT, False, "\]", None, False, 1),
          Reference(Reference.Type.IMPLICIT, False, "\[\]", None, False, 1),
          Reference(Reference.Type.INLINE, False, "", "\]", False, 2)],
         [Reference(Reference.Type.IMPLICIT, False,
                    "po\\\\[abc\\\\][d]kus\\](normal", None, False, 1),
          Reference(Reference.Type.IMPLICIT, False, "d", None, False, 1)],
         [Reference(Reference.Type.INLINE, False, "image", "google.jpg",
                    False, 1)],
         [Reference(Reference.Type.IMPLICIT, False, r"this\\\[this not\]\\",
                    None, False, 1)]
         ]
     self.make_comparison(test_inputs, test_outputs, "Other links")