use crate::migrate_ruff::migrate_file;
use crate::type_introspection_context::TypeIntrospectionContext;
use crate::types::TypeIntrospectionMethod;
use std::collections::HashMap;
use std::path::Path;
#[test]
fn test_file_refresh_after_migration() {
let source1 = r#"
from dissolve import replace_me
@replace_me()
def old_func(x):
return new_func(x * 2)
# First usage
result1 = old_func(5)
"#;
let source2 = r#"
from dissolve import replace_me
# This file imports from the first file
from test_module1 import old_func
# Second usage
result2 = old_func(10)
"#;
let mut type_context =
TypeIntrospectionContext::new(TypeIntrospectionMethod::PyrightWithMypyFallback).unwrap();
type_context
.open_file(Path::new("test_module1.py"), source1)
.unwrap();
type_context
.open_file(Path::new("test_module2.py"), source2)
.unwrap();
let collector = crate::RuffDeprecatedFunctionCollector::new(
"test_module1".to_string(),
Some(Path::new("test_module1.py")),
);
let result1 = collector.collect_from_source(source1.to_string()).unwrap();
let migrated1 = migrate_file(
source1,
"test_module1",
Path::new("test_module1.py"),
&mut type_context,
result1.replacements,
HashMap::new(),
)
.unwrap();
assert!(migrated1.contains("new_func(5 * 2)"));
assert!(!migrated1.contains("old_func(5)"));
let migrated2 = migrate_file(
source2,
"test_module2",
Path::new("test_module2.py"),
&mut type_context,
HashMap::new(), HashMap::new(),
)
.unwrap();
assert_eq!(migrated2, source2);
type_context.shutdown().unwrap();
}
#[test]
fn test_file_version_tracking() {
let source = r#"
def example():
return 42
"#;
let mut type_context =
TypeIntrospectionContext::new(TypeIntrospectionMethod::PyrightLsp).unwrap();
type_context
.open_file(Path::new("test.py"), source)
.unwrap();
let updated1 = "def example():\n return 43\n";
type_context
.update_file(Path::new("test.py"), updated1)
.unwrap();
let updated2 = "def example():\n return 44\n";
type_context
.update_file(Path::new("test.py"), updated2)
.unwrap();
type_context.shutdown().unwrap();
}