-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache removed and filelist unit test #32
Changes from 1 commit
0bf4c0d
c20e9b1
a79620f
9daab7a
6230ddb
c97b900
c591b8d
092c786
75d2919
75c1604
5c81e0a
9c41ce0
89894d2
6350c2c
0780d87
a82ac2a
42335a9
82c1c70
30cbe08
7157e9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
modernmetric.db | ||
|
||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import os | ||
import json | ||
from modernmetric.fp import file_process | ||
from modernmetric.cls.modules import ( | ||
get_modules_metrics, | ||
get_modules_calculated | ||
) | ||
from pathlib import Path | ||
from modernmetric.__main__ import main as modernmetric | ||
|
||
|
||
class MockArgs: | ||
|
@@ -124,6 +126,28 @@ def test_scan_self(): | |
f"Aggregate {metric} should equal sum of individual values" | ||
|
||
|
||
def test_filelist_scan(): | ||
curr_dir = os.path.dirname(os.path.abspath(__file__)) | ||
project_root = os.path.dirname(curr_dir) | ||
stats_input_file = os.path.join( | ||
project_root, 'testfiles', 'samplefilelist.json' | ||
) | ||
stats_output_file = os.path.join(curr_dir, "test.stats.json") | ||
custom_args = [ | ||
f"--file={stats_input_file}", | ||
f"--output={stats_output_file}" | ||
] | ||
modernmetric(custom_args=custom_args, license_identifier='unit_test') | ||
with open(stats_output_file, 'r') as f: | ||
stats = json.load(f) | ||
files = stats['files'] | ||
assert files is not None | ||
assert files["../testfiles/test.c"]["loc"] == 25 | ||
assert files["../testfiles/test.c"]["cyclomatic_complexity"] == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Test assertions could be more specific and descriptive Consider using more specific assertions with meaningful error messages. For example: Suggested implementation: files = stats['files']
assert files is not None, "Files dictionary should not be None"
assert len(files) == 1, "Expected exactly 1 file in analysis"
test_file = files["../testfiles/test.c"]
assert test_file is not None, "Test file '../testfiles/test.c' should be present in results"
assert test_file["loc"] == 25, "Test file should have exactly 25 lines of code"
# TODO: Verify if cyclomatic complexity of 0 is correct
assert test_file["cyclomatic_complexity"] >= 1, "Cyclomatic complexity should be at least 1 for any non-empty file"
assert stats["overall"]["loc"] == 178, "Overall LOC count should be 178" Note: I've added a comment about cyclomatic complexity and changed the assertion to expect at least 1, since a value of 0 is suspicious for any non-empty file. The developer should:
|
||
assert stats["overall"]["loc"] == 178 | ||
os.remove(stats_output_file) | ||
|
||
|
||
def main(): | ||
"""Run the self-scan test""" | ||
test_scan_self() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Test should verify file list processing functionality more thoroughly
While the test checks basic file metrics, it should also verify: 1) handling of invalid file paths in the JSON, 2) empty file lists, 3) proper error handling for missing or malformed JSON files, and 4) relative/absolute path handling.
Suggested implementation:
You'll need to:
import pytest
at the top of the file if not already presenttmp_path
fixture (most recent pytest versions do)