diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1fed4b0..0c3d1af 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,15 +1,15 @@ repos: - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 25.1.0 hooks: - id: black args: [--line-length=80] - repo: https://github.com/PyCQA/flake8 - rev: "3.8.4" + rev: "7.2.0" hooks: - id: flake8 - repo: https://github.com/asottile/pyupgrade - rev: v2.7.4 + rev: v3.19.1 hooks: - id: pyupgrade args: [--py36-plus] diff --git a/morepath_wiki/html.py b/morepath_wiki/html.py index efb04ee..eceee26 100644 --- a/morepath_wiki/html.py +++ b/morepath_wiki/html.py @@ -346,7 +346,7 @@ def __exit__(self, exc_type, exc_value, exc_tb): self._stack.pop() def __repr__(self): - return "".format(self._name, id(self)) + return f"" def _stringify(self, str_type): # turn me and my content into text @@ -424,19 +424,19 @@ def _stringify(self, str_type): class TestCase(unittest.TestCase): def test_empty_tag(self): "generation of an empty HTML tag" - self.assertEquals(str(HTML().br), "
") + self.assertEqual(str(HTML().br), "
") def test_empty_tag_xml(self): "generation of an empty XHTML tag" - self.assertEquals(str(XHTML().br), "
") + self.assertEqual(str(XHTML().br), "
") def test_tag_add(self): "test top-level tag creation" - self.assertEquals(str(HTML("html", "text")), "\ntext\n") + self.assertEqual(str(HTML("html", "text")), "\ntext\n") def test_tag_add_no_newline(self): "test top-level tag creation" - self.assertEquals( + self.assertEqual( str(HTML("html", "text", newlines=False)), "text" ) @@ -445,7 +445,7 @@ def test_iadd_tag(self): h = XML("xml") h += XML("some-tag", "spam", newlines=False) h += XML("text", "spam", newlines=False) - self.assertEquals( + self.assertEqual( str(h), "\nspam\nspam\n", ) @@ -455,63 +455,63 @@ def test_iadd_text(self): h = HTML("html", newlines=False) h += "text" h += "text" - self.assertEquals(str(h), "texttext") + self.assertEqual(str(h), "texttext") def test_xhtml_match_tag(self): "check forced generation of matching tag when empty" - self.assertEquals(str(XHTML().p), "

") + self.assertEqual(str(XHTML().p), "

") if sys.version_info[0] == 2: def test_empty_tag_unicode(self): "generation of an empty HTML tag" - self.assertEquals(unicode(HTML().br), unicode("
")) + self.assertEqual(unicode(HTML().br), unicode("
")) def test_empty_tag_xml_unicode(self): "generation of an empty XHTML tag" - self.assertEquals(unicode(XHTML().br), unicode("
")) + self.assertEqual(unicode(XHTML().br), unicode("
")) def test_xhtml_match_tag_unicode(self): "check forced generation of matching tag when empty" - self.assertEquals(unicode(XHTML().p), unicode("

")) + self.assertEqual(unicode(XHTML().p), unicode("

")) def test_just_tag(self): "generate HTML for just one tag" - self.assertEquals(str(HTML().br), "
") + self.assertEqual(str(HTML().br), "
") def test_just_tag_xhtml(self): "generate XHTML for just one tag" - self.assertEquals(str(XHTML().br), "
") + self.assertEqual(str(XHTML().br), "
") def test_xml(self): "generate XML" - self.assertEquals(str(XML().br), "
") - self.assertEquals(str(XML().p), "

") - self.assertEquals(str(XML().br("text")), "
text
") + self.assertEqual(str(XML().br), "
") + self.assertEqual(str(XML().p), "

") + self.assertEqual(str(XML().br("text")), "
text
") def test_para_tag(self): "generation of a tag with contents" h = HTML() h.p("hello") - self.assertEquals(str(h), "

hello

") + self.assertEqual(str(h), "

hello

") def test_escape(self): "escaping of special HTML characters in text" h = HTML() h.text("<>&") - self.assertEquals(str(h), "<>&") + self.assertEqual(str(h), "<>&") def test_no_escape(self): "no escaping of special HTML characters in text" h = HTML() h.text("<>&", False) - self.assertEquals(str(h), "<>&") + self.assertEqual(str(h), "<>&") def test_escape_attr(self): "escaping of special HTML characters in attributes" h = HTML() h.br(id='<>&"') - self.assertEquals(str(h), '
') + self.assertEqual(str(h), '
') def test_subtag_context(self): 'generation of sub-tags using "with" context' @@ -519,7 +519,7 @@ def test_subtag_context(self): with h.ol: h.li("foo") h.li("bar") - self.assertEquals(str(h), "
    \n
  1. foo
  2. \n
  3. bar
  4. \n
") + self.assertEqual(str(h), "
    \n
  1. foo
  2. \n
  3. bar
  4. \n
") def test_subtag_direct(self): "generation of sub-tags directly on the parent tag" @@ -527,7 +527,7 @@ def test_subtag_direct(self): l = h.ol l.li("foo") l.li.b("bar") - self.assertEquals( + self.assertEqual( str(h), "
    \n
  1. foo
  2. \n
  3. bar
  4. \n
" ) @@ -537,7 +537,7 @@ def test_subtag_direct_context(self): with h.ol as l: l.li("foo") l.li.b("bar") - self.assertEquals( + self.assertEqual( str(h), "
    \n
  1. foo
  2. \n
  3. bar
  4. \n
" ) @@ -547,35 +547,35 @@ def test_subtag_no_newlines(self): l = h.ol(newlines=False) l.li("foo") l.li("bar") - self.assertEquals(str(h), "
  1. foo
  2. bar
") + self.assertEqual(str(h), "
  1. foo
  2. bar
") def test_add_text(self): "add text to a tag" h = HTML() p = h.p("hello, world!\n") p.text("more text") - self.assertEquals(str(h), "

hello, world!\nmore text

") + self.assertEqual(str(h), "

hello, world!\nmore text

") def test_add_text_newlines(self): "add text to a tag with newlines for prettiness" h = HTML() p = h.p("hello, world!", newlines=True) p.text("more text") - self.assertEquals(str(h), "

\nhello, world!\nmore text\n

") + self.assertEqual(str(h), "

\nhello, world!\nmore text\n

") def test_doc_newlines(self): "default document adding newlines between tags" h = HTML() h.br h.br - self.assertEquals(str(h), "
\n
") + self.assertEqual(str(h), "
\n
") def test_doc_no_newlines(self): "prevent document adding newlines between tags" h = HTML(newlines=False) h.br h.br - self.assertEquals(str(h), "

") + self.assertEqual(str(h), "

") def test_unicode(self): "make sure unicode input works and results in unicode output" @@ -588,7 +588,7 @@ def test_unicode(self): unicode = str TEST = "euro €" h.p(TEST) - self.assertEquals(unicode(h), "

%s

" % TEST) + self.assertEqual(unicode(h), "

%s

" % TEST) def test_table(self): 'multiple "with" context blocks' @@ -598,7 +598,7 @@ def test_table(self): with h.tr: h.td("column 1") h.td("column 2") - self.assertEquals( + self.assertEqual( str(h), """
column 1column 2