Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tests/analyze/test_analyze_json_go.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import json
import os
from typer.testing import CliRunner
from cli.main import app

# Setup test runner
runner = CliRunner()

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

def test_analyze_command_with_json_flag():
"""Test the analyze command with the --json flag for Go"""
# Run the command with --json flag
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"])

# Check if the command executed successfully
assert result.exit_code == 0

# Parse the JSON output
output = json.loads(result.stdout)

# Check if all expected stats are in the output
assert "file_name" in output
assert "line_count" in output
assert "comment_line_count" in output
assert "function_count" in output

# Verify the values match expected results
assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH)
assert output["line_count"] == 194
assert output["comment_line_count"] == 34
assert output["function_count"] == 15

def test_analyze_command_with_all_and_json_flags():
"""Test the analyze command with both --all and --json flags for Go"""
# Run the command with both flags
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"])

# Check if the command executed successfully
assert result.exit_code == 0

# Parse the JSON output
output = json.loads(result.stdout)

# Verify the values match expected results
assert output["line_count"] == 194
assert output["comment_line_count"] == 34
assert output["function_count"] == 15

def test_analyze_command_with_nonexistent_file():
"""Test the analyze command with a nonexistent file"""
# Run the command with a file that doesn't exist
result = runner.invoke(app, ["analyze", "nonexistent_file.go", "--json"])

# Parse the JSON output (should contain an error)
output = json.loads(result.stdout)

# Check if the output contains an error message
assert "error" in output
60 changes: 60 additions & 0 deletions tests/analyze/test_analyze_json_javascript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import json
import os
from typer.testing import CliRunner
from cli.main import app

# Setup test runner
runner = CliRunner()

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

def test_analyze_command_with_json_flag():
"""Test the analyze command with the --json flag for JavaScript"""
# Run the command with --json flag
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"])

# Check if the command executed successfully
assert result.exit_code == 0

# Parse the JSON output
output = json.loads(result.stdout)

# Check if all expected stats are in the output
assert "file_name" in output
assert "line_count" in output
assert "comment_line_count" in output
assert "function_count" in output

# Verify the values match expected results
assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH)
assert output["line_count"] == 152
assert output["comment_line_count"] == 23
assert output["function_count"] == 15

def test_analyze_command_with_all_and_json_flags():
"""Test the analyze command with both --all and --json flags for JavaScript"""
# Run the command with both flags
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"])

# Check if the command executed successfully
assert result.exit_code == 0

# Parse the JSON output
output = json.loads(result.stdout)

# Verify the values match expected results
assert output["line_count"] == 152
assert output["comment_line_count"] == 23
assert output["function_count"] == 15

def test_analyze_command_with_nonexistent_file():
"""Test the analyze command with a nonexistent file"""
# Run the command with a file that doesn't exist
result = runner.invoke(app, ["analyze", "nonexistent_file.js", "--json"])

# Parse the JSON output (should contain an error)
output = json.loads(result.stdout)

# Check if the output contains an error message
assert "error" in output
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.py")

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

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

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

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

# Check if the output contains an error message
assert "error" in output
assert "error" in output
60 changes: 60 additions & 0 deletions tests/analyze/test_analyze_json_ruby.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import json
import os
from typer.testing import CliRunner
from cli.main import app

# Setup test runner
runner = CliRunner()

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

def test_analyze_command_with_json_flag():
"""Test the analyze command with the --json flag for Ruby"""
# Run the command with --json flag
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"])

# Check if the command executed successfully
assert result.exit_code == 0

# Parse the JSON output
output = json.loads(result.stdout)

# Check if all expected stats are in the output
assert "file_name" in output
assert "line_count" in output
assert "comment_line_count" in output
assert "function_count" in output

# Verify the values match expected results
assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH)
assert output["line_count"] == 225
assert output["comment_line_count"] == 50
assert output["function_count"] == 17

def test_analyze_command_with_all_and_json_flags():
"""Test the analyze command with both --all and --json flags for Ruby"""
# Run the command with both flags
result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"])

# Check if the command executed successfully
assert result.exit_code == 0

# Parse the JSON output
output = json.loads(result.stdout)

# Verify the values match expected results
assert output["line_count"] == 225
assert output["comment_line_count"] == 50
assert output["function_count"] == 17

def test_analyze_command_with_nonexistent_file():
"""Test the analyze command with a nonexistent file"""
# Run the command with a file that doesn't exist
result = runner.invoke(app, ["analyze", "nonexistent_file.rb", "--json"])

# Parse the JSON output (should contain an error)
output = json.loads(result.stdout)

# Check if the output contains an error message
assert "error" in output