Skip to content

Commit 5718aef

Browse files
committed
un comment count comment line test to see whats wrong and then hopefully fix it
1 parent 7cda24b commit 5718aef

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
# import pytest
2-
# import os
3-
# from spice.analyzers.count_comment_lines import count_comment_lines
1+
import pytest
2+
import os
3+
from spice.analyzers.count_comment_lines import count_comment_lines
44

5-
# # Define the path to the sample code directory relative to the test file
6-
# SAMPLE_CODE_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "sample-code")
5+
# Define the path to the sample code directory relative to the test file
6+
SAMPLE_CODE_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "sample-code")
77

8-
# # Test cases for count_comment_lines
9-
# @pytest.mark.parametrize(
10-
# "filename, expected_comment_lines",
11-
# [
12-
# ("sample_comments.py", 4), # Based on the content of sample_comments.py
13-
# ("example.py", 1), # Based on the content of example.py (assuming it has one full comment line)
14-
# ("example.js", 2), # Based on the content of example.js (assuming two full comment lines)
15-
# ("example.go", 2), # Based on the content of example.go (assuming two full comment lines)
16-
# ("example.rb", 1), # Based on the content of example.rb (assuming one full comment line)
17-
# ]
18-
# )
19-
# def test_count_comment_lines_python(filename, expected_comment_lines):
20-
# """Test count_comment_lines with various sample files."""
21-
# file_path = os.path.join(SAMPLE_CODE_DIR, filename)
22-
# # Ensure the sample file exists before running the test
23-
# assert os.path.exists(file_path), f"Sample file not found: {file_path}"
24-
# assert count_comment_lines(file_path) == expected_comment_lines
8+
# Test cases for count_comment_lines
9+
@pytest.mark.parametrize(
10+
"filename, expected_comment_lines",
11+
[
12+
("sample_comments.py", 4), # Based on the content of sample_comments.py
13+
("example.py", 1), # Based on the content of example.py (assuming it has one full comment line)
14+
("example.js", 2), # Based on the content of example.js (assuming two full comment lines)
15+
("example.go", 2), # Based on the content of example.go (assuming two full comment lines)
16+
("example.rb", 1), # Based on the content of example.rb (assuming one full comment line)
17+
]
18+
)
19+
def test_count_comment_lines_python(filename, expected_comment_lines):
20+
"""Test count_comment_lines with various sample files."""
21+
file_path = os.path.join(SAMPLE_CODE_DIR, filename)
22+
# Ensure the sample file exists before running the test
23+
assert os.path.exists(file_path), f"Sample file not found: {file_path}"
24+
assert count_comment_lines(file_path) == expected_comment_lines
2525

26-
# def test_count_comment_lines_empty_file():
27-
# """Test count_comment_lines with an empty file."""
28-
# empty_file_path = os.path.join(SAMPLE_CODE_DIR, "empty_test_file.py")
29-
# with open(empty_file_path, "w") as f:
30-
# f.write("")
31-
# assert count_comment_lines(empty_file_path) == 0
32-
# os.remove(empty_file_path) # Clean up the empty file
26+
def test_count_comment_lines_empty_file():
27+
"""Test count_comment_lines with an empty file."""
28+
empty_file_path = os.path.join(SAMPLE_CODE_DIR, "empty_test_file.py")
29+
with open(empty_file_path, "w") as f:
30+
f.write("")
31+
assert count_comment_lines(empty_file_path) == 0
32+
os.remove(empty_file_path) # Clean up the empty file
3333

34-
# def test_count_comment_lines_no_comments():
35-
# """Test count_comment_lines with a file containing no comments."""
36-
# no_comments_path = os.path.join(SAMPLE_CODE_DIR, "no_comments_test_file.py")
37-
# with open(no_comments_path, "w") as f:
38-
# f.write("print(\"Hello\")\nx = 1")
39-
# assert count_comment_lines(no_comments_path) == 0
40-
# os.remove(no_comments_path) # Clean up
34+
def test_count_comment_lines_no_comments():
35+
"""Test count_comment_lines with a file containing no comments."""
36+
no_comments_path = os.path.join(SAMPLE_CODE_DIR, "no_comments_test_file.py")
37+
with open(no_comments_path, "w") as f:
38+
f.write("print(\"Hello\")\nx = 1")
39+
assert count_comment_lines(no_comments_path) == 0
40+
os.remove(no_comments_path) # Clean up
4141

42-
# def test_count_comment_lines_only_inline():
43-
# """Test count_comment_lines with only inline comments."""
44-
# inline_comments_path = os.path.join(SAMPLE_CODE_DIR, "inline_comments_test_file.py")
45-
# with open(inline_comments_path, "w") as f:
46-
# f.write("x = 1 # inline\ny = 2 # another inline")
47-
# assert count_comment_lines(inline_comments_path) == 0
48-
# os.remove(inline_comments_path) # Clean up
42+
def test_count_comment_lines_only_inline():
43+
"""Test count_comment_lines with only inline comments."""
44+
inline_comments_path = os.path.join(SAMPLE_CODE_DIR, "inline_comments_test_file.py")
45+
with open(inline_comments_path, "w") as f:
46+
f.write("x = 1 # inline\ny = 2 # another inline")
47+
assert count_comment_lines(inline_comments_path) == 0
48+
os.remove(inline_comments_path) # Clean up
4949

5050

0 commit comments

Comments
 (0)