Skip to content
Closed
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
57 changes: 57 additions & 0 deletions tests/test_loopguard_trial_nose_django.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""trial, nosetests, python -m nose and python -m django test are test runs.

The micro-skills observer already reads Twisted's `trial`, nose's `nosetests` and `python -m nose`,
and `python -m django test` as test runs, and `SpiralState` already counts `trial`. `VERIFY_RE` now
reads them too, so turns verified with them do not count as ended green after a failure."""
import pytest

from tokeneconomizer import loopguard as guard
from tokeneconomizer.loopguard import turn


@pytest.mark.parametrize("cmd", [
"trial mypkg",
"trial mypkg.test_foo",
".venv/bin/trial mypkg",
"nosetests -v",
"nosetests tests/",
".venv/bin/nosetests",
"python -m nose",
"python3 -m nose -v",
"python -m django test",
"python3.12 -m django test myapp",
"uv run trial mypkg",
"uv run nosetests",
"uv run python -m django test",
"poetry run python -m nose",
])
def test_trial_nose_and_django_test_count_as_verifications(cmd):
assert turn.status_of_tests(cmd) == "own"
g = guard.TurnGuard(turn_key="t")
g.fold("Edit", {"file_path": "/r/a.py", "old_string": "x", "new_string": "y"}, "ok")
g.fold("Bash", {"command": cmd}, "FAILED (failures=1)", 1)
assert g.verifications == 1 and not g.resolved_proxy()


@pytest.mark.parametrize("cmd", [
"trial --help",
"trial --version",
"nosetests --help",
"nosetests -h",
"nosetests --version",
"python -m django runserver",
"python -m django migrate",
"python -m django",
"python -m nose --help",
"trials",
"nosetestspro",
])
def test_commands_that_run_no_tests_are_not_verifications(cmd):
assert turn.status_of_tests(cmd) is None


def test_the_observer_and_the_loop_guard_agree():
from tokeneconomizer.microskills import observe
for cmd in ["trial mypkg", "nosetests -v", "python -m nose", "python -m django test"]:
assert [o.intent for o in observe.classify_command(cmd)] == ["run_tests"]
assert turn.status_of_tests(cmd) == "own"
4 changes: 2 additions & 2 deletions tokeneconomizer/loopguard/turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
_MAKE_VALUE = r"(?:\$\s*\w+|[^\s\-]\S*)"
VERIFY_RE = re.compile(
r"(?i)(?:^|[\s;&|(])(?:(?:~?/)?(?:[\w.\-]+/)*" + _PYTHON + r"\s+)?"
r"(?:~?/)?(?:[\w.\-]+/)*(?:pytest|py\.test|tox|nox|"
+ _PYTHON + r"\s+-m\s+(?:pytest|unittest|tox|nox)|"
r"(?:~?/)?(?:[\w.\-]+/)*(?:pytest|py\.test|tox|nox|nosetests|trial|"
+ _PYTHON + r"\s+-m\s+(?:pytest|unittest|tox|nox|nose|django\s+test)|"
# coverage.py measuring a test run (`coverage run -m pytest`, `python -m coverage run
# manage.py test`), past its own options, of which these take a value
r"(?:-m\s+)?coverage\s+run(?:\s+(?:--(?:rcfile|source|omit|include|data-file|context|"
Expand Down