Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codecheck: Address issues found by recent black 23.1.0 and pylint 2.16.0 #38

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions tests/unit/test_build/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ def test_verbosity(mock_build, pyproject, build_args):

verbose = build_args.get("verbose", False)
capture = not verbose

# emulate build error to see captured out/err
def _raise_process_error(*args, **kwargs):
stdout, stderr = (b"stdout", b"stderr") if capture else (None, None)
raise CalledProcessError(
1, ["command args"], output=stdout, stderr=stderr
)
stdout, stderr = (b"stdout", b"stderr") if capture else (None, None)

mock_build.side_effect = _raise_process_error
mock_build.side_effect = CalledProcessError(
1, ["command args"], output=stdout, stderr=stderr
)

expected_err_msg = "build_wheel failed"
if not verbose:
Expand Down Expand Up @@ -290,11 +289,9 @@ def test_raisable_thread(mock_build, pyproject, mocker):

# override mock_build's mock for os.read
mock_os_read = mocker.patch("pyproject_installer.build_cmd._build.os.read")
# emulate os.read error to raise thread
def _raise_os_read(*args, **kwargs):
raise OSError("oops")

mock_os_read.side_effect = _raise_os_read
# emulate os.read error to raise thread
mock_os_read.side_effect = OSError("oops")

with pytest.raises(RuntimeError, match="oops"):
build_wheel(pyproject_path, outdir=outdir)
Expand Down
25 changes: 5 additions & 20 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,7 @@ def test_install_default_wheel_missing_tracker(
):
"""Check error if wheeltracker is missing and wheel is default"""

def _mock_read_text(*args, **kwargs):
raise FileNotFoundError()

mock_read_tracker.side_effect = _mock_read_text
mock_read_tracker.side_effect = FileNotFoundError
install_args = ["install"]
with pytest.raises(SystemExit) as exc:
project_main.main(install_args)
Expand Down Expand Up @@ -493,10 +490,7 @@ def test_run_cli_default_wheel_missing_tracker(mock_read_tracker, capsys):
- check outputs
"""

def _mock_read_text(*args, **kwargs):
raise FileNotFoundError()

mock_read_tracker.side_effect = _mock_read_text
mock_read_tracker.side_effect = FileNotFoundError
run_args = ["run", "foo"]
with pytest.raises(SystemExit) as exc:
project_main.main(run_args)
Expand All @@ -517,10 +511,7 @@ def test_run_cli_failed_result(mock_run_command, mock_read_tracker, caplog):
"""
exc_msg = "nonexistent command"

def _mock_result(*args, **kwargs):
raise RunCommandError(exc_msg)

mock_run_command.side_effect = _mock_result
mock_run_command.side_effect = RunCommandError(exc_msg)
run_args = ["run", "nonexistent command"]
caplog.set_level(logging.INFO)
with pytest.raises(SystemExit) as exc:
Expand All @@ -540,10 +531,7 @@ def test_run_cli_venv_error(mock_run_command, mock_read_tracker, caplog):
"""
exc_msg = "venv error"

def _mock_result(*args, **kwargs):
raise RunCommandEnvError(exc_msg)

mock_run_command.side_effect = _mock_result
mock_run_command.side_effect = RunCommandEnvError(exc_msg)
run_args = ["run", "nonexistent command"]
caplog.set_level(logging.INFO)
with pytest.raises(SystemExit) as exc:
Expand All @@ -564,10 +552,7 @@ def test_run_cli_internal_error(mock_run_command, mock_read_tracker, caplog):
"""
exc_msg = "something went wrong"

def _mock_result(*args, **kwargs):
raise Exception(exc_msg)

mock_run_command.side_effect = _mock_result
mock_run_command.side_effect = Exception(exc_msg)
run_args = ["run", "nonexistent command"]
caplog.set_level(logging.INFO)
with pytest.raises(SystemExit) as exc:
Expand Down