MCPcopy Create free account
hub / github.com/astral-sh/ruff / try_from

Method try_from

crates/ruff_python_parser/tests/generate_inline_tests.rs:152–182  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

150 type Error = anyhow::Error;
151
152 fn try_from(path: &Path) -> Result<Self> {
153 let mut tests = TestCollection::default();
154
155 for entry in walkdir::WalkDir::new(path) {
156 let entry = entry?;
157 if !entry.file_type().is_file() {
158 continue;
159 }
160 if entry.path().extension().unwrap_or_default() != "rs" {
161 continue;
162 }
163 let text = fs::read_to_string(entry.path())?;
164 for test in collect_tests(&text) {
165 if test.is_ok() {
166 if let Some(old_test) = tests.ok.insert(test.name.clone(), test) {
167 anyhow::bail!(
168 "Duplicate test found: {name:?} (search '// test_ok {name}' for the location)\n",
169 name = old_test.name
170 );
171 }
172 } else if let Some(old_test) = tests.err.insert(test.name.clone(), test) {
173 anyhow::bail!(
174 "Duplicate test found: {name:?} (search '// test_err {name}' for the location)\n",
175 name = old_test.name
176 );
177 }
178 }
179 }
180
181 Ok(tests)
182 }
183}
184
185#[derive(Debug, Clone, Copy)]

Callers

nothing calls this directly

Calls 10

collect_testsFunction · 0.85
OkClass · 0.85
is_okMethod · 0.80
defaultFunction · 0.50
is_fileMethod · 0.45
file_typeMethod · 0.45
extensionMethod · 0.45
pathMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected