Skip to content

Commit

Permalink
test: count entire project
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Nov 14, 2024
1 parent 5db7ce5 commit 7df566c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lua/python_import/lookup_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ M.default_import_from = {
nullcontext = "contextlib",
closing = "contextlib",
deepcopy = "copy",
redirect_stdout = "contextlib",
redirect_stderr = "contextlib",

OrderedDict = "collections",
namedtuple = "collections",
Expand Down
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ testpaths = ["tests"]
log_cli = true
log_cli_level = "INFO"

[tool.coverage.report]
omit = [
"src/python_import/_version.py", # CHANGE
# OPTIONALLY ADD MORE LATER
]

[tool.ruff]
src = ["src"] # for ruff isort
namespace-packages = ["tools", "scripts", "tests"] # for INP rule, suppress on these directories
Expand Down Expand Up @@ -166,8 +172,3 @@ max-args = 10
max-bool-expr = 10
max-statements = 100

[tool.coverage.report]
omit = [
"src/python_import/_version.py", # CHANGE
# OPTIONALLY ADD MORE LATER
]
4 changes: 2 additions & 2 deletions src/python_import/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def common(

@app.command()
def count(
project_root: str,
project_root: Path,
module_name: str,
) -> None:
"""
Expand Down Expand Up @@ -92,7 +92,7 @@ def count(
# print(rg_output["type"])
if rg_output["type"] == "match":
file_path = str(
(Path(project_root) / rg_output["data"]["path"]["text"]).resolve()
(project_root / rg_output["data"]["path"]["text"]).resolve()
)
row = rg_output["data"]["line_number"] - 1
col = rg_output["data"]["submatches"][0]["start"]
Expand Down
1 change: 1 addition & 0 deletions tests/test_one_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

logger = logging.getLogger(__name__)


SCRIPT_DIR = Path(__file__).parent
PY_LANGUAGE = Language(tspython.language())
parser = Parser(PY_LANGUAGE)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from __future__ import annotations

from contextlib import redirect_stdout
from io import StringIO
from pathlib import Path

from python_import.cli.main import count

SCRIPT_DIR = Path(__file__).parent


def test_cli_count():
with redirect_stdout(StringIO()) as stdout:
count(
project_root=SCRIPT_DIR / "sample_projects/project1",
module_name="foo",
)

assert stdout.getvalue() == "00003:from python_import import foo\n"

0 comments on commit 7df566c

Please sign in to comment.