Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Jul 24, 2020
1 parent 26c7112 commit 6776555
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 25 deletions.
17 changes: 13 additions & 4 deletions repo_helper/cli.py
Expand Up @@ -32,10 +32,10 @@

# 3rd party
import click
import pre_commit.main
import pre_commit.main # type: ignore
from domdf_python_tools.paths import PathPlus
from dulwich import porcelain, repo
from dulwich.errors import CommitError
from dulwich import porcelain, repo # type: ignore
from dulwich.errors import CommitError # type: ignore

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'], max_content_width=120)
click_command = partial(click.command, context_settings=CONTEXT_SETTINGS)
Expand Down Expand Up @@ -110,7 +110,16 @@ def cli(ctx, path, initialise, force, commit, message):
# print(f"{commit=}")
# print(f"{message=}")

gh = RepoHelper(path)
try:
gh = RepoHelper(path)
except FileNotFoundError as e:
with Fore.RED:
error_block = textwrap.indent(str(e), " ")
print(f"""\
Unable to run 'repo_helper'.
The error was:
{error_block}""")
return 1

status, lines = check_git_status(gh.target_repo)

Expand Down
11 changes: 8 additions & 3 deletions repo_helper/docs.py
Expand Up @@ -26,14 +26,15 @@
#

# stdlib
import logging
import os.path
import pathlib
import shutil
from typing import List
from typing import Dict, Sequence, Union

import cssutils
from cssutils import css
import cssutils # type: ignore
from cssutils import css # type: ignore
# 3rd party
import jinja2
from domdf_python_tools.paths import clean_writer, PathPlus
Expand All @@ -51,7 +52,6 @@
shields_regex,
short_desc_regex
)
from repo_helper.utils import ensure_requirements

# this package
from .templates import init_repo_template_dir, template_dir
Expand All @@ -67,6 +67,11 @@
"make_docutils_conf",
]

# Disable logging from cssutils
logging.getLogger("CSSUTILS").addHandler(logging.NullHandler())
logging.getLogger("CSSUTILS").propagate = False
logging.getLogger("CSSUTILS").addFilter(lambda record: False)


def ensure_doc_requirements(repo_path: pathlib.Path, templates: jinja2.Environment) -> List[str]:
"""
Expand Down
6 changes: 3 additions & 3 deletions repo_helper/wizard.py
Expand Up @@ -49,9 +49,9 @@ def wizard(ctx):
# from domdf_python_tools.utils import stderr_writer
# 3rd party
from domdf_python_tools.terminal_colours import Fore
from dulwich.errors import NotGitRepository
from dulwich.repo import Repo
from email_validator import EmailNotValidError, validate_email
from dulwich.errors import NotGitRepository # type: ignore
from dulwich.repo import Repo # type: ignore
from email_validator import EmailNotValidError, validate_email # type: ignore

path: PathPlus = ctx.obj["PATH"]
config_file = path / 'repo_helper.yml'
Expand Down
3 changes: 3 additions & 0 deletions repo_helper/yaml_parser.py
Expand Up @@ -59,6 +59,9 @@ def parse_yaml(repo_path: pathlib.Path):
if (repo_path / "git_helper.yml").is_file():
(repo_path / "git_helper.yml").rename(repo_path / "repo_helper.yml")

if not (repo_path / "repo_helper.yml").is_file():
raise FileNotFoundError(f"'repo_helper.yml' not found in {repo_path}")

with importlib_resources.path(repo_helper, "repo_helper_schema.json") as schema:
validate(str(schema), [repo_path / "repo_helper.yml"])

Expand Down
14 changes: 7 additions & 7 deletions requirements.txt
@@ -1,19 +1,19 @@
bump2version
click
colorama >=0.4.3
colorama>=0.4.3
configupdater
cssutils
domdf-python-tools >=0.4.1
domdf-python-tools>=0.4.1
dulwich==0.19.16
importlib_resources
jinja2 >=2.11.2
packaging >=20.4
jinja2>=2.11.2
packaging>=20.4
pre-commit
pyyaml >=5.3.1
pyyaml>=5.3.1
requests
requirements-parser >=0.2.0
requirements-parser>=0.2.0
tox
trove_classifiers >=2020.5.21
trove_classifiers>=2020.5.21
typing_extensions
typing_inspect
ytools3
8 changes: 6 additions & 2 deletions tests/test_docs.py
Expand Up @@ -124,11 +124,15 @@ def test_make_docs_source_rst(demo_environment):

managed_files = make_docs_source_rst(tmpdir_p, demo_environment)
assert managed_files == [
os.path.join("doc-source", "Source.rst"), os.path.join("doc-source", "git_download.png")
os.path.join("doc-source", "Source.rst"),
os.path.join("doc-source", "Building.rst"),
os.path.join("doc-source", "git_download.png")
]
for filename in managed_files:
for filename in [os.path.join("doc-source", "Source.rst"), os.path.join("doc-source", "git_download.png")]:
assert (tmpdir_p / filename).is_file()

assert not (tmpdir_p / "doc-source" / "Building.rst").is_file()


def test_ensure_doc_requirements(demo_environment):
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_testing.py
Expand Up @@ -45,7 +45,7 @@ def test_ensure_tests_requirements(demo_environment):
encoding="UTF-8"
) == """\
coverage >=5.1
coverage_pyver_pragma >=0.0.1
coverage_pyver_pragma >=0.0.2
pytest >=6.0.0rc1
pytest-cov >=2.8.1
pytest-randomly >=3.3.1
Expand All @@ -62,7 +62,7 @@ def test_ensure_tests_requirements(demo_environment):
encoding="UTF-8"
) == """\
coverage >=5.1
coverage_pyver_pragma >=0.0.1
coverage_pyver_pragma >=0.0.2
lorem >=0.1.1
pytest >=6.0.0rc1
pytest-cov >=2.8.1
Expand Down Expand Up @@ -96,8 +96,8 @@ def test_make_isort(demo_environment):
[settings]
line_length = 115
force_to_top = True
indent = Tab
multi_line_output = 3
indent = " "
multi_line_output = 8
import_heading_stdlib = stdlib
import_heading_thirdparty = 3rd party
import_heading_firstparty = this package
Expand Down Expand Up @@ -152,8 +152,8 @@ def test_make_isort(demo_environment):
wheel
line_length = 115
force_to_top = True
indent = Tab
multi_line_output = 3
indent = " "
multi_line_output = 8
import_heading_stdlib = stdlib
import_heading_thirdparty = 3rd party
import_heading_firstparty = this package
Expand Down

0 comments on commit 6776555

Please sign in to comment.