f2/lang: rename the test functions to be selectable using their expected names
one would expect the lang tests to be selectable (using `-k`) using `eval_okay` `eval_fail` etc though this was not the case so far. This commit renames the functions to reflect the expected names Change-Id: I4cd340c093d774feeb4d96820d28e49c665b159f
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from functional2.lang.test_lang import test_eval as nix_eval
|
||||
from functional2.lang.test_lang import test_eval_okay as nix_eval
|
||||
from functional2.testlib.fixtures.file_helper import with_files, File, AssetSymlink
|
||||
from functional2.testlib.fixtures.nix import Nix
|
||||
from functional2.testlib.fixtures.snapshot import Snapshot
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from pathlib import Path
|
||||
from collections.abc import Callable
|
||||
|
||||
from functional2.lang.test_lang import test_eval as nix_eval
|
||||
from functional2.lang.test_lang import test_eval_okay as nix_eval
|
||||
from functional2.testlib.fixtures.file_helper import (
|
||||
with_files,
|
||||
CopyFile,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from functional2.lang.test_lang import test_eval as nix_eval
|
||||
from functional2.lang.test_lang import test_eval_okay as nix_eval
|
||||
from functional2.testlib.fixtures.file_helper import (
|
||||
with_files,
|
||||
CopyFile,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from functional2.lang.test_lang import test_eval as nix_eval
|
||||
from functional2.lang.test_lang import test_eval_okay as nix_eval
|
||||
from functional2.testlib.fixtures.file_helper import (
|
||||
with_files,
|
||||
CopyFile,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from functional2.lang.test_lang import test_eval as nix_eval
|
||||
from functional2.lang.test_lang import test_eval_okay as nix_eval
|
||||
from functional2.testlib.fixtures.file_helper import AssetSymlink, CopyFile, CopyTree, with_files
|
||||
from functional2.testlib.fixtures.nix import Nix
|
||||
from functional2.testlib.fixtures.snapshot import Snapshot
|
||||
|
||||
@@ -5,7 +5,6 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from _pytest.fixtures import FixtureRequest
|
||||
from _pytest.python import Metafunc
|
||||
|
||||
from functional2.lang.lang_util import LangTest, fetch_all_lang_tests, LangTestRunner
|
||||
@@ -25,13 +24,13 @@ def pytest_generate_tests(metafunc: Metafunc):
|
||||
return
|
||||
selected_runner: LangTestRunner
|
||||
match func_name:
|
||||
case "test_eval":
|
||||
case "test_eval_okay":
|
||||
selected_runner = LangTestRunner.EVAL_OKAY
|
||||
case "test_xfail_eval":
|
||||
case "test_eval_fail":
|
||||
selected_runner = LangTestRunner.EVAL_FAIL
|
||||
case "test_parser":
|
||||
case "test_parse_okay":
|
||||
selected_runner = LangTestRunner.PARSE_OKAY
|
||||
case "test_xfail_parser":
|
||||
case "test_parse_fail":
|
||||
selected_runner = LangTestRunner.PARSE_FAIL
|
||||
case _:
|
||||
return
|
||||
@@ -42,12 +41,7 @@ def pytest_generate_tests(metafunc: Metafunc):
|
||||
files, flags, ids = zip(*map(LangTest.to_params, selected_tests)) # type: ignore
|
||||
else:
|
||||
files, flags, ids = [], [], []
|
||||
metafunc.parametrize(("files", "flags"), zip(files, flags), ids=ids, indirect=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def flags(request: FixtureRequest) -> list[str]:
|
||||
return request.param
|
||||
metafunc.parametrize(("files", "flags"), zip(files, flags), ids=ids, indirect=["files"])
|
||||
|
||||
|
||||
def _cleanup_output(stdout: str, stderr: str, origin: Path) -> tuple[str, str]:
|
||||
@@ -60,7 +54,7 @@ def _cleanup_output(stdout: str, stderr: str, origin: Path) -> tuple[str, str]:
|
||||
return clean_out, clean_err
|
||||
|
||||
|
||||
def test_parser(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str], Snapshot]):
|
||||
def test_parse_okay(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str], Snapshot]):
|
||||
nix_command = nix.nix_instantiate(
|
||||
["--parse", *flags, files / "in.nix"],
|
||||
# TODO(Commentator2.0): Mirrors behavior of init.sh from functional
|
||||
@@ -89,7 +83,7 @@ def test_parser(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str
|
||||
assert snapshot("err.exp") == stderr
|
||||
|
||||
|
||||
def test_xfail_parser(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str], Snapshot]):
|
||||
def test_parse_fail(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str], Snapshot]):
|
||||
nix_command = nix.nix_instantiate(["--parse", *flags, files / "in.nix"], flake=True)
|
||||
result = nix_command.run().expect(1)
|
||||
stdout, stderr = _cleanup_output(result.stdout_s, result.stderr_s, files)
|
||||
@@ -98,7 +92,7 @@ def test_xfail_parser(files: Path, nix: Nix, flags: list[str], snapshot: Callabl
|
||||
assert snapshot("err.exp") == stderr
|
||||
|
||||
|
||||
def test_eval(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str], Snapshot]):
|
||||
def test_eval_okay(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str], Snapshot]):
|
||||
nix_command = nix.nix_instantiate(["--eval", "--strict", *flags, files / "in.nix"], flake=True)
|
||||
result = nix_command.run().ok()
|
||||
stdout, stderr = _cleanup_output(result.stdout_s, result.stderr_s, files)
|
||||
@@ -107,7 +101,7 @@ def test_eval(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str],
|
||||
assert snapshot("err.exp") == stderr
|
||||
|
||||
|
||||
def test_xfail_eval(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str], Snapshot]):
|
||||
def test_eval_fail(files: Path, nix: Nix, flags: list[str], snapshot: Callable[[str], Snapshot]):
|
||||
nix_command = nix.nix_instantiate(
|
||||
["--eval", "--strict", "--show-trace", *flags, files / "in.nix"], flake=True
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ from functional2.testlib.utils import get_functional2_lang_files
|
||||
)
|
||||
def test_detects_generic_lang_test(pytest_command: Command):
|
||||
result = pytest_command.run().ok()
|
||||
assert "lang/test_lang.py::test_eval[generic_test:eval-okay]" in result.stdout_plain
|
||||
assert "lang/test_lang.py::test_eval_okay[generic_test:eval-okay]" in result.stdout_plain
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pytest_command", [["-k", "toml_test", "--setup-plan"]], indirect=True)
|
||||
@@ -50,7 +50,7 @@ def test_detects_generic_lang_test(pytest_command: Command):
|
||||
)
|
||||
def test_detects_toml_lang_test(pytest_command: Command):
|
||||
result = pytest_command.run().ok()
|
||||
assert "lang/test_lang.py::test_eval[toml_test:my_name]" in result.stdout_plain
|
||||
assert "lang/test_lang.py::test_eval_okay[toml_test:my_name]" in result.stdout_plain
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pytest_command", [["--setup-plan"]], indirect=True)
|
||||
@@ -71,7 +71,7 @@ def test_detects_toml_lang_test(pytest_command: Command):
|
||||
)
|
||||
def test_skips_py_files(files: Path, pytest_command: Command):
|
||||
result = pytest_command.run().ok()
|
||||
assert "lang/test_lang.py::test_eval[some_py_module:eval-okay]" not in result.stdout_plain
|
||||
assert "lang/test_lang.py::test_eval_okay[some_py_module:eval-okay]" not in result.stdout_plain
|
||||
assert (
|
||||
f"[ INFO] [lang-test-collector] skipping {files.absolute()}/functional2/lang/some_py_module as it contains a py file, assuming custom tests"
|
||||
in result.stdout_plain
|
||||
@@ -223,11 +223,13 @@ def test_collection_fails_with_bad_naming(pytest_command: Command):
|
||||
)
|
||||
def test_all_runners_work(pytest_command: Command):
|
||||
result = pytest_command.run().ok()
|
||||
assert "lang/test_lang.py::test_eval[infra_okay_runners:eval-okay]" in result.stdout_plain
|
||||
assert "lang/test_lang.py::test_parser[infra_okay_runners:parse-okay]" in result.stdout_plain
|
||||
assert "lang/test_lang.py::test_xfail_eval[infra_fail_runners:eval-fail]" in result.stdout_plain
|
||||
assert "lang/test_lang.py::test_eval_okay[infra_okay_runners:eval-okay]" in result.stdout_plain
|
||||
assert (
|
||||
"lang/test_lang.py::test_xfail_parser[infra_fail_runners:parse-fail]" in result.stdout_plain
|
||||
"lang/test_lang.py::test_parse_okay[infra_okay_runners:parse-okay]" in result.stdout_plain
|
||||
)
|
||||
assert "lang/test_lang.py::test_eval_fail[infra_fail_runners:eval-fail]" in result.stdout_plain
|
||||
assert (
|
||||
"lang/test_lang.py::test_parse_fail[infra_fail_runners:parse-fail]" in result.stdout_plain
|
||||
)
|
||||
|
||||
|
||||
@@ -628,8 +630,8 @@ def test_toml_matrix_only_list_str(pytest_command: Command):
|
||||
def test_toml_matrix_uses_all_files(pytest_command: Command):
|
||||
res = pytest_command.run().ok()
|
||||
out = res.stdout_plain
|
||||
assert "test_eval[matrix-all:eval-okay] PASSED" in out
|
||||
assert "test_eval[matrix-all:eval-okay-1] PASSED" in out
|
||||
assert "test_eval_okay[matrix-all:eval-okay] PASSED" in out
|
||||
assert "test_eval_okay[matrix-all:eval-okay-1] PASSED" in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pytest_command", [[]], indirect=True)
|
||||
@@ -670,9 +672,9 @@ def test_toml_matrix_uses_all_files(pytest_command: Command):
|
||||
def test_toml_mixing_matrix_single(pytest_command: Command):
|
||||
res = pytest_command.run().ok()
|
||||
out = res.stdout_plain
|
||||
assert "test_eval[mixed-matrix:eval-okay] PASSED" in out
|
||||
assert "test_eval[mixed-matrix:eval-okay-1] PASSED" in out
|
||||
assert "test_eval[mixed-matrix:non-matrix-1] PASSED" in out
|
||||
assert "test_eval_okay[mixed-matrix:eval-okay] PASSED" in out
|
||||
assert "test_eval_okay[mixed-matrix:eval-okay-1] PASSED" in out
|
||||
assert "test_eval_okay[mixed-matrix:non-matrix-1] PASSED" in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pytest_command", [[]], indirect=True)
|
||||
@@ -747,11 +749,11 @@ def test_toml_non_unique_name(pytest_command: Command):
|
||||
def test_toml_matrix_subset(pytest_command: Command):
|
||||
res = pytest_command.run().ok()
|
||||
out = res.stdout_plain
|
||||
assert "test_eval[subset:matrix] PASSED" in out
|
||||
assert "test_eval[subset:matrix-hello] PASSED" in out
|
||||
assert "test_eval[subset:matrix-1] PASSED" not in out
|
||||
assert "test_eval[subset:eval-okay-1] PASSED" in out
|
||||
assert "test_eval[subset:eval-okay] PASSED" not in out
|
||||
assert "test_eval_okay[subset:matrix] PASSED" in out
|
||||
assert "test_eval_okay[subset:matrix-hello] PASSED" in out
|
||||
assert "test_eval_okay[subset:matrix-1] PASSED" not in out
|
||||
assert "test_eval_okay[subset:eval-okay-1] PASSED" in out
|
||||
assert "test_eval_okay[subset:eval-okay] PASSED" not in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pytest_command", [[]], indirect=True)
|
||||
@@ -816,7 +818,7 @@ def test_toml_bad_in_naming(pytest_command: Command):
|
||||
def test_toml_missing_in_file(pytest_command: Command):
|
||||
res = pytest_command.run().expect(1)
|
||||
out = res.stdout_plain
|
||||
assert "ERROR lang/test_lang.py::test_eval[toml-missing:eval-okay] - FileNotFound" in out
|
||||
assert "ERROR lang/test_lang.py::test_eval_okay[toml-missing:eval-okay] - FileNotF" in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pytest_command", [[]], indirect=True)
|
||||
@@ -838,7 +840,7 @@ def test_toml_missing_in_file(pytest_command: Command):
|
||||
def test_generic_missing_in_file(pytest_command: Command):
|
||||
res = pytest_command.run().expect(1)
|
||||
out = res.stdout_plain
|
||||
assert "ERROR lang/test_lang.py::test_eval[generic-missing:eval-okay] - FileNotFound" in out
|
||||
assert "ERROR lang/test_lang.py::test_eval_okay[generic-missing:eval-okay] - FileNotF" in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pytest_command", [["--setup-plan"]], indirect=True)
|
||||
|
||||
Reference in New Issue
Block a user