Commit f37411ae authored by Peter Grayson's avatar Peter Grayson
Browse files

test: address current ruff lint findings (RUF061, RUF043, PLC0415)

Latest ruff adds three families of findings in the test suite:

- RUF061 wants `pytest.raises` used as a context manager (8 callsites)
- RUF043 wants regex `match=` patterns marked as raw strings (5
  patterns)
- PLC0415 wants imports hoisted to module scope (test_exceptions had a
  redundant `import traceback` and a couple of late `sys` / `StringIO`
  imports).

All three are legitimate cleanups.
parent 7093b482
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -72,7 +72,8 @@ def test_run_with_processed_event(env):


def test_run_with_untriggered_event(env):
    excinfo = pytest.raises(RuntimeError, env.run, until=env.event())
    with pytest.raises(RuntimeError) as excinfo:
        env.run(until=env.event())
    assert str(excinfo.value).startswith(
        'No scheduled events left but "until" event was not triggered:'
    )
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ def test_unavailable_value(env):
    trying to access it will result in a AttributeError."""
    event = env.event()

    with pytest.raises(AttributeError, match='.* is not yet available$'):
    with pytest.raises(AttributeError, match=r'.* is not yet available$'):
        _ = event.value


+2 −4
Original line number Diff line number Diff line
@@ -5,8 +5,10 @@ Tests for forwarding exceptions from child to parent processes.

import platform
import re
import sys
import textwrap
import traceback
from io import StringIO

import pytest

@@ -205,7 +207,6 @@ def test_process_exception_chaining(env):
    traceback of the exception gets modified by a process.

    See https://bitbucket.org/simpy/simpy/issue/60 for more details."""
    import traceback

    def process_a(event):
        try:
@@ -249,9 +250,6 @@ def test_sys_excepthook(env):
    except BaseException:
        # Let the default exception hook print the traceback to the redirected
        # standard error channel.
        import sys
        from io import StringIO

        stderr, sys.stderr = sys.stderr, StringIO()

        typ, e, tb = sys.exc_info()
+4 −2
Original line number Diff line number Diff line
@@ -111,7 +111,8 @@ def test_interrupt_terminated_process(env):

        # Wait long enough so that child_proc terminates.
        yield env.timeout(2)
        ei = pytest.raises(RuntimeError, child_proc.interrupt)
        with pytest.raises(RuntimeError) as ei:
            child_proc.interrupt()
        assert re.match(
            r'<Process\(child\) object at 0x.*> has terminated '
            r'and cannot be interrupted.',
@@ -154,7 +155,8 @@ def test_interrupt_self(env):
    """A process should not be able to interrupt itself."""

    def pem(env):
        pytest.raises(RuntimeError, env.active_process.interrupt)
        with pytest.raises(RuntimeError):
            env.active_process.interrupt()
        yield env.timeout(0)

    env.process(pem(env))
+2 −1
Original line number Diff line number Diff line
@@ -181,4 +181,5 @@ def test_error_and_interrupted_join(env):
        yield env.timeout(0)

    env.process(parent(env))
    pytest.raises(AttributeError, env.run)
    with pytest.raises(AttributeError):
        env.run()
Loading