def _( root: Path = project, search=each("x/y/z", "a.py", "a/b.py", "a/b/c/d/e.py"), mod="a/b/c/d/e.py", ): module_path = root / mod assert not handled_within(module_path, [root / search])
def _( root: Path = project, search=each("", "/", "a", "a/b", "a/b/c"), mod="a/b/c/d/e.py", ): module_path = root / mod assert handled_within(module_path, [root / search])
async def _(email=each("", "invalid")): with raises(ValidationError) as exc: SocialLoginInput(email=email, social_account=SocialAccount(social_id="10")) errors = exc.raised.errors() assert len(errors) == 1 assert { "loc": ("email",), "msg": "value is not a valid email address", "type": "value_error.email", } in errors
def _( items=each(range(5), "echolocation", [-2, 3, 4, -3, 2, 3]), key=each(is_even, is_vowel, square), result=each( { True: [0, 2, 4], False: [1, 3] }, { True: ["e", "o", "o", "a", "i", "o"], False: ["c", "h", "l", "c", "t", "n"] }, { 4: [-2, 2], 9: [3, -3, 3], 16: [4] }, ), ): assert group_by(items, key) == result
def _(src=each( "assert x", "assert f(x)", "assert x + y + z", "assert 1 < 2 < 3", "assert 1 == 1 == 3", "print(x)", "yield", )): in_tree = ast.parse(src).body[0] out_tree = RewriteAssert().visit(in_tree) assert in_tree == out_tree
def _( mod=test_module, excludes=each( "*", "*/**.py", str(PATH), "**/test_mod.py", "path/to/*", "path/*/*.py", ), ): assert is_excluded_module(mod, [excludes])
def _( src=each( "assert x == y", "assert x != y", "assert x in y", "assert x not in y", "assert x is y", "assert x is not y", "assert x < y", "assert x <= y", "assert x > y", "assert x >= y", ), fn=each( "assert_equal", "assert_not_equal", "assert_in", "assert_not_in", "assert_is", "assert_is_not", "assert_less_than", "assert_less_than_equal_to", "assert_greater_than", "assert_greater_than_equal_to", ), ): in_tree = ast.parse(src).body[0] out_tree = RewriteAssert().visit(in_tree) assert out_tree.lineno == in_tree.lineno assert out_tree.col_offset == in_tree.col_offset assert out_tree.value.lineno == in_tree.lineno assert out_tree.value.col_offset == in_tree.col_offset assert out_tree.value.func.id == fn assert out_tree.value.args[0].id == "x" assert out_tree.value.args[1].id == "y" assert out_tree.value.args[2].s == ""
def _( src=each( "assert x == y", "assert x == y, 'message'", "assert x < y", "assert x in y", "assert x is y", "assert x is not y", ), func="my_assert", ): assert_node = ast.parse(src).body[0] call = make_call_node(assert_node, func) # check that `assert x OP y` becomes `my_assert(x, y, '')` lhs = assert_node.test.left.id rhs = assert_node.test.comparators[0].id msg = assert_node.msg.s if assert_node.msg else "" assert call.value.args[0].id == lhs assert call.value.args[1].id == rhs assert call.value.args[2].s == msg
def _(path=each(THIS_FILE.parent / "the-fixture-is-not-in-this-file.py")): fixtures = [Fixture(f) for f in [named_fixture]] assert list(filter_fixtures(fixtures, paths=[path])) == []
def _(query=each("echo", "foobar", "wizbang")): fixtures = [Fixture(f) for f in [named_fixture, marker_fixture]] assert list(filter_fixtures(fixtures, query=query)) == []
def _(path=each(THIS_FILE, THIS_FILE.parent, THIS_FILE.parent.parent)): fixtures = [Fixture(f) for f in [named_fixture]] assert list(filter_fixtures(fixtures, paths=[path])) == fixtures
def _(query=each("test", "test_collect", "collect", "t_coll")): fixtures = [Fixture(f) for f in [named_fixture]] assert list(filter_fixtures(fixtures, query=query)) == fixtures
def _(query=each("marker", "mark", "ret", "return", '"')): fixtures = [Fixture(f) for f in [named_fixture, marker_fixture]] assert list(filter_fixtures(fixtures, query=query)) == [Fixture(marker_fixture)]
def _(exit_code=each(0, 1), outcome=each(TestOutcome.FAIL, TestOutcome.FAIL)): t = Test(fn=lambda: sys.exit(exit_code), module_name=mod) assert t.run(FixtureCache()).outcome is outcome
def _(query=each("named_fixture", "named", "fixture", "med_fix")): fixtures = [Fixture(f) for f in [named_fixture]] assert list(filter_fixtures(fixtures, query=query)) == fixtures
def _(mod=test_module, excludes=each("abc", str(PATH.parent))): assert not is_excluded_module(mod, [excludes])
def test_1(a=each(1, 2), b=each(1, 2, 3)): pass
def _(input=s, num_chars=each(20, 11, 10, 5), expected=each(s, s, "hello w...", "he...")): result = truncate(input, num_chars) expect(result).equals(expected)
def _( outcome=each(TestOutcome.PASS, TestOutcome.SKIP, TestOutcome.FAIL, TestOutcome.XFAIL, TestOutcome.XPASS), colour=each("green", "blue", "red", "magenta", "yellow"), ): expect(outcome_to_colour(outcome)).equals(colour)
def invalid_test(a=each(1, 2), b=each(3, 4, 5)): pass
def test(a=each(1, 2), b=each(3, 4)): pass
def parameterised_test(a=each(1, 2, 3), b="a value"): pass
def _( module_name=each("test_apples", "apples"), rv=each(True, False), ): module = ModuleInfo(ModuleFinder(), module_name, False) assert is_test_module(module) == rv
def _(mod=test_module, excludes=each("abc", "/path/to", "/path")): assert not _is_excluded_module(mod, exclusions=[excludes])
fs_root = os.path.normpath(os.path.abspath(os.sep)) assert project_root == Path(fs_root) @fixture def fake_project_pyproject(): yield from make_project("pyproject.toml") @fixture def fake_project_git(): yield from make_project(".git") @using( root_file=each("pyproject.toml", ".git"), project=each(fake_project_pyproject, fake_project_git), ) @test("find_project_root finds project root with '{root_file}' file") def _(root_file, project): root = find_project_root([project / "a/b/c", project / "a/d"]) assert root.resolve() == project.resolve() assert (root / root_file).exists() def is_even(n): return n % 2 == 0 def is_vowel(char): return char in "aeiou"
call_kwargs = kwargs t = Test(fn=func, module_name=mod) t.run(cache) assert called_with == "val" assert call_kwargs == {"kwargs": {}} # type: ignore[comparison-overlap] @test("Test.run returns DRYRUN TestResult when dry_run == True") def _(cache=cache): t = Test(fn=lambda: 1, module_name=mod) result = t.run(cache, dry_run=True) assert result == TestResult(t, outcome=TestOutcome.DRYRUN) TRUTHY_PREDICATES = each(True, lambda: True, 1, "truthy string") FALSY_PREDICATES = each(False, lambda: False, 0, "") @test("Test.run returns *SKIP* TestResult, @skip(when={when})") def _(cache=cache, when=TRUTHY_PREDICATES): t = Test(fn=lambda: 1, module_name=mod, marker=SkipMarker(when=when)) result = t.run(cache) assert result == TestResult(t, outcome=TestOutcome.SKIP) @test("Test.run returns *PASS* TestResult for passing test, @skip(when={when})" ) def _(cache=cache, when=FALSY_PREDICATES): def test_fn(): assert True
def test_1(a=each(a, "second", a)): events.append("running test")
def _( input=s, num_chars=each(20, 11, 10, 5), expected=each(s, s, "hello w...", "he...") ): result = truncate(input, num_chars) assert result == expected
def test_2(a=each(1, 2), b=each(1, 2)): pass
def _(x=each(lambda: 5)): assert x == 5