Skip to content

Commit

Permalink
ci adjustments need
Browse files Browse the repository at this point in the history
- ci: azure-pipelines coverage report omit setup.py
- ci: azure-pipelines need --testall to get 100% coverage
- ci: README.md affected by version. Update version
- test: WorkDir
- test: conftest fixture ensure_doc_scratch
  • Loading branch information
msftcangoblowm committed Aug 30, 2024
1 parent cc015fa commit 489a99a
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 31 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source =
omit =
# Don't worry about covering vendored libraries
src/sphobjinv/_vendored/*
setup.py

[report]
exclude_lines =
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ changes.

### [2.4.1.11] - 2024-08-28

#### Administrative

* azure-pipelines coverage report omit setup.py
* README.md affected by version. Update version
* azure-pipelines need --testall to get 100% coverage

#### Tests

* test conftest fixture ensure_doc_scratch
* test WorkDir
* fix inventory path must surround by single quotes
* fix use git config to set textconv executable
* add to WorkDir git config list/get/set support
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ inventory creation/modification:
>>> import sphobjinv as soi
>>> inv = soi.Inventory('doc/build/html/objects.inv')
>>> print(inv)
<Inventory (fname_zlib): sphobjinv v2.3, 220 objects>
<Inventory (fname_zlib): sphobjinv v2.4, 234 objects>
>>> inv.project
'sphobjinv'
>>> inv.version
'2.3'
'2.4'
>>> inv.objects[0]
DataObjStr(name='sphobjinv.cli.convert', domain='py', role='module', priority='0', uri='cli/implementation/convert.html#module-$', dispname='-')

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ stages:
- script: cd doc; make html; mkdir scratch
displayName: Build docset

- script: pytest --cov=. --nonloc --flake8_ext
- script: pytest --cov=. --nonloc --flake8_ext --testall
displayName: Run pytest with coverage on the entire project tree

- script: coverage report --include="tests/*" --fail-under=100
Expand Down
14 changes: 7 additions & 7 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def scratch_path(tmp_path, res_path, misc_info, is_win, unix2dos):
# With the conversion of resources/objects_attrs.txt to Unix EOLs in order to
# provide for a Unix-testable sdist, on Windows systems this resource needs
# to be converted to DOS EOLs for consistency.
if is_win:
if is_win: # pragma: no cover
win_path = tmp_path / f"{scr_base}{misc_info.Extensions.DEC.value}"
win_path.write_bytes(unix2dos(win_path.read_bytes()))

Expand Down Expand Up @@ -258,7 +258,7 @@ def func(path):
"""Perform the 'live' inventory load test."""
try:
sphinx_ifile_load(path)
except Exception as e: # noqa: PIE786
except Exception as e: # noqa: PIE786 # pragma: no cover
# An exception here is a failing test, not a test error.
pytest.fail(e)

Expand Down Expand Up @@ -298,7 +298,7 @@ def func(arglist, *, expect=0): # , suffix=None):
except SystemExit as e:
retcode = e.args[0]
ok = True
else:
else: # pragma: no cover
ok = False

# Do all pytesty stuff outside monkeypatch context
Expand Down Expand Up @@ -331,7 +331,7 @@ def func(arglist, *, expect=0): # , suffix=None):
except SystemExit as e:
retcode = e.args[0]
ok = True
else:
else: # pragma: no cover
ok = False

# Do all pytesty stuff outside monkeypatch context
Expand Down Expand Up @@ -364,7 +364,7 @@ def func(arglist, *, prog="sphobjinv-textconv"):
except SystemExit as e:
retcode = e.args[0]
is_system_exit = True
else:
else: # pragma: no cover
is_system_exit = False

return retcode, is_system_exit
Expand All @@ -382,7 +382,7 @@ def func(path):
res_bytes = Path(misc_info.res_decomp_path).read_bytes()
tgt_bytes = Path(path).read_bytes() # .replace(b"\r\n", b"\n")

if is_win:
if is_win: # pragma: no cover
# Have to explicitly convert these newlines, now that the
# tests/resource/objects_attrs.txt file is marked 'binary' in
# .gitattributes
Expand Down Expand Up @@ -469,7 +469,7 @@ def func(path_cwd):
path_f_dst = path_cwd / path_f_src.name
path_f_dst.touch()
assert path_f_dst.is_file()
if not path_f_src.exists():
if not path_f_src.exists(): # pragma: no cover
# workflow "Run test suite in sandbox" fails to find .gitattributes
sep = os.linesep
contents = (
Expand Down
14 changes: 12 additions & 2 deletions tests/test_api_good.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,12 @@ def test_api_inventory_datafile_gen_and_reimport(
scr_fpath = scratch_path / fname

# Drop most unless testall
if not pytestconfig.getoption("--testall") and fname != "objects_attrs.inv":
skips = (
"objects_attrs.inv",
"objects_attrs_plus_one_entry.inv",
)
is_not_test_all = not pytestconfig.getoption("--testall")
if is_not_test_all and fname not in skips: # pragma: no cover
pytest.skip("'--testall' not specified")

# Make Inventory
Expand Down Expand Up @@ -529,7 +534,12 @@ def test_api_inventory_matches_sphinx_ifile(
scr_fpath = scratch_path / fname

# Drop most unless testall
if not pytestconfig.getoption("--testall") and fname != "objects_attrs.inv":
skips = (
"objects_attrs.inv",
"objects_attrs_plus_one_entry.inv",
)
is_not_test_all = not pytestconfig.getoption("--testall")
if is_not_test_all and fname not in skips: # pragma: no cover
pytest.skip("'--testall' not specified")

original_ifile_data = sphinx_ifile_load(testall_inv_path)
Expand Down
7 changes: 2 additions & 5 deletions tests/test_api_good_nonlocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,9 @@ def test_api_inventory_many_url_imports(
"objects_attrs_plus_one_entry.inv",
)
is_not_testall = not pytestconfig.getoption("--testall")
if is_not_testall:
reason = "'--testall' not specified"
pytest.skip(reason)
is_skip = fname in skips
if is_skip:
reason = f"skip online checks for theis inventory {fname}"
if is_not_testall or is_skip: # pragma: no cover
reason = "'--testall' not specified"
pytest.skip(reason)

# Construct inventories for comparison
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_cli_convert_cycle_formats(
if (
not pytestconfig.getoption("--testall")
and testall_inv_path.name != "objects_attrs.inv"
):
): # pragma: no cover
pytest.skip("'--testall' not specified")

run_cmdline_test(["convert", "plain", str(res_src_path), str(plain_path)])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli_textconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_cli_textconv_via_subprocess(
text=True,
capture_output=True,
)
except (sp.CalledProcessError, sp.TimeoutExpired):
except (sp.CalledProcessError, sp.TimeoutExpired): # pragma: no cover
pytest.xfail()
else:
out = p_result.stdout
Expand Down Expand Up @@ -280,7 +280,7 @@ def test_cli_textconv_zlib_inv_stdin(
str_err = b_err.decode("utf-8")
assert retcode == expected_retcode
assert "Invalid plaintext or JSON inventory format." in str_err
else:
else: # pragma: no cover
reason = (
"Piping in zlib inventory via stdin is not supported. "
"Was expecting exit code 1"
Expand Down
44 changes: 38 additions & 6 deletions tests/test_cli_textconv_with_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def func(path_cwd):

# On Windows, resolved executables paths
resolved_soi_textconv_path = shutil.which(soi_textconv_path)
if resolved_soi_textconv_path is None:
if resolved_soi_textconv_path is None: # pragma: no cover
resolved_soi_textconv_path = soi_textconv_path
val = resolved_soi_textconv_path

if is_win:
if is_win: # pragma: no cover
# On Windows, extensions Windows searches to find executables
msg_info = f"""PATHEXT: {os.environ.get("PATHEXT", None)}"""
logger_.info(msg_info)
Expand All @@ -111,7 +111,7 @@ def func(path_cwd):
reason = f"Unable to set git config setting {key} to {val}"
assert is_success is True, reason

if is_win:
if is_win: # pragma: no cover
# .git/config after update
gc_contents = path_git_config_dst.read_text()
msg_info = f""".git/config (after update):{os.linesep}{gc_contents}"""
Expand All @@ -123,6 +123,38 @@ def func(path_cwd):
class TestTextconvIntegration:
"""Prove git diff an compare |objects.inv| files."""

def test_workdir(
self,
scratch_path,
):
"""Test interface of WorkDir."""
path_cwd = scratch_path
wd = WorkDir(path_cwd)

# __repr__
assert len(repr(wd)) != 0

# run fail
cmd = "dsfsadfdsfsadfdsaf"
assert run(cmd) is None

wd("git init")
wd("git config user.email [email protected]")
wd('git config user.name "a test"')

# From .git/config get nonexistent key
invalid_key = "diff.sigfault.textconv"
assert wd.git_config_get(invalid_key) is None

# Write bytes and str data to file
fname = "a.txt"
write_these = (
b"aaaaa",
"aaaaa",
)
for contents in write_these:
wd.write(fname, contents)

def test_textconv_git_diff(
self,
caplog,
Expand Down Expand Up @@ -166,7 +198,7 @@ def test_textconv_git_diff(
if is_win or is_linux:
msg_info = f"cwd {wd.cwd!s}"
logger.info(msg_info)
if is_win:
if is_win: # pragma: no cover
from pathlib import WindowsPath

soi_textconv_path = "sphobjinv-textconv"
Expand Down Expand Up @@ -229,12 +261,12 @@ def test_textconv_git_diff(

# Diagnostics before assertions
# On error, not showing locals, so print source file and diff
if is_win or is_linux:
if is_win or is_linux: # pragma: no cover
msg_info = f"cmd: {cmd}"
logger.info(msg_info)
msg_info = f"diff: {out}"
logger.info(msg_info)
if retcode != 0:
if retcode != 0: # pragma: no cover
msg_info = f"err: {err}"
logger.info(msg_info)
msg_info = f"regex: {expected_diff}"
Expand Down
6 changes: 6 additions & 0 deletions tests/test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ def test_decomp_comp_fixture(misc_info, decomp_cmp_test, scratch_path):
decomp_cmp_test(
scratch_path / f"{misc_info.FNames.INIT.value}{misc_info.Extensions.DEC.value}"
)


def test_ensure_doc_scratch(scratch_path, ensure_doc_scratch):
"""Test unused ensure_doc_scratch."""
path_cwd = scratch_path
assert path_cwd.exists() and path_cwd.is_dir()
14 changes: 9 additions & 5 deletions tests/wd_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run(

try:
p_out = sp.run(cmd, cwd=cwd, text=True, capture_output=True) # noqa: S603
except sp.CalledProcessError:
except (sp.CalledProcessError, FileNotFoundError):
ret = None
else:
ret = p_out
Expand Down Expand Up @@ -165,7 +165,7 @@ def _reason(self, given_reason: str | None) -> str:
|str| -- formatted reason
"""
if given_reason is None:
if given_reason is None: # pragma: no cover
return f"number-{next(self.__counter)}"
else:
return given_reason
Expand Down Expand Up @@ -218,7 +218,11 @@ def commit(self, reason: str | None = None, signed: bool = False) -> None:
reason=reason,
)

def commit_testfile(self, reason: str | None = None, signed: bool = False) -> None:
def commit_testfile(
self,
reason: str | None = None,
signed: bool = False,
) -> None: # pragma: no cover
"""Commit a test.txt file.
Parameters
Expand Down Expand Up @@ -340,7 +344,7 @@ def git_config_set(
"config",
dotted_key,
]
if is_path and is_win:
if is_path and is_win: # pragma: no cover
# In Bash, single quotes protect (Windows path) backslashes
# Does not deal with escaping spaces
# `Path is Windows safe <https://stackoverflow.com/a/68555279>`_
Expand All @@ -353,7 +357,7 @@ def git_config_set(
# git config diff.inv.textconv "sh -c 'sphobjinv co plain \"\$0\" -'"
# git config diff.inv.textconv "sh -c 'sphobjinv-textconv \"\$0\"'"
cp_out = run(cmd, cwd=self.cwd)
if cp_out is None or cp_out.returncode != 0:
if cp_out is None or cp_out.returncode != 0: # pragma: no cover
ret = False
else:
ret = True
Expand Down

0 comments on commit 489a99a

Please sign in to comment.