Skip to content

Fix test/normalize.py so it runs on Python 3.8.#216

Closed
bolinfest wants to merge 1 commit intogithub:masterfrom
bolinfest:cgi-escape-fix
Closed

Fix test/normalize.py so it runs on Python 3.8.#216
bolinfest wants to merge 1 commit intogithub:masterfrom
bolinfest:cgi-escape-fix

Conversation

@bolinfest
Copy link

@bolinfest bolinfest commented Apr 9, 2021

cgi.escape was removed in Python 3.8, so fall back to
html.escape in that case.

Test Plan:

$ python3 -V
Python 3.8.6
$ make test
Running tests...
Test project /Users/mbolin/src/cmark-gfm/build
      Start  1: api_test
 1/13 Test  #1: api_test ...............................   Passed    0.18 sec
      Start  2: html_normalization
 2/13 Test  #2: html_normalization .....................   Passed    0.13 sec
      Start  3: spectest_library
 3/13 Test  #3: spectest_library .......................   Passed    0.15 sec
      Start  4: pathological_tests_library
 4/13 Test  #4: pathological_tests_library .............   Passed   58.57 sec
      Start  5: roundtriptest_library
 5/13 Test  #5: roundtriptest_library ..................   Passed    0.42 sec
      Start  6: entity_library
 6/13 Test  #6: entity_library .........................   Passed    0.12 sec
      Start  7: spectest_executable
 7/13 Test  #7: spectest_executable ....................   Passed    3.24 sec
      Start  8: smartpuncttest_executable
 8/13 Test  #8: smartpuncttest_executable ..............   Passed    0.14 sec
      Start  9: extensions_executable
 9/13 Test  #9: extensions_executable ..................   Passed    0.19 sec
      Start 10: roundtrip_extensions_executable
10/13 Test #10: roundtrip_extensions_executable ........   Passed    0.31 sec
      Start 11: option_table_prefer_style_attributes
11/13 Test #11: option_table_prefer_style_attributes ...   Passed    0.10 sec
      Start 12: option_full_info_string
12/13 Test #12: option_full_info_string ................   Passed    0.12 sec
      Start 13: regressiontest_executable
13/13 Test #13: regressiontest_executable ..............   Passed    0.15 sec

100% tests passed, 0 tests failed out of 13

Total Test time (real) =  63.83 sec

`cgi.escape` was removed in Python 3.8, so fall back to
`html.escape` in that case.

Test Plan:
```
$ python3 -V
Python 3.8.6
$ python3 -m doctest test/normalize.py --verbose
Trying:
    normalize_html("<p>a  \t b</p>")
Expecting:
    '<p>a b</p>'
ok
Trying:
    normalize_html("<p>a  \t\nb</p>")
Expecting:
    '<p>a b</p>'
ok
Trying:
    normalize_html("<p>a  b</p>")
Expecting:
    '<p>a b</p>'
ok
Trying:
    normalize_html(" <p>a  b</p>")
Expecting:
    '<p>a b</p>'
ok
Trying:
    normalize_html("<p>a  b</p> ")
Expecting:
    '<p>a b</p>'
ok
Trying:
    normalize_html("\n\t<p>\n\t\ta  b\t\t</p>\n\t")
Expecting:
    '<p>a b</p>'
ok
Trying:
    normalize_html("<i>a  b</i> ")
Expecting:
    '<i>a b</i> '
ok
Trying:
    normalize_html("<br />")
Expecting:
    '<br>'
ok
Trying:
    normalize_html('<a title="bar" href="proxy.php?url=foo">x</a>')
Expecting:
    '<a href="proxy.php?url=foo" title="bar">x</a>'
ok
Trying:
    normalize_html("&forall;&amp;&gt;&lt;&quot;")
Expecting:
    '\u2200&amp;&gt;&lt;&quot;'
ok
16 items had no tests:
    normalize
    normalize.HTMLParseError
    normalize.MyHTMLParser
    normalize.MyHTMLParser.__init__
    normalize.MyHTMLParser.handle_charref
    normalize.MyHTMLParser.handle_comment
    normalize.MyHTMLParser.handle_data
    normalize.MyHTMLParser.handle_decl
    normalize.MyHTMLParser.handle_endtag
    normalize.MyHTMLParser.handle_entityref
    normalize.MyHTMLParser.handle_pi
    normalize.MyHTMLParser.handle_startendtag
    normalize.MyHTMLParser.handle_starttag
    normalize.MyHTMLParser.is_block_tag
    normalize.MyHTMLParser.output_char
    normalize.MyHTMLParser.unknown_decl
1 items passed all tests:
  10 tests in normalize.normalize_html
10 tests in 17 items.
10 passed and 0 failed.
Test passed.
```
@bolinfest
Copy link
Author

Oh, basically the same as #184. This has the cgi.escape() fallback, though perhaps that's not desirable?

@phillmv
Copy link
Member

phillmv commented Aug 23, 2021

Thanks for your help; I kind of arbitrarily picked #184 instead on the assumption that supporting multiple Python versions is maybe more work than its worth.

@phillmv phillmv closed this Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants