use std::path::Path;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_load_module_file_detection() {
std::fs::write("src/test_single.py", "# test file").expect("Failed to create test file");
assert!(Path::new("src/test_single.py").exists());
std::fs::remove_file("src/test_single.py").ok();
}
#[test]
fn test_package_module_detection() {
std::fs::create_dir_all("src/test_package").ok();
std::fs::write("src/test_package/__init__.py", "# test package").expect("Failed to create test package");
assert!(Path::new("src/test_package/__init__.py").exists());
std::fs::remove_dir_all("src/test_package").ok();
}
#[test]
fn test_module_path_formats() {
let mod_name = "test_module";
let mod_name_dir = format!("src/{}/__init__.py", mod_name);
let mod_name_file = format!("src/{}.py", mod_name);
assert_eq!(mod_name_dir, "src/test_module/__init__.py");
assert_eq!(mod_name_file, "src/test_module.py");
}
#[test]
fn test_python_files_exist() {
assert!(Path::new("src/simple_math.py").exists());
assert!(Path::new("src/string_ops.py").exists());
assert!(Path::new("src/package_test/__init__.py").exists());
assert!(Path::new("src/empty_module.py").exists());
assert!(Path::new("src/minimal_test.py").exists());
}
#[test]
fn test_python_file_contents() {
let simple_math_content = std::fs::read_to_string("src/simple_math.py")
.expect("Failed to read simple_math.py");
assert!(simple_math_content.contains("def add(a, b):"));
assert!(simple_math_content.contains("def multiply(x, y):"));
assert!(simple_math_content.contains("PI = 3.14159"));
let empty_content = std::fs::read_to_string("src/empty_module.py")
.expect("Failed to read empty_module.py");
assert!(empty_content.contains("# Empty module"));
}
#[test]
fn test_string_formatting() {
let mod_name = "test_module";
let error_msg = format!("unable to determine parent of module for {}", mod_name);
assert_eq!(error_msg, "unable to determine parent of module for test_module");
let not_found_msg = format!("Module not found {}", mod_name);
assert_eq!(not_found_msg, "Module not found test_module");
}
#[test]
fn test_file_path_construction() {
let test_cases = vec![
("simple_math", "src/simple_math.py", "src/simple_math/__init__.py"),
("package_test", "src/package_test.py", "src/package_test/__init__.py"),
("empty_module", "src/empty_module.py", "src/empty_module/__init__.py"),
];
for (mod_name, expected_file, expected_dir) in test_cases {
let actual_file = format!("src/{}.py", mod_name);
let actual_dir = format!("src/{}/__init__.py", mod_name);
assert_eq!(actual_file, expected_file);
assert_eq!(actual_dir, expected_dir);
}
}
}