Skip to content

Commit 858a513

Browse files
Make paths OS-agnostic
1 parent 6e42cad commit 858a513

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

codegraph/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List, Union
44

55

6-
def get_python_paths_list(paths: Union[str, List]) -> List:
6+
def get_python_paths_list(paths: Union[str, List]) -> List[str]:
77
"""
88
return list of paths to python files, that found in provided path
99
:param paths: paths to folder or python file that need to tests
@@ -22,11 +22,10 @@ def get_python_paths_list(paths: Union[str, List]) -> List:
2222
for path in paths:
2323
path = Path(path).absolute()
2424
if not path.exists():
25-
raise ValueError(f"Path {path.as_posix()} does not exists")
26-
path = path.as_posix()
25+
raise ValueError(f"Path {path.as_posix()} does not exist")
2726
paths_list += [
28-
path
29-
for path in glob.glob(path + "/*", recursive=True)
30-
if path.endswith(".py") and not path.endswith("__init__.py")
27+
Path(p).as_posix()
28+
for p in glob.glob(str(path / "**" / "*.py"), recursive=True)
29+
if not p.endswith("__init__.py")
3130
]
3231
return paths_list

tests/test_utils.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ def test_get_python_paths_list_error():
1212

1313

1414
def test_get_python_paths_list():
15-
expected = list(
16-
map(
17-
lambda x: (pathlib.Path(__file__).parents[1] / "codegraph" / x).as_posix(),
18-
["core.py", "parser.py", "utils.py", "vizualyzer.py", "main.py"],
19-
)
20-
)
21-
assert sorted(
22-
get_python_paths_list(
23-
(pathlib.Path(__file__).parents[1] / "codegraph").as_posix()
24-
)) == sorted(expected)
15+
base_path = pathlib.Path(__file__).parents[1] / "codegraph"
16+
expected = [
17+
(base_path / x).as_posix()
18+
for x in ["core.py", "parser.py", "utils.py", "vizualyzer.py", "main.py"]
19+
]
20+
result = get_python_paths_list(base_path.as_posix())
21+
assert sorted(result) == sorted(expected)

0 commit comments

Comments
 (0)