Skip to content

Commit 7df566c

Browse files
committed
test: count entire project
1 parent 5db7ce5 commit 7df566c

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

lua/python_import/lookup_table.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ M.default_import_from = {
8383
nullcontext = "contextlib",
8484
closing = "contextlib",
8585
deepcopy = "copy",
86+
redirect_stdout = "contextlib",
87+
redirect_stderr = "contextlib",
8688

8789
OrderedDict = "collections",
8890
namedtuple = "collections",

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ testpaths = ["tests"]
5959
log_cli = true
6060
log_cli_level = "INFO"
6161

62+
[tool.coverage.report]
63+
omit = [
64+
"src/python_import/_version.py", # CHANGE
65+
# OPTIONALLY ADD MORE LATER
66+
]
67+
6268
[tool.ruff]
6369
src = ["src"] # for ruff isort
6470
namespace-packages = ["tools", "scripts", "tests"] # for INP rule, suppress on these directories
@@ -166,8 +172,3 @@ max-args = 10
166172
max-bool-expr = 10
167173
max-statements = 100
168174

169-
[tool.coverage.report]
170-
omit = [
171-
"src/python_import/_version.py", # CHANGE
172-
# OPTIONALLY ADD MORE LATER
173-
]

src/python_import/cli/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def common(
3939

4040
@app.command()
4141
def count(
42-
project_root: str,
42+
project_root: Path,
4343
module_name: str,
4444
) -> None:
4545
"""
@@ -92,7 +92,7 @@ def count(
9292
# print(rg_output["type"])
9393
if rg_output["type"] == "match":
9494
file_path = str(
95-
(Path(project_root) / rg_output["data"]["path"]["text"]).resolve()
95+
(project_root / rg_output["data"]["path"]["text"]).resolve()
9696
)
9797
row = rg_output["data"]["line_number"] - 1
9898
col = rg_output["data"]["submatches"][0]["start"]

tests/test_one_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
logger = logging.getLogger(__name__)
1212

13+
1314
SCRIPT_DIR = Path(__file__).parent
1415
PY_LANGUAGE = Language(tspython.language())
1516
parser = Parser(PY_LANGUAGE)

tests/test_project.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from __future__ import annotations
2+
3+
from contextlib import redirect_stdout
4+
from io import StringIO
5+
from pathlib import Path
6+
7+
from python_import.cli.main import count
8+
9+
SCRIPT_DIR = Path(__file__).parent
10+
11+
12+
def test_cli_count():
13+
with redirect_stdout(StringIO()) as stdout:
14+
count(
15+
project_root=SCRIPT_DIR / "sample_projects/project1",
16+
module_name="foo",
17+
)
18+
19+
assert stdout.getvalue() == "00003:from python_import import foo\n"

0 commit comments

Comments
 (0)