Skip to content

Commit 4d699b2

Browse files
committed
test external dependencies in py json
1 parent 6fbc106 commit 4d699b2

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/analyze/test_analyze_json_python.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
import os
33
from typer.testing import CliRunner
44
from cli.main import app
5+
from cli.commands.analyze import analyze_to_json
56

67
# Setup test runner
78
runner = CliRunner()
89

910
# Get the absolute path to the sample file
1011
SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.py")
1112

13+
# Get path to the sample files
14+
SAMPLES_DIR = os.path.join(os.path.dirname(__file__), "..", "sample-code")
15+
PY_SAMPLE = os.path.join(SAMPLES_DIR, "example.py")
16+
1217
def test_analyze_command_with_json_flag():
1318
"""Test the analyze command with the --json flag for Python"""
1419
# Run the command with --json flag
@@ -61,3 +66,35 @@ def test_analyze_command_with_nonexistent_file():
6166

6267
# Check if the output contains an error message
6368
assert "error" in output
69+
70+
def test_analyze_json_python():
71+
result = analyze_to_json(PY_SAMPLE, ["line_count", "function_count", "comment_line_count", "blank_line_count", "inline_comment_count", "external_dependencies_count"])
72+
73+
json_obj = json.loads(result)
74+
assert isinstance(json_obj, dict)
75+
assert PY_SAMPLE in json_obj
76+
77+
stats = json_obj[PY_SAMPLE]
78+
assert isinstance(stats, dict)
79+
assert "line_count" in stats
80+
assert "function_count" in stats
81+
assert "comment_line_count" in stats
82+
assert "blank_line_count" in stats
83+
assert "inline_comment_count" in stats
84+
assert "external_dependencies_count" in stats
85+
86+
assert isinstance(stats["line_count"], int)
87+
assert isinstance(stats["function_count"], int)
88+
assert isinstance(stats["comment_line_count"], int)
89+
assert isinstance(stats["blank_line_count"], int)
90+
assert isinstance(stats["inline_comment_count"], int)
91+
assert isinstance(stats["external_dependencies_count"], int)
92+
93+
assert stats["line_count"] > 0
94+
assert stats["function_count"] >= 0
95+
assert stats["comment_line_count"] >= 0
96+
assert stats["blank_line_count"] >= 0
97+
assert stats["inline_comment_count"] == 2
98+
# This assertion depends on the content of example.py
99+
# If the sample file has external dependencies, this should be adjusted accordingly
100+
assert isinstance(stats["external_dependencies_count"], int)

0 commit comments

Comments
 (0)