Skip to content

Commit

Permalink
fixes, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Nov 11, 2023
1 parent 9d10532 commit 1b617c5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 60 deletions.
2 changes: 1 addition & 1 deletion autotest/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ python_files =
test_*.py
*_test*.py
markers =
slow: tests that don't complete in a few seconds
slow: tests not completing in a few seconds
meta: run by other tests (e.g. testing fixtures)
14 changes: 1 addition & 13 deletions autotest/test_executables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

from modflow_devtools.executables import Executables
from modflow_devtools.misc import get_suffixes, add_sys_path
from modflow_devtools.misc import add_sys_path, get_suffixes

ext, _ = get_suffixes(sys.platform)
exe_stem = "pytest"
Expand All @@ -24,15 +24,3 @@ def exes():
def test_access(exes):
# support both attribute and dictionary style access
assert exes.pytest == exes["pytest"] == exe_path


def test_get_version(exes):
ver_str = Executables.get_version(exes.pytest)
version = (
subprocess.check_output([f"{exes.pytest}", "-v"])
.decode("utf-8")
.split(":")[1]
.strip()
)
assert ver_str == version
assert int(ver_str[0].split(".")[0]) >= 6
13 changes: 4 additions & 9 deletions autotest/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_keep_class_scoped_tmpdir(tmp_path, arg):
TestKeepClassScopedTmpdirInner.test_keep_class_scoped_tmpdir_inner.__name__,
"-M",
"test_keep",
"-K",
arg,
tmp_path,
]
assert pytest.main(args) == ExitCode.OK
Expand All @@ -160,19 +160,14 @@ def test_keep_module_scoped_tmpdir(tmp_path, arg):
test_keep_module_scoped_tmpdir_inner.__name__,
"-M",
"test_keep",
"-K",
arg,
tmp_path,
]
assert pytest.main(args) == ExitCode.OK
this_path = Path(__file__)
keep_path = (
tmp_path
/ f"{str(this_path.parent.parent.name)}.{str(this_path.parent.name)}.{str(this_path.stem)}0"
tmp_path / f"{str(this_path.parent.name)}.{str(this_path.stem)}0"
)
from pprint import pprint

print(keep_path)
pprint(list(keep_path.glob("*")))
assert test_keep_fname in [f.name for f in keep_path.glob("*")]


Expand All @@ -186,7 +181,7 @@ def test_keep_session_scoped_tmpdir(tmp_path, arg, request):
test_keep_session_scoped_tmpdir_inner.__name__,
"-M",
"test_keep",
"-K",
arg,
tmp_path,
]
assert pytest.main(args) == ExitCode.OK
Expand Down
4 changes: 2 additions & 2 deletions autotest/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def empty_archive(module_tmpdir) -> Path:
path = module_tmpdir / "empty.zip"
with open(path, "wb") as zip:
zip.write(data)
return path
yield path


def test_extractall_empty(empty_archive, function_tmpdir):
Expand All @@ -61,7 +61,7 @@ def archive(module_tmpdir) -> Path:
zip = MFZipFile(zip_path.name, "w")
zip.write(exe_path.name, compress_type=zipfile.ZIP_DEFLATED)
zip.close()
return zip_path
yield zip_path


@pytest.mark.parametrize("mf", [True, False])
Expand Down
11 changes: 0 additions & 11 deletions docs/md/executables.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,3 @@ def test_targets(targets):
# attribute- and dictionary-style access is supported
assert targets["mf6"] == targets.mf6
```

There is also a convenience function for getting a program's version string. The function will automatically strip the program name from the output (assumed delimited with `:`).

```python
import subprocess

def test_executables_version(targets):
# returns e.g. '6.4.1 Release 12/09/2022'
assert targets.get_version(targets.mf6) == \
subprocess.check_output([f"{targets.mf6}", "-v"]).decode('utf-8').strip().split(":")[1].strip()
```
17 changes: 1 addition & 16 deletions modflow_devtools/executables.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import sys
from os import PathLike
from pathlib import Path
from types import SimpleNamespace
from typing import Dict, Optional

from modflow_devtools.misc import get_suffixes, run_cmd
from typing import Dict


class Executables(SimpleNamespace):
Expand All @@ -27,14 +23,3 @@ def as_dict(self) -> Dict[str, Path]:
"""

return self.__dict__.copy()

@staticmethod
def get_version(path: PathLike = None, flag: str = "-v") -> Optional[str]:
"""Get an executable's version string."""

out, err, ret = run_cmd(str(path), flag)
if ret == 0:
out = "".join(out).strip()
return out.split(":")[1].strip()
else:
return None
8 changes: 0 additions & 8 deletions pytest.ini

This file was deleted.

0 comments on commit 1b617c5

Please sign in to comment.