Skip to content

Commit

Permalink
Improve test coverage (#270)
Browse files Browse the repository at this point in the history
* improve coverage

* 100% coverage on streaming.py

* use unlink() instad of own utils rm_rf

* complete test coverage

* move coverage configuration to pyproject.toml

* lint issue

* add assert

* format

* Update tests/test_utils.py

* Ignore W503

* Update tests/test_utils.py

---------

Co-authored-by: Jannis Leidel <jannis@leidel.info>
  • Loading branch information
dholth and jezdez authored Jan 9, 2025
1 parent 49e80e9 commit 685a302
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 418 deletions.
7 changes: 0 additions & 7 deletions .coveragerc

This file was deleted.

11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ addopts = [
"--ignore setup.py",
"--ignore run_test.py",
"--cov-report term-missing",
"--cov-branch",
"--tb native",
"--strict-markers",
"--durations=20",
]
markers = ["serial: execute test serially (to avoid race conditions)"]

[tool.coverage.run]
source = [ "src/", ]
omit = [
"setup.py",
"src/conda_package_handling/__main__.py",
"src/conda_package_handling/_version.py",
"versioneer.py",
"tests/*",
]
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
max-line-length = 100
ignore = E122,E123,E126,E127,E128,E731,E722
ignore = E122,E123,E126,E127,E128,E731,E722,W503
exclude = build,src/conda_package_handling/_version.py,tests,conda.recipe,.git,versioneer.py,benchmarks,.asv,rever
10 changes: 6 additions & 4 deletions src/conda_package_handling/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .tarball import CondaTarBZ2 as _CondaTarBZ2
from .utils import ensure_list, filter_info_files
from .utils import get_executor as _get_executor
from .utils import rm_rf as _rm_rf

SUPPORTED_EXTENSIONS: dict[str, type[AbstractBaseFormat]] = {".tar.bz2": _CondaTarBZ2}

Expand Down Expand Up @@ -113,7 +112,7 @@ def create(prefix, file_list, out_fn, out_folder=None, **kw):
# don't leave broken files around
abs_out_fn = _os.path.join(out_folder, out_fn)
if _os.path.isfile(abs_out_fn):
_rm_rf(abs_out_fn)
_os.unlink(abs_out_fn)
raise err
else:
raise ValueError(
Expand Down Expand Up @@ -191,7 +190,7 @@ def is_info(filename):
except BaseException as e:
# don't leave partial package around
if _os.path.isfile(out_fn):
_rm_rf(out_fn)
_os.unlink(out_fn)
if not isinstance(e, Exception):
raise
errors = str(e)
Expand All @@ -216,7 +215,10 @@ def transmute(in_file, out_ext, out_folder=None, processes=1, **kw):
for fn, out_fn, errors in executor.map(convert_f, flist):
if errors:
failed_files[fn] = errors
_rm_rf(out_fn)
try:
_os.unlink(out_fn)
except FileNotFoundError:
pass
return failed_files


Expand Down
7 changes: 4 additions & 3 deletions src/conda_package_handling/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io
import tarfile
from contextlib import redirect_stdout
from pathlib import Path
from tarfile import TarError
from typing import Generator
from zipfile import BadZipFile
Expand All @@ -18,9 +19,9 @@


def _stream_components(
filename: str,
filename: str | Path,
components: list[str],
dest_dir: str = "",
dest_dir: str | Path = "",
) -> Generator[Generator[tuple[tarfile.TarFile, tarfile.TarInfo]]]:
if str(filename).endswith(".tar.bz2"):
assert components == ["pkg"]
Expand All @@ -38,7 +39,7 @@ def _stream_components(
raise exceptions.InvalidArchiveError(filename, f"failed with error: {str(e)}") from e


def _extract(filename: str, dest_dir: str, components: list[str]):
def _extract(filename: str | Path, dest_dir: str | Path, components: list[str]):
"""
Extract .conda or .tar.bz2 package to dest_dir.
Expand Down
Loading

0 comments on commit 685a302

Please sign in to comment.