Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- id: python-no-log-warn
- id: text-unicode-replacement-char
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.14
rev: v0.15.0
hooks:
- id: ruff-format
- id: ruff-check
Expand Down
12 changes: 6 additions & 6 deletions src/_pytask/collect_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ def _print_collected_tasks(
for node in sorted(
deps,
key=(
lambda x: x.path.as_posix()
if isinstance(x, PPathNode)
else x.name
lambda x: (
x.path.as_posix() if isinstance(x, PPathNode) else x.name
)
),
):
text = format_node_name(node, (common_ancestor,))
Expand All @@ -211,9 +211,9 @@ def _print_collected_tasks(
products: list[Any] = list(tree_leaves(task.produces))
for node in sorted(
products,
key=lambda x: x.path.as_posix()
if isinstance(x, PPathNode)
else x.name,
key=lambda x: (
x.path.as_posix() if isinstance(x, PPathNode) else x.name
),
):
text = format_node_name(node, (common_ancestor,))
task_branch.add(Text.assemble(FILE_ICON, "<Product ", text, ">"))
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def import_optional_dependency(
return None

# Handle submodules: if we have submodule, grab parent module from sys.modules
parent = name.split(".")[0]
parent = name.split(".", maxsplit=1)[0]
if parent != name:
install_name = parent
module_to_get = sys.modules[install_name]
Expand Down
8 changes: 5 additions & 3 deletions src/_pytask/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ def _add_product(
# another task that is a dependency in the current task. Thus, draw an edge
# connecting the two nodes.
tree_map(
lambda x: dag.add_edge(x.value.signature, x.signature)
if isinstance(x, PythonNode) and isinstance(x.value, PythonNode)
else None,
lambda x: (
dag.add_edge(x.value.signature, x.signature)
if isinstance(x, PythonNode) and isinstance(x.value, PythonNode)
else None
),
task.depends_on,
)
return dag
Expand Down
42 changes: 26 additions & 16 deletions tests/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def test_init_capturing(self):
try:
capman = CaptureManager(CaptureMethod.FD)
capman.start_capturing()
pytest.raises(AssertionError, capman.start_capturing)
with pytest.raises(AssertionError):
capman.start_capturing()
capman.stop_capturing()
finally:
capouter.stop_capturing()
Expand Down Expand Up @@ -364,7 +365,8 @@ def test_text(self):
def test_unicode_and_str_mixture(self):
f = capture.CaptureIO()
f.write("\u00f6")
pytest.raises(TypeError, f.write, b"hello")
with pytest.raises(TypeError):
f.write(b"hello")

def test_write_bytes_to_buffer(self):
"""In python3, stdout / stderr are text io wrappers (exposing a buffer property
Expand Down Expand Up @@ -394,7 +396,8 @@ def test_unicode_and_str_mixture(self):
sio = io.StringIO()
f = capture.TeeCaptureIO(sio)
f.write("\u00f6")
pytest.raises(TypeError, f.write, b"hello")
with pytest.raises(TypeError):
f.write(b"hello")


def test_dontreadfrominput():
Expand All @@ -403,11 +406,15 @@ def test_dontreadfrominput():
f = DontReadFromInput()
assert f.buffer is f
assert not f.isatty()
pytest.raises(OSError, f.read)
pytest.raises(OSError, f.readlines)
with pytest.raises(OSError):
f.read()
with pytest.raises(OSError):
f.readlines()
iter_f = iter(f)
pytest.raises(OSError, next, iter_f)
pytest.raises(UnsupportedOperation, f.fileno)
with pytest.raises(OSError):
next(iter_f)
with pytest.raises(UnsupportedOperation):
f.fileno()
f.close() # just for completeness


Expand Down Expand Up @@ -474,7 +481,8 @@ def test_simple(self, tmpfile):
cap = capture.FDCapture(fd)
data = b"hello"
os.write(fd, data)
pytest.raises(AssertionError, cap.snap)
with pytest.raises(AssertionError):
cap.snap()
cap.done()
cap = capture.FDCapture(fd)
cap.start()
Expand All @@ -495,7 +503,8 @@ def test_simple_fail_second_start(self, tmpfile):
fd = tmpfile.fileno()
cap = capture.FDCapture(fd)
cap.done()
pytest.raises(AssertionError, cap.start)
with pytest.raises(AssertionError):
cap.start()

def test_stderr(self):
cap = capture.FDCapture(2)
Expand Down Expand Up @@ -546,7 +555,8 @@ def test_simple_resume_suspend(self):
assert s == "but now yes\n"
cap.suspend()
cap.done()
pytest.raises(AssertionError, cap.suspend)
with pytest.raises(AssertionError):
cap.suspend()

assert repr(cap) == (
"<FDCapture 1 oldfd={} _state='done' tmpfile={!r}>".format( # noqa: UP032
Expand Down Expand Up @@ -631,7 +641,8 @@ def test_reset_twice_error(self):
with self.getcapture() as cap:
print("hello")
out, err = cap.readouterr()
pytest.raises(ValueError, cap.stop_capturing)
with pytest.raises(ValueError):
cap.stop_capturing()
assert out == "hello\n"
assert not err

Expand Down Expand Up @@ -688,8 +699,8 @@ def test_stdin_nulled_by_default(self):
print("XX this test may well hang instead of crashing")
print("XX which indicates an error in the underlying capturing")
print("XX mechanisms")
with self.getcapture():
pytest.raises(OSError, sys.stdin.read)
with self.getcapture(), pytest.raises(OSError):
sys.stdin.read()


class TestTeeStdCapture(TestStdCapture):
Expand Down Expand Up @@ -829,6 +840,5 @@ def test_fdcapture_invalid_fd_without_fd_reuse(self, tmp_path):

def test__get_multicapture() -> None:
assert isinstance(_get_multicapture(CaptureMethod.NO), MultiCapture)
pytest.raises(ValueError, _get_multicapture, "unknown").match(
r"^unknown capturing method: 'unknown'"
)
with pytest.raises(ValueError, match=r"^unknown capturing method: 'unknown'"):
_get_multicapture("unknown")
Loading