Skip to content

Commit 00ba8cb

Browse files
committed
fix tests now that pyo3 serializes PathBuf into Path instead of str
1 parent db67117 commit 00ba8cb

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

python/tach/extension.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ProjectConfig:
142142
cache: CacheConfig
143143
external: ExternalDependencyConfig
144144
exclude: list[str]
145-
source_roots: list[str]
145+
source_roots: list[Path]
146146
exact: bool
147147
disable_logging: bool
148148
ignore_type_checking_imports: bool

python/tach/mod.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def handle_utility_edits(
6363

6464

6565
def handle_source_root_edits(
66-
project_config: ProjectConfig, selected_source_roots: list[str]
66+
project_config: ProjectConfig, selected_source_roots: list[Path]
6767
) -> None:
6868
existing_source_roots = set(project_config.source_roots)
6969
selected_source_roots_set = set(selected_source_roots)
@@ -93,8 +93,7 @@ def apply_selected_configuration(
9393
project_config.set_location(project_config_path)
9494

9595
relative_selected_source_roots = [
96-
str(source_root.relative_to(project_root))
97-
for source_root in selected_source_roots
96+
source_root.relative_to(project_root) for source_root in selected_source_roots
9897
]
9998
handle_source_root_edits(project_config, relative_selected_source_roots)
10099

python/tests/test_mod.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
34
from unittest.mock import patch
45

56
import pytest
@@ -51,7 +52,7 @@ def test_mod_edit_interactive_new_configuration(
5152

5253
# Verify the saved configuration
5354
saved_config = parse_project_config(temp_project_dir)
54-
assert set(saved_config.source_roots) == {"src"}
55+
assert set(saved_config.source_roots) == {Path("src")}
5556
assert set(saved_config.module_paths()) == {"module1", "module2", "utils"}
5657
assert set(saved_config.utility_paths()) == {"utils"}
5758

@@ -123,7 +124,7 @@ def test_mod_edit_interactive_update_existing(temp_project_dir, initial_project_
123124
mock_get.assert_called_once()
124125

125126
saved_config = parse_project_config(temp_project_dir)
126-
assert set(saved_config.source_roots) == {"src", "tests"}
127+
assert set(saved_config.source_roots) == {Path("src"), Path("tests")}
127128
assert set(saved_config.module_paths()) == {"new_module", "new_utility"}
128129
assert set(saved_config.utility_paths()) == {"new_utility"}
129130

@@ -152,6 +153,6 @@ def test_mod_edit_interactive_update_existing(temp_project_dir, initial_project_
152153

153154
# Verify final configuration
154155
final_config = parse_project_config(temp_project_dir)
155-
assert set(final_config.source_roots) == {"src"}
156+
assert set(final_config.source_roots) == {Path("src")}
156157
assert set(final_config.module_paths()) == {"new_module", "another_module"}
157158
assert set(final_config.utility_paths()) == set()

src/commands/helpers/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'py> IntoPyObject<'py> for LocatedImport {
2020
type Target = PythonImport;
2121
type Output = Bound<'py, Self::Target>;
2222
type Error = pyo3::PyErr;
23-
fn into_pyobject(self, py: Python<'py>) -> std::result::Result<Self::Output, Self::Error> {
23+
fn into_pyobject(self, py: Python<'py>) -> std::result::Result<Self::Output, Self::Error> {
2424
PythonImport {
2525
module_path: self.import.module_path,
2626
line_number: self.alias_line_number,

src/config/rules.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ impl<'py> IntoPyObject<'py> for RuleSetting {
4040
type Target = PyString;
4141
type Output = Bound<'py, Self::Target>;
4242
type Error = std::convert::Infallible;
43-
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, <RuleSetting as IntoPyObject<'py>>::Error> {
43+
fn into_pyobject(
44+
self,
45+
py: Python<'py>,
46+
) -> Result<Self::Output, <RuleSetting as IntoPyObject<'py>>::Error> {
4447
match self {
4548
Self::Error => "error".into_pyobject(py),
4649
Self::Warn => "warn".into_pyobject(py),

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,7 @@ fn extension(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
339339
m.add_class::<dep_map::PyDirection>()?;
340340
m.add_class::<test::TachPytestPluginHandler>()?;
341341
m.add_function(wrap_pyfunction!(parse_project_config, m)?)?;
342-
m.add_function(wrap_pyfunction!(
343-
parse_project_config_from_pyproject,
344-
m
345-
)?)?;
342+
m.add_function(wrap_pyfunction!(parse_project_config_from_pyproject, m)?)?;
346343
m.add_function(wrap_pyfunction!(get_project_imports, m)?)?;
347344
m.add_function(wrap_pyfunction!(get_external_imports, m)?)?;
348345
m.add_function(wrap_pyfunction!(check_external_dependencies, m)?)?;

0 commit comments

Comments
 (0)