Skip to content

Commit

Permalink
Test fixes.
Browse files Browse the repository at this point in the history
[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
stuhood committed Aug 5, 2020
1 parent 931bee5 commit 96fff4d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def test_map_third_party_modules_to_addresses(self) -> None:
"""
),
)
result = self.request_single_product(ThirdPartyModuleToAddressMapping, Params())
result = self.request_single_product(
ThirdPartyModuleToAddressMapping, Params(create_options_bootstrapper())
)
assert result.mapping == FrozenDict(
{
"colors": Address.parse("3rdparty/python:ansicolors"),
Expand Down
33 changes: 13 additions & 20 deletions src/python/pants/backend/python/dependency_inference/rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,9 @@ def run_dep_inference(address: Address) -> InferredDependencies:
Params(InferPythonDependencies(target[PythonSources]), options_bootstrapper),
)

# NB: We do not infer `src/python/app.py`, even though it's used by `src/python/f2.py`,
# because it is part of the requested address.
normal_address = Address("src/python")
assert run_dep_inference(normal_address) == InferredDependencies(
[
Address("3rdparty/python", target_name="Django"),
Address("src/python/util", relative_file_path="dep.py", target_name="util"),
]
)

generated_subtarget_address = Address(
"src/python", relative_file_path="f2.py", target_name="python"
)
generated_subtarget_address = Address("src/python", relative_file_path="f2.py")
assert run_dep_inference(generated_subtarget_address) == InferredDependencies(
[Address("src/python", relative_file_path="app.py", target_name="python")]
[Address("src/python", relative_file_path="app.py")]
)

def test_infer_python_inits(self) -> None:
Expand All @@ -139,10 +127,12 @@ def run_dep_inference(address: Address) -> InferredDependencies:
Params(InferInitDependencies(target[PythonSources]), options_bootstrapper),
)

assert run_dep_inference(Address.parse("src/python/root/mid/leaf")) == InferredDependencies(
assert run_dep_inference(
Address("src/python/root/mid/leaf", relative_file_path="__init__.py")
) == InferredDependencies(
[
Address("src/python/root", relative_file_path="__init__.py", target_name="root"),
Address("src/python/root/mid", relative_file_path="__init__.py", target_name="mid"),
Address("src/python/root", relative_file_path="__init__.py"),
Address("src/python/root/mid", relative_file_path="__init__.py"),
]
)

Expand All @@ -168,9 +158,12 @@ def run_dep_inference(address: Address) -> InferredDependencies:
Params(InferConftestDependencies(target[PythonSources]), options_bootstrapper),
)

assert run_dep_inference(Address.parse("src/python/root/mid/leaf")) == InferredDependencies(
assert run_dep_inference(
Address("src/python/root/mid/leaf", relative_file_path="this_is_a_test.py")
) == InferredDependencies(
[
Address("src/python/root", relative_file_path="conftest.py", target_name="root"),
Address("src/python/root/mid", relative_file_path="conftest.py", target_name="mid"),
Address("src/python/root", relative_file_path="conftest.py"),
Address("src/python/root/mid", relative_file_path="conftest.py"),
Address("src/python/root/mid/leaf", relative_file_path="conftest.py"),
]
)
5 changes: 5 additions & 0 deletions src/python/pants/option/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ python_library()
python_tests(
name="tests",
sources=['*_test.py', '!*_integration_test.py'],
dependencies=[
# Used by `options_bootstrapper_test` and `config_test`.
'//:build_root',
'//:pants_toml',
],
timeout=300,
)

Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/testutil/goal_rule_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def assert_entries(self, sep: str, *output, **kwargs) -> None:
# ['1', '2', '3', ''] - always an extra empty string if the separator is properly always
# a suffix and not applied just between entries.
result = self.execute_rule(**kwargs)
assert sorted([*output, ""]) == sorted(result.stdout.split(sep))
self.assertEqual(sorted([*output, ""]), sorted(result.stdout.split(sep)))

def assert_console_output(self, *output, **kwargs) -> None:
"""Verifies the expected output entries are emitted by the goal rule.
Expand All @@ -114,7 +114,7 @@ def assert_console_output(self, *output, **kwargs) -> None:
**kwargs: additional kwargs passed to execute_rule.
"""
result = self.execute_rule(**kwargs)
assert sorted(output) == sorted(result.stdout.splitlines())
self.assertEqual(sorted(output), sorted(result.stdout.splitlines()))

def assert_console_output_contains(self, output, **kwargs) -> None:
"""Verifies the expected output string is emitted by the goal rule.
Expand Down
4 changes: 4 additions & 0 deletions tests/python/pants_test/init/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
python_tests(
name='tests',
timeout = 270,
dependencies=[
# Used by `test_options_initializer`.
'//:build_root',
],
)

python_library()
22 changes: 14 additions & 8 deletions tests/python/pants_test/integration/changed_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,30 @@ def add_to_git(commit_msg, *files):

class ChangedIntegrationTest(PantsRunIntegrationTest, AbstractTestGenerator):

# TODO(#10355): Once we teach `dependees` to understand generated subtargets, some of these
# should change to be generated subtargets.
TEST_MAPPING = {
# A `python_binary` with `sources=['file.name']`.
"src/python/python_targets/test_binary.py": dict(
none=["src/python/python_targets/test_binary.py:test"],
direct=["src/python/python_targets:test"],
transitive=["src/python/python_targets:test"],
direct=[
"src/python/python_targets/test_binary.py:test",
"src/python/python_targets:test",
],
transitive=[
"src/python/python_targets/test_binary.py:test",
"src/python/python_targets:test",
],
),
# A `python_library` with `sources=['file.name']`.
"src/python/python_targets/test_library.py": dict(
none=["src/python/python_targets/test_library.py:test_library"],
direct=[
"src/python/python_targets:test",
"src/python/python_targets/test_binary.py:test",
"src/python/python_targets/test_library.py:test_library",
"src/python/python_targets:test_library",
"src/python/python_targets:test_library_direct_dependee",
],
transitive=[
"src/python/python_targets/test_binary.py:test",
"src/python/python_targets/test_library.py:test_library",
"src/python/python_targets:test",
"src/python/python_targets:test_library",
"src/python/python_targets:test_library_direct_dependee",
Expand All @@ -165,8 +171,8 @@ class ChangedIntegrationTest(PantsRunIntegrationTest, AbstractTestGenerator):
# A `python_library` with `sources=['file.name'] .
"src/python/sources/sources.py": dict(
none=["src/python/sources/sources.py"],
direct=["src/python/sources"],
transitive=["src/python/sources"],
direct=["src/python/sources", "src/python/sources/sources.py",],
transitive=["src/python/sources", "src/python/sources/sources.py",],
),
# An unclaimed source file.
"src/python/python_targets/test_unclaimed_src.py": dict(none=[], direct=[], transitive=[]),
Expand Down

0 comments on commit 96fff4d

Please sign in to comment.