Skip to content

Commit

Permalink
Remove coverage tests for legacy adapter from buck2
Browse files Browse the repository at this point in the history
Summary: Legacy test adapter goes away

Reviewed By: fgasperij

Differential Revision: D63460646

fbshipit-source-id: 4d303fcd36fbeb64574d11337594e1b2a17442bd
  • Loading branch information
Nikita Patskov authored and facebook-github-bot committed Sep 30, 2024
1 parent c5f7282 commit 80d5330
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,49 @@

@buck_test(inplace=True)
async def test_python_coverage(buck: Buck) -> None:
for new_interface in ("true", "false"):
with tempfile.NamedTemporaryFile("w") as covfile:
await buck.test(
"@fbcode//mode/dbgo-cov",
"-c",
f"fbcode.use_new_testpilot_interface={new_interface}",
"fbcode//buck2/tests/targets/rules/python/coverage:test",
"--",
"--collect-coverage",
f"--coverage-output={covfile.name}",
)
paths = []
with open(covfile.name) as results:
for line in results:
paths.append(json.loads(line)["filepath"])
assert "fbcode/buck2/tests/targets/rules/python/coverage/lib.py" in paths, str(
paths
with tempfile.NamedTemporaryFile("w") as covfile:
await buck.test(
"@fbcode//mode/dbgo-cov",
"fbcode//buck2/tests/targets/rules/python/coverage:test",
"--",
"--collect-coverage",
f"--coverage-output={covfile.name}",
)
paths = []
with open(covfile.name) as results:
for line in results:
paths.append(json.loads(line)["filepath"])
assert "fbcode/buck2/tests/targets/rules/python/coverage/lib.py" in paths, str(
paths
)


@buck_test(inplace=True)
async def test_python_coverage_filtering_by_folder(buck: Buck) -> None:
folder_to_collect = "buck2/tests/targets/rules/python/coverage"
for new_interface in ("true", "false"):
with tempfile.NamedTemporaryFile("w") as covfile:
await buck.test(
"@fbcode//mode/dbgo-cov",
"-c",
f"fbcode.use_new_testpilot_interface={new_interface}",
"fbcode//buck2/tests/targets/rules/python/coverage:test",
"-c",
f"fbcode.cxx_coverage_only={folder_to_collect}",
"--",
"--collect-coverage",
f"--coverage-output={covfile.name}",
)
paths = []
with open(covfile.name) as results:
for line in results:
paths.append(json.loads(line)["filepath"])
assert set(paths) == {
f"fbcode/{folder_to_collect}/lib.py",
f"fbcode/{folder_to_collect}/test.py",
}, f"Only folder fbcode/{folder_to_collect} should have coverage, instead got coverage for {str(paths)}"
with tempfile.NamedTemporaryFile("w") as covfile:
await buck.test(
"@fbcode//mode/dbgo-cov",
"fbcode//buck2/tests/targets/rules/python/coverage:test",
"-c",
f"fbcode.cxx_coverage_only={folder_to_collect}",
"--",
"--collect-coverage",
f"--coverage-output={covfile.name}",
)
paths = []
with open(covfile.name) as results:
for line in results:
paths.append(json.loads(line)["filepath"])
assert set(paths) == {
f"fbcode/{folder_to_collect}/lib.py",
f"fbcode/{folder_to_collect}/test.py",
}, f"Only folder fbcode/{folder_to_collect} should have coverage, instead got coverage for {str(paths)}"


@dataclass
class PythonCoverageResult:
using_new_testpilot_interface_paths: List[str] = field(default_factory=list)
without_using_new_testpilot_interface_paths: List[str] = field(default_factory=list)


async def python_collect_coverage_for(
Expand All @@ -79,34 +72,28 @@ async def python_collect_coverage_for(
) -> PythonCoverageResult:
filter_str = " ".join(filter)
result = PythonCoverageResult()
for new_interface in ("true", "false"):
with tempfile.NamedTemporaryFile("w") as covfile:
buck_args = [mode] if mode else []
buck_args.extend(
[
"--config",
"fbcode.coverage_selective=true",
"--config",
f"fbcode.cxx_coverage_only={filter_str}",
"--config",
f"fbcode.use_new_testpilot_interface={new_interface}",
target,
"fbcode//buck2/tests/targets/rules/python/coverage:test",
"--",
"--collect-coverage",
f"--coverage-output={covfile.name}",
]
)
await buck.test(*buck_args)
paths = []
with open(covfile.name) as results:
for line in results:
paths.append(json.loads(line)["filepath"])

if new_interface == "true":
result.using_new_testpilot_interface_paths = paths
else:
result.without_using_new_testpilot_interface_paths = paths
with tempfile.NamedTemporaryFile("w") as covfile:
buck_args = [mode] if mode else []
buck_args.extend(
[
"--config",
"fbcode.coverage_selective=true",
"--config",
f"fbcode.cxx_coverage_only={filter_str}",
target,
"fbcode//buck2/tests/targets/rules/python/coverage:test",
"--",
"--collect-coverage",
f"--coverage-output={covfile.name}",
]
)
await buck.test(*buck_args)
paths = []
with open(covfile.name) as results:
for line in results:
paths.append(json.loads(line)["filepath"])

result.using_new_testpilot_interface_paths = paths

return result

Expand All @@ -121,10 +108,6 @@ async def test_python_coverage_filtering_by_file(buck: Buck) -> None:
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.using_new_testpilot_interface_paths)}"

assert set(result.without_using_new_testpilot_interface_paths) == {
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.without_using_new_testpilot_interface_paths)}"


@buck_test(inplace=True)
async def test_python_coverage_filtering_by_file_with_base_module_remap(
Expand All @@ -142,10 +125,6 @@ async def test_python_coverage_filtering_by_file_with_base_module_remap(
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.using_new_testpilot_interface_paths)}"

assert set(result.without_using_new_testpilot_interface_paths) == {
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.without_using_new_testpilot_interface_paths)}"


@buck_test(inplace=True)
async def test_python_coverage_filtering_by_file_with_opt_mode(buck: Buck) -> None:
Expand All @@ -161,10 +140,6 @@ async def test_python_coverage_filtering_by_file_with_opt_mode(buck: Buck) -> No
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.using_new_testpilot_interface_paths)}"

assert set(result.without_using_new_testpilot_interface_paths) == {
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.without_using_new_testpilot_interface_paths)}"


@buck_test(inplace=True)
async def test_python_coverage_filtering_by_file_on_cinder_target(buck: Buck) -> None:
Expand All @@ -180,10 +155,6 @@ async def test_python_coverage_filtering_by_file_on_cinder_target(buck: Buck) ->
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.using_new_testpilot_interface_paths)}"

assert set(result.without_using_new_testpilot_interface_paths) == {
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.without_using_new_testpilot_interface_paths)}"


@buck_test(inplace=True)
async def test_python_coverage_filtering_by_source_file_on_cpp_dep(buck: Buck) -> None:
Expand All @@ -199,10 +170,6 @@ async def test_python_coverage_filtering_by_source_file_on_cpp_dep(buck: Buck) -
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.using_new_testpilot_interface_paths)}"

assert set(result.without_using_new_testpilot_interface_paths) == {
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.without_using_new_testpilot_interface_paths)}"


@buck_test(inplace=True)
async def test_python_coverage_filtering_by_header_file_on_cpp_dep(buck: Buck) -> None:
Expand All @@ -219,10 +186,6 @@ async def test_python_coverage_filtering_by_header_file_on_cpp_dep(buck: Buck) -
fbcode_filename
}, f"Only {source_file} should have coverage, instead got coverage for {str(result.using_new_testpilot_interface_paths)}"

assert set(result.without_using_new_testpilot_interface_paths) == {
fbcode_filename
}, f"Only {source_file} should have coverage, instead got coverage for {str(result.without_using_new_testpilot_interface_paths)}"


@buck_test(inplace=True)
async def test_python_coverage_filtering_by_file_on_ligen_cpp_dep(buck: Buck) -> None:
Expand All @@ -239,7 +202,3 @@ async def test_python_coverage_filtering_by_file_on_ligen_cpp_dep(buck: Buck) ->
assert set(result.using_new_testpilot_interface_paths) == {
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.using_new_testpilot_interface_paths)}"

assert set(result.without_using_new_testpilot_interface_paths) == {
fbcode_filename
}, f"Only {file_to_collect_coverage} should have coverage, instead got coverage for {str(result.without_using_new_testpilot_interface_paths)}"
Loading

0 comments on commit 80d5330

Please sign in to comment.