Skip to content

Commit 5ba8f8f

Browse files
authored
Merge pull request #129 from ManfredHair/tests-for-all-langs
tests for all 4 langs
2 parents 40ae2ee + 0a97503 commit 5ba8f8f

4 files changed

Lines changed: 183 additions & 3 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import json
2+
import os
3+
from typer.testing import CliRunner
4+
from cli.main import app
5+
6+
# Setup test runner
7+
runner = CliRunner()
8+
9+
# Get the absolute path to the sample file
10+
SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.go")
11+
12+
def test_analyze_command_with_json_flag():
13+
"""Test the analyze command with the --json flag for Go"""
14+
# Run the command with --json flag
15+
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"])
16+
17+
# Check if the command executed successfully
18+
assert result.exit_code == 0
19+
20+
# Parse the JSON output
21+
output = json.loads(result.stdout)
22+
23+
# Check if all expected stats are in the output
24+
assert "file_name" in output
25+
assert "line_count" in output
26+
assert "comment_line_count" in output
27+
assert "function_count" in output
28+
29+
# Verify the values match expected results
30+
assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH)
31+
assert output["line_count"] == 194
32+
assert output["comment_line_count"] == 34
33+
assert output["function_count"] == 15
34+
35+
def test_analyze_command_with_all_and_json_flags():
36+
"""Test the analyze command with both --all and --json flags for Go"""
37+
# Run the command with both flags
38+
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"])
39+
40+
# Check if the command executed successfully
41+
assert result.exit_code == 0
42+
43+
# Parse the JSON output
44+
output = json.loads(result.stdout)
45+
46+
# Verify the values match expected results
47+
assert output["line_count"] == 194
48+
assert output["comment_line_count"] == 34
49+
assert output["function_count"] == 15
50+
51+
def test_analyze_command_with_nonexistent_file():
52+
"""Test the analyze command with a nonexistent file"""
53+
# Run the command with a file that doesn't exist
54+
result = runner.invoke(app, ["analyze", "nonexistent_file.go", "--json"])
55+
56+
# Parse the JSON output (should contain an error)
57+
output = json.loads(result.stdout)
58+
59+
# Check if the output contains an error message
60+
assert "error" in output
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import json
2+
import os
3+
from typer.testing import CliRunner
4+
from cli.main import app
5+
6+
# Setup test runner
7+
runner = CliRunner()
8+
9+
# Get the absolute path to the sample file
10+
SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.js")
11+
12+
def test_analyze_command_with_json_flag():
13+
"""Test the analyze command with the --json flag for JavaScript"""
14+
# Run the command with --json flag
15+
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"])
16+
17+
# Check if the command executed successfully
18+
assert result.exit_code == 0
19+
20+
# Parse the JSON output
21+
output = json.loads(result.stdout)
22+
23+
# Check if all expected stats are in the output
24+
assert "file_name" in output
25+
assert "line_count" in output
26+
assert "comment_line_count" in output
27+
assert "function_count" in output
28+
29+
# Verify the values match expected results
30+
assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH)
31+
assert output["line_count"] == 152
32+
assert output["comment_line_count"] == 23
33+
assert output["function_count"] == 15
34+
35+
def test_analyze_command_with_all_and_json_flags():
36+
"""Test the analyze command with both --all and --json flags for JavaScript"""
37+
# Run the command with both flags
38+
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"])
39+
40+
# Check if the command executed successfully
41+
assert result.exit_code == 0
42+
43+
# Parse the JSON output
44+
output = json.loads(result.stdout)
45+
46+
# Verify the values match expected results
47+
assert output["line_count"] == 152
48+
assert output["comment_line_count"] == 23
49+
assert output["function_count"] == 15
50+
51+
def test_analyze_command_with_nonexistent_file():
52+
"""Test the analyze command with a nonexistent file"""
53+
# Run the command with a file that doesn't exist
54+
result = runner.invoke(app, ["analyze", "nonexistent_file.js", "--json"])
55+
56+
# Parse the JSON output (should contain an error)
57+
output = json.loads(result.stdout)
58+
59+
# Check if the output contains an error message
60+
assert "error" in output

tests/analyze/test_analyze_json_python-example.py renamed to tests/analyze/test_analyze_json_python.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.py")
1111

1212
def test_analyze_command_with_json_flag():
13-
"""Test the analyze command with the --json flag"""
13+
"""Test the analyze command with the --json flag for Python"""
1414
# Run the command with --json flag
1515
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"])
1616

@@ -33,7 +33,7 @@ def test_analyze_command_with_json_flag():
3333
assert output["function_count"] == 17
3434

3535
def test_analyze_command_with_all_and_json_flags():
36-
"""Test the analyze command with both --all and --json flags"""
36+
"""Test the analyze command with both --all and --json flags for Python"""
3737
# Run the command with both flags
3838
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"])
3939

@@ -57,4 +57,4 @@ def test_analyze_command_with_nonexistent_file():
5757
output = json.loads(result.stdout)
5858

5959
# Check if the output contains an error message
60-
assert "error" in output
60+
assert "error" in output
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import json
2+
import os
3+
from typer.testing import CliRunner
4+
from cli.main import app
5+
6+
# Setup test runner
7+
runner = CliRunner()
8+
9+
# Get the absolute path to the sample file
10+
SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.rb")
11+
12+
def test_analyze_command_with_json_flag():
13+
"""Test the analyze command with the --json flag for Ruby"""
14+
# Run the command with --json flag
15+
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"])
16+
17+
# Check if the command executed successfully
18+
assert result.exit_code == 0
19+
20+
# Parse the JSON output
21+
output = json.loads(result.stdout)
22+
23+
# Check if all expected stats are in the output
24+
assert "file_name" in output
25+
assert "line_count" in output
26+
assert "comment_line_count" in output
27+
assert "function_count" in output
28+
29+
# Verify the values match expected results
30+
assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH)
31+
assert output["line_count"] == 225
32+
assert output["comment_line_count"] == 50
33+
assert output["function_count"] == 17
34+
35+
def test_analyze_command_with_all_and_json_flags():
36+
"""Test the analyze command with both --all and --json flags for Ruby"""
37+
# Run the command with both flags
38+
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"])
39+
40+
# Check if the command executed successfully
41+
assert result.exit_code == 0
42+
43+
# Parse the JSON output
44+
output = json.loads(result.stdout)
45+
46+
# Verify the values match expected results
47+
assert output["line_count"] == 225
48+
assert output["comment_line_count"] == 50
49+
assert output["function_count"] == 17
50+
51+
def test_analyze_command_with_nonexistent_file():
52+
"""Test the analyze command with a nonexistent file"""
53+
# Run the command with a file that doesn't exist
54+
result = runner.invoke(app, ["analyze", "nonexistent_file.rb", "--json"])
55+
56+
# Parse the JSON output (should contain an error)
57+
output = json.loads(result.stdout)
58+
59+
# Check if the output contains an error message
60+
assert "error" in output

0 commit comments

Comments
 (0)