mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-18 19:41:34 +00:00
[ty] Simplify semantic token tests (#21206)
This commit is contained in:
parent
1b2ed6a503
commit
e8c35b9704
5 changed files with 422 additions and 411 deletions
|
|
@ -302,7 +302,6 @@ mod tests {
|
|||
|
||||
use insta::assert_snapshot;
|
||||
use ruff_db::{
|
||||
Db as _,
|
||||
files::{File, system_path_to_file},
|
||||
source::source_text,
|
||||
};
|
||||
|
|
@ -311,9 +310,6 @@ mod tests {
|
|||
|
||||
use ruff_db::system::{DbWithWritableSystem, SystemPathBuf};
|
||||
use ty_project::ProjectMetadata;
|
||||
use ty_python_semantic::{
|
||||
Program, ProgramSettings, PythonPlatform, PythonVersionWithSource, SearchPathSettings,
|
||||
};
|
||||
|
||||
pub(super) fn inlay_hint_test(source: &str) -> InlayHintTest {
|
||||
const START: &str = "<START>";
|
||||
|
|
@ -324,6 +320,8 @@ mod tests {
|
|||
SystemPathBuf::from("/"),
|
||||
));
|
||||
|
||||
db.init_program().unwrap();
|
||||
|
||||
let source = dedent(source);
|
||||
|
||||
let start = source.find(START);
|
||||
|
|
@ -345,19 +343,6 @@ mod tests {
|
|||
|
||||
let file = system_path_to_file(&db, "main.py").expect("newly written file to existing");
|
||||
|
||||
let search_paths = SearchPathSettings::new(vec![SystemPathBuf::from("/")])
|
||||
.to_search_paths(db.system(), db.vendored())
|
||||
.expect("Valid search path settings");
|
||||
|
||||
Program::from_settings(
|
||||
&db,
|
||||
ProgramSettings {
|
||||
python_version: PythonVersionWithSource::default(),
|
||||
python_platform: PythonPlatform::default(),
|
||||
search_paths,
|
||||
},
|
||||
);
|
||||
|
||||
InlayHintTest { db, file, range }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -338,9 +338,6 @@ mod tests {
|
|||
use ruff_python_trivia::textwrap::dedent;
|
||||
use ruff_text_size::TextSize;
|
||||
use ty_project::ProjectMetadata;
|
||||
use ty_python_semantic::{
|
||||
Program, ProgramSettings, PythonPlatform, PythonVersionWithSource, SearchPathSettings,
|
||||
};
|
||||
|
||||
/// A way to create a simple single-file (named `main.py`) cursor test.
|
||||
///
|
||||
|
|
@ -417,18 +414,7 @@ mod tests {
|
|||
SystemPathBuf::from("/"),
|
||||
));
|
||||
|
||||
let search_paths = SearchPathSettings::new(vec![SystemPathBuf::from("/")])
|
||||
.to_search_paths(db.system(), db.vendored())
|
||||
.expect("Valid search path settings");
|
||||
|
||||
Program::from_settings(
|
||||
&db,
|
||||
ProgramSettings {
|
||||
python_version: PythonVersionWithSource::default(),
|
||||
python_platform: PythonPlatform::default(),
|
||||
search_paths,
|
||||
},
|
||||
);
|
||||
db.init_program().unwrap();
|
||||
|
||||
let mut cursor: Option<Cursor> = None;
|
||||
for &Source {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -516,11 +516,13 @@ pub(crate) mod tests {
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use ruff_db::Db as SourceDb;
|
||||
use ruff_db::files::Files;
|
||||
use ruff_db::files::{FileRootKind, Files};
|
||||
use ruff_db::system::{DbWithTestSystem, System, TestSystem};
|
||||
use ruff_db::vendored::VendoredFileSystem;
|
||||
use ty_python_semantic::Program;
|
||||
use ty_python_semantic::lint::{LintRegistry, RuleSelection};
|
||||
use ty_python_semantic::{
|
||||
Program, ProgramSettings, PythonPlatform, PythonVersionWithSource, SearchPathSettings,
|
||||
};
|
||||
|
||||
use crate::db::Db;
|
||||
use crate::{Project, ProjectMetadata};
|
||||
|
|
@ -560,6 +562,27 @@ pub(crate) mod tests {
|
|||
db.project = Some(project);
|
||||
db
|
||||
}
|
||||
|
||||
pub fn init_program(&mut self) -> anyhow::Result<()> {
|
||||
let root = self.project().root(self);
|
||||
|
||||
let search_paths = SearchPathSettings::new(vec![root.to_path_buf()])
|
||||
.to_search_paths(self.system(), self.vendored())
|
||||
.expect("Valid search path settings");
|
||||
|
||||
Program::from_settings(
|
||||
self,
|
||||
ProgramSettings {
|
||||
python_version: PythonVersionWithSource::default(),
|
||||
python_platform: PythonPlatform::default(),
|
||||
search_paths,
|
||||
},
|
||||
);
|
||||
|
||||
self.files().try_add_root(self, root, FileRootKind::Project);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TestDb {
|
||||
|
|
|
|||
|
|
@ -751,34 +751,20 @@ mod tests {
|
|||
use crate::ProjectMetadata;
|
||||
use crate::check_file_impl;
|
||||
use crate::db::tests::TestDb;
|
||||
use ruff_db::Db as _;
|
||||
use ruff_db::files::system_path_to_file;
|
||||
use ruff_db::source::source_text;
|
||||
use ruff_db::system::{DbWithTestSystem, DbWithWritableSystem as _, SystemPath, SystemPathBuf};
|
||||
use ruff_db::testing::assert_function_query_was_not_run;
|
||||
use ruff_python_ast::name::Name;
|
||||
use ty_python_semantic::types::check_types;
|
||||
use ty_python_semantic::{
|
||||
Program, ProgramSettings, PythonPlatform, PythonVersionWithSource, SearchPathSettings,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn check_file_skips_type_checking_when_file_cant_be_read() -> ruff_db::system::Result<()> {
|
||||
let project = ProjectMetadata::new(Name::new_static("test"), SystemPathBuf::from("/"));
|
||||
let mut db = TestDb::new(project);
|
||||
db.init_program().unwrap();
|
||||
let path = SystemPath::new("test.py");
|
||||
|
||||
Program::from_settings(
|
||||
&db,
|
||||
ProgramSettings {
|
||||
python_version: PythonVersionWithSource::default(),
|
||||
python_platform: PythonPlatform::default(),
|
||||
search_paths: SearchPathSettings::new(vec![SystemPathBuf::from(".")])
|
||||
.to_search_paths(db.system(), db.vendored())
|
||||
.expect("Valid search path settings"),
|
||||
},
|
||||
);
|
||||
|
||||
db.write_file(path, "x = 10")?;
|
||||
let file = system_path_to_file(&db, path).unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue