Skip to content

Commit

Permalink
Merge pull request #180 from boxine/fix-doctest
Browse files Browse the repository at this point in the history
Fix doctest + update requirements
  • Loading branch information
phihag authored Aug 23, 2023
2 parents 6a3a15b + 86687ad commit 425c7ee
Show file tree
Hide file tree
Showing 10 changed files with 631 additions and 680 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
*.egg-info
__pycache__
/dist/
/coverage.json
/coverage.xml
/coverage.*

!.github
!.editorconfig
!.flake8
!.gitignore
!.gitkeep
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Assert complex output via auto updated snapshot files with nice diff error messa

#### bx_py_utils.test_utils.unittest_utils

* [`BaseDocTests()`](https://github.com/boxine/bx_py_utils/blob/master/bx_py_utils/test_utils/unittest_utils.py#L40-L87) - Helper to include all doctests in unittests, without change unittest setup. Just add a normal TestCase.
* [`BaseDocTests()`](https://github.com/boxine/bx_py_utils/blob/master/bx_py_utils/test_utils/unittest_utils.py#L40-L91) - Helper to include all doctests in unittests, without change unittest setup. Just add a normal TestCase.
* [`assert_no_flat_tests_functions()`](https://github.com/boxine/bx_py_utils/blob/master/bx_py_utils/test_utils/unittest_utils.py#L16-L30) - Check if there exists normal test functions (That will not be executed by normal unittests)

### bx_py_utils.text_tools
Expand Down
10 changes: 5 additions & 5 deletions bx_py_utils/doc_write/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ Notes:

### Notes

* The created created Markdown file is relative to `output_base_path` (defined in `pyproject.toml`)

* Headlines will be sorted, so they appears ordered by the level.

* All Doc-String without the `{prefix}` will be ignored.

* The `{file-path}` must has the file extension `.md`
Otherwise the DocString block will be ignored.
Otherwise the DocString block will be ignored.

* The created created Markdown file is relative to `output_base_path` (defined in `pyproject.toml`)

* Headlines will be sorted, so they appears ordered by the level.
2 changes: 1 addition & 1 deletion bx_py_utils/html_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def pretty_format_html(data, parser='html.parser', **bs_kwargs):
Pretty format given HTML document via BeautifulSoup (Needs 'beautifulsoup4' package)
"""
soup = get_beautiful_soup_instance(data, parser, **bs_kwargs)
return soup.prettify()
return soup.prettify().rstrip()


def get_html_elements(data, query_selector, parser='html.parser', **bs_kwargs):
Expand Down
6 changes: 5 additions & 1 deletion bx_py_utils/test_utils/unittest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ def run_doctests(

for module in modules:
self.assertTrue(inspect.ismodule(module), f'Not a module: {module}')

for info in pkgutil.walk_packages(module.__path__, module.__name__ + '.'):
module_finder = info.module_finder
module_path = module_finder.path
if filename_matcher(patterns=excludes, file_path=module_path):
continue

module = importlib.import_module(info.name)
tests: list[doctest.DocTest] = finder.find(obj=module)
for test in tests:
Expand Down
2 changes: 1 addition & 1 deletion bx_py_utils_tests/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from pathlib import Path

from cli_base.cli_tools.subprocess_utils import verbose_check_call
from manageprojects.utilities.publish import publish_package
from manageprojects.utilities.subprocess_utils import verbose_check_call

import bx_py_utils

Expand Down
14 changes: 8 additions & 6 deletions bx_py_utils_tests/tests/test_html_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,24 @@ def test_validate_html(self):
)

def test_pretty_format_html(self):
assert pretty_format_html('<p>Test</p>') == '<p>\n Test\n</p>'
self.assertEqual(pretty_format_html('<p>Test</p>'), '<p>\n Test\n</p>')

html = pretty_format_html(
'''
\r\n <h1>X</h1> \r\n \r\n
<p><strong>Test</strong></p> \r\n \r\n
'''
)
assert html == '<h1>\n X\n</h1>\n<p>\n <strong>\n Test\n </strong>\n</p>\n'
self.assertEqual(html, '<h1>\n X\n</h1>\n<p>\n <strong>\n Test\n </strong>\n</p>')

assert pretty_format_html("<code>&lt;script&gt;alert('XSS')&lt;/script&gt;</code>") == (
'<code>\n' " &lt;script&gt;alert('XSS')&lt;/script&gt;\n" '</code>'
self.assertEqual(
pretty_format_html("<code>&lt;script&gt;alert('XSS')&lt;/script&gt;</code>"),
('<code>\n' " &lt;script&gt;alert('XSS')&lt;/script&gt;\n" '</code>'),
)

assert pretty_format_html('<p>&lt;XSS énc🕳d&#128065;ng&gt; a&#97;&#x61;</p>') == (
'<p>\n &lt;XSS énc🕳d👁ng&gt; aaa\n</p>'
self.assertEqual(
pretty_format_html('<p>&lt;XSS énc🕳d&#128065;ng&gt; a&#97;&#x61;</p>'),
('<p>\n &lt;XSS énc🕳d👁ng&gt; aaa\n</p>'),
)

# Our helpful error message if requirements missing?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ <h1>
This is a paragraph.
</p>
</body>
</html>
</html>
1,264 changes: 603 additions & 661 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bx_py_utils"
version = "85"
version = "86"
description = "Various Python utility functions"
homepage = "https://github.com/boxine/bx_py_utils/"
authors = [
Expand Down Expand Up @@ -38,6 +38,7 @@ flake8 = "*" # https://github.com/pycqa/flake8
EditorConfig = "*" # https://github.com/editorconfig/editorconfig-core-py
safety = "*" # https://github.com/pyupio/safety
mypy = "*" # https://github.com/python/mypy
cli-base-utilities = "*" # https://github.com/jedie/cli-base-utilities
manageprojects = "*" # https://github.com/jedie/manageprojects
twine = "*" # https://github.com/pypa/twine
beautifulsoup4 = "*"
Expand Down Expand Up @@ -90,6 +91,7 @@ lines_after_imports=2
branch = true
parallel = true
source = ['.']
concurrency = ["multiprocessing"]
command_line = "-m unittest --locals --verbose"

[tool.coverage.report]
Expand Down Expand Up @@ -146,6 +148,7 @@ applied_migrations = [
"cf44769", # 2023-01-11T08:15:06+01:00
"01611af", # 2023-01-25T09:47:16+01:00
"04d5a25", # 2023-03-07T16:25:36+01:00
"be3f649", # 2023-08-22T19:36:57+02:00
]

[manageprojects.cookiecutter_context.cookiecutter]
Expand Down

0 comments on commit 425c7ee

Please sign in to comment.