Skip to content

Commit

Permalink
Use system-agnostic command for running Python and devnull
Browse files Browse the repository at this point in the history
In this commit, we use Ptrhon standard library to provide sys.executable and os.devnull.
  • Loading branch information
mknorps committed Dec 21, 2023
1 parent 9915676 commit d689171
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/project_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Common helpers shared between test_real_project and test_sample_projects."""
import hashlib
import logging
import os
import shlex
import subprocess
import sys
Expand Down Expand Up @@ -150,7 +151,7 @@ def venv_hash(self) -> str:
The Python version currently used to run the tests is used to compute
the hash and create the venv.
"""
dummy_script = self.venv_script_lines(Path("/dev/null"))
dummy_script = self.venv_script_lines(Path(os.devnull))
py_version = f"{sys.version_info.major},{sys.version_info.minor}"
script_and_version_bytes = ("".join(dummy_script) + py_version).encode()
return hashlib.sha256(script_and_version_bytes).hexdigest()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cmdline_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_options_interactions__correct_options__does_not_abort(cli_arguments):
)
args = basepath + drawn_args

with open("/dev/null", "w") as f_out:
with open(os.devnull, "w") as f_out:
exit_code = main(cmdline_args=args, stdin=io.StringIO(to_stdin), stdout=f_out)

assert exit_code in {0, 3, 4}
4 changes: 3 additions & 1 deletion tests/test_real_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"""
import json
import logging
import os
import subprocess
import sys
import tarfile
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -51,7 +53,7 @@ def verify_requirements(venv_path: Path, requirements: List[str]) -> None:
def run_fawltydeps_json(
*args: str, venv_dir: Optional[Path], cwd: Optional[Path] = None
) -> JsonData:
argv = ["fawltydeps", "--config-file=/dev/null", "--json"]
argv = [sys.executable, "-m", "fawltydeps", f"--config-file={os.devnull}", "--json"]
if venv_dir is not None:
argv += [f"--pyenv={venv_dir}"]
proc = subprocess.run(
Expand Down
8 changes: 5 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import subprocess
import sys
from dataclasses import dataclass, field, replace
from pathlib import Path
from pprint import pformat
Expand Down Expand Up @@ -106,13 +107,14 @@ def unused_factory(*deps: str) -> List[UnusedDependency]:

def run_fawltydeps_subprocess(
*args: str,
config_file: Path = Path("/dev/null"),
config_file: Path = Path(os.devnull),
to_stdin: Optional[str] = None,
cwd: Optional[Path] = None,
) -> Tuple[str, str, int]:
"""Run FawltyDeps as a subprocess. Designed for integration tests."""
proc = subprocess.run(
["fawltydeps", f"--config-file={config_file}"] + list(args),
[sys.executable, "-m", "fawltydeps", f"--config-file={config_file}"]
+ list(args),
input=to_stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand All @@ -131,7 +133,7 @@ def run_fawltydeps_subprocess(

def run_fawltydeps_function(
*args: str,
config_file: Path = Path("/dev/null"),
config_file: Path = Path(os.devnull),
to_stdin: Optional[Union[str, bytes]] = None,
basepath: Optional[Path] = None,
) -> Tuple[str, int]:
Expand Down

0 comments on commit d689171

Please sign in to comment.