Skip to content

Commit c35ecb9

Browse files
jorenhammeta-codesync[bot]
authored andcommitted
Check the whole test corpus in the pyrefly coverage check/report consistency test (#4253)
Summary: The test that keeps `coverage check` findings consistent with the `coverage report` untyped symbols ran on an arbitrary list of 19 files, for no obvious reason (mea culpa). It now globs the `COVERAGE_TEST_PATH` directory, which currently counts 57 files, which also simplifies the testcase code. Pull Request resolved: #4253 Test Plan: That's indeed the point :) Reviewed By: rchen152 Differential Revision: D129033591 fbshipit-source-id: 3f1930c73d4b02e61b5f119782b86efa42864b37
1 parent 1633021 commit c35ecb9

1 file changed

Lines changed: 27 additions & 30 deletions

File tree

‎pyrefly/lib/commands/coverage/collect.rs‎

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,7 @@ pub fn collect_module_reports(
20332033

20342034
#[cfg(test)]
20352035
mod tests {
2036+
use std::collections::BTreeSet;
20362037
use std::collections::HashSet;
20372038
use std::path::PathBuf;
20382039

@@ -2052,12 +2053,17 @@ mod tests {
20522053
use crate::state::require::Require;
20532054
use crate::test::util::TestEnv;
20542055

2056+
/// The checked-in test-file directory from the COVERAGE_TEST_PATH env var.
2057+
fn test_files_dir() -> PathBuf {
2058+
let path =
2059+
std::env::var("COVERAGE_TEST_PATH").expect("COVERAGE_TEST_PATH env var must be set");
2060+
PathBuf::from(path)
2061+
}
2062+
20552063
/// Load a checked-in test file from the COVERAGE_TEST_PATH directory.
20562064
/// Normalizes `\r\n` to `\n` so snapshots pass on Windows.
20572065
fn load_test_file(name: &str) -> String {
2058-
let path =
2059-
std::env::var("COVERAGE_TEST_PATH").expect("COVERAGE_TEST_PATH env var must be set");
2060-
std::fs::read_to_string(PathBuf::from(path).join(name))
2066+
std::fs::read_to_string(test_files_dir().join(name))
20612067
.unwrap_or_else(|e| panic!("failed to read test file {name}: {e}"))
20622068
.replace("\r\n", "\n")
20632069
}
@@ -2420,33 +2426,24 @@ mod tests {
24202426

24212427
#[test]
24222428
fn test_check_findings_match_report_symbols() {
2423-
for file in [
2424-
"any_annotations.py",
2425-
"any_detection.py",
2426-
"decorators.py",
2427-
"dunder_attrs.py",
2428-
"dunder_implicit.py",
2429-
"functions.py",
2430-
"incomplete_methods.py",
2431-
"inheritance.py",
2432-
"inherited_attrs.py",
2433-
"instance_attrs.py",
2434-
"method_aliases.py",
2435-
"optional_imports.py",
2436-
"overloads.py",
2437-
"overloads_partial.py",
2438-
"partial_any.py",
2439-
"property_basic.py",
2440-
"schema_classes_methods.py",
2441-
"stub_ignores_py_annotations.pyi",
2442-
"variables.py",
2443-
] {
2444-
// `.pyi` entries are stub-merged with their `.py` source.
2445-
let (p, module_path) = if let Some(stem) = file.strip_suffix(".pyi") {
2446-
(
2447-
merged_stub_symbols(file, &format!("{stem}.py")),
2448-
"test.pyi".to_owned(),
2449-
)
2429+
// These need a site-package env; see their dedicated tests.
2430+
const SKIP: &[&str] = &["schema_classes_pydantic.py", "schema_classes_attrs.py"];
2431+
2432+
let files: BTreeSet<String> = std::fs::read_dir(test_files_dir())
2433+
.unwrap()
2434+
.map(|entry| entry.unwrap().file_name().into_string().unwrap())
2435+
.filter(|f| (f.ends_with(".py") || f.ends_with(".pyi")) && !SKIP.contains(&f.as_str()))
2436+
.collect();
2437+
assert!(files.len() > 30, "corpus discovery looks broken: {files:?}");
2438+
2439+
for file in &files {
2440+
// `.pyi` entries with a `.py` twin are stub-merged, like the production pipeline.
2441+
let py_twin = file
2442+
.strip_suffix(".pyi")
2443+
.map(|stem| format!("{stem}.py"))
2444+
.filter(|py| files.contains(py));
2445+
let (p, module_path) = if let Some(py) = py_twin {
2446+
(merged_stub_symbols(file, &py), "test.pyi".to_owned())
24502447
} else {
24512448
parse_test_module(file, TestEnv::new())
24522449
};

0 commit comments

Comments
 (0)