Skip to content

Commit

Permalink
Improve test reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Mar 30, 2022
1 parent dd71dd1 commit 368d562
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
23 changes: 12 additions & 11 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,20 @@ def build_docs_setup(
:return: Object with results of command
:rtype: click.testing.Result
"""
cmd_args = [
"--clean",
"--config-file",
f"{mkdocs_yml_filepath}",
"--site-dir",
f"{output_path}",
"--verbose",
]
if strict:
cmd_args.append("--strict")

try:
runner = CliRunner()
run = runner.invoke(
build_command,
[
"--clean",
"--config-file",
f"{mkdocs_yml_filepath}",
"--site-dir",
f"{output_path}",
"--verbose",
],
)
run = runner.invoke(build_command, cmd_args)
return run
except Exception as err:
logging.critical(err)
Expand Down
7 changes: 3 additions & 4 deletions tests/fixtures/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Test home page

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
Sed ut perspiciatis *unde* omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?

Feeds:
Eos **aliquid incidunt non**. Possimus ipsam id reiciendis enim. Laudantium eligendi deleniti rem delectus corrupti sit doloremque quod. Dolorem est laborum enim a ut aut.

- latest created: [feed_rss_created.xml](feed_rss_created.xml)
- latest updated: [feed_rss_updated.xml](feed_rss_updated.xml)
Laudantium minima cumque mollitia alias voluptatibus sit doloribus natus. Nam earum dolores est velit optio ipsa sit. Veritatis aut iusto distinctio veritatis aperiam in. Nemo aperiam ipsum dolorem ea officiis pariatur sapiente. Quibusdam est ut eligendi vitae ducimus fugiat. Harum ea necessitatibus inventore rem voluptatem est quaerat incidunt.
22 changes: 11 additions & 11 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def tearDownClass(cls):
"""Executed after the last test."""
# In case of some tests failure, ensure that everything is cleaned up
temp_page = Path("tests/fixtures/docs/temp_page_not_in_git_log.md")
if temp_page.exists():
temp_page.unlink()
# if temp_page.exists():
# temp_page.unlink()

git_dir = Path("_git")
if git_dir.exists():
Expand Down Expand Up @@ -379,7 +379,7 @@ def test_rss_feed_validation(self):
with tempfile.TemporaryDirectory() as tmpdirname:
cli_result = self.build_docs_setup(
testproject_path="docs",
mkdocs_yml_filepath=Path("mkdocs.yml"),
mkdocs_yml_filepath=Path("tests/fixtures/mkdocs_complete.yml"),
output_path=tmpdirname,
)

Expand Down Expand Up @@ -410,8 +410,8 @@ def test_bad_config(self):
strict=True,
)

# cli should returns an error code (2)
self.assertEqual(cli_result.exit_code, 2)
# cli should returns an error code (1)
self.assertEqual(cli_result.exit_code, 1)
self.assertIsNotNone(cli_result.exception)

def test_bad_date_format(self):
Expand All @@ -431,8 +431,9 @@ def test_bad_date_format(self):
strict=True,
)

self.assertEqual(cli_result.exit_code, 0)
self.assertIsNone(cli_result.exception)
# cli should returns an error code (1)
self.assertEqual(cli_result.exit_code, 1)
self.assertIsNotNone(cli_result.exception)

# rm page
temp_page.unlink()
Expand All @@ -451,10 +452,8 @@ def test_not_in_git_log(self):
testproject_path="docs",
mkdocs_yml_filepath=Path("tests/fixtures/mkdocs_disabled.yml"),
output_path=tmpdirname,
strict=True,
)
if cli_result.exception is not None:
e = cli_result.exception
logger.debug(format_exception(type(e), e, e.__traceback__))

self.assertEqual(cli_result.exit_code, 0)
self.assertIsNone(cli_result.exception)
Expand All @@ -471,8 +470,9 @@ def test_not_git_repo(self):
with tempfile.TemporaryDirectory() as tmpdirname:
cli_result = self.build_docs_setup(
testproject_path="docs",
mkdocs_yml_filepath=Path("tests/fixtures/mkdocs_disabled.yml"),
mkdocs_yml_filepath=Path("tests/fixtures/mkdocs_minimal.yml"),
output_path=tmpdirname,
strict=True,
)
if cli_result.exception is not None:
e = cli_result.exception
Expand Down

0 comments on commit 368d562

Please sign in to comment.