Repository navigation
Expand file tree
/
Copy pathtest_analyzer.py
More file actions
1148 lines (877 loc) · 26.4 KB
/
Copy pathtest_analyzer.py
File metadata and controls
1148 lines (877 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ast
import json
import os
import sys
from pathlib import Path
import pytest
from analyzer import (
main,
)
from analysis.file_analysis import (
analyze_file,
parse_python_file,
)
from analysis.lines import (
analyze_lines,
)
from analysis.quality import (
analyze_quality,
calculate_health_score,
get_health_rating,
)
from analysis.ast_analysis import (
analyze_ast,
analyze_functions,
analyze_imports,
analyze_control_flow,
analyze_classes,
analyze_operations,
)
from analysis.duplicate_detection import (
detect_duplicates,
)
from analysis.complexity import (
calculate_complexity,
count_function_arguments,
)
from analysis.lines import count_todos_and_fixmes
from reporting.terminal import display_quality_issues_metrics
# Helper function to capture stdout using a temporary file
def capture_output(func, *args, **kwargs):
"""Capture stdout while running a function"""
import tempfile
old_stdout = sys.stdout
temp_file = tempfile.NamedTemporaryFile(mode="w+", delete=False)
sys.stdout = temp_file
try:
func(*args, **kwargs)
temp_file.flush()
with open(temp_file.name, "r") as f:
return f.read()
finally:
sys.stdout = old_stdout
temp_file.close()
Path(temp_file.name).unlink(missing_ok=True)
# ==================== Tests for get_health_rating ====================
def test_get_health_rating():
"""Test health rating categorization"""
assert get_health_rating(100) == "Excellent"
assert get_health_rating(90) == "Excellent"
assert get_health_rating(89) == "Good"
assert get_health_rating(75) == "Good"
assert get_health_rating(74) == "Needs Improvement"
assert get_health_rating(50) == "Needs Improvement"
assert get_health_rating(49) == "Poor"
assert get_health_rating(0) == "Poor"
# ==================== Tests for analyze_lines ====================
def test_analyze_lines_basic():
"""Test basic line analysis"""
lines = [
"def test():",
" # This is a comment",
" print('hello')",
"",
" # TODO: fix this",
" # FIXME: urgent",
" return True",
]
result = analyze_lines(lines)
assert result["blank_lines"] == 1
assert result["comment_lines"] == 3
assert result["code_lines"] == 3
assert result["todos"] == 1
assert result["fixmes"] == 1
def test_analyze_lines_empty():
"""Test empty file analysis"""
lines = []
result = analyze_lines(lines)
assert result["blank_lines"] == 0
assert result["comment_lines"] == 0
assert result["code_lines"] == 0
assert result["todos"] == 0
assert result["fixmes"] == 0
def test_analyze_lines_only_blanks():
"""Test file with only blank lines"""
lines = ["", "", ""]
result = analyze_lines(lines)
assert result["blank_lines"] == 3
assert result["code_lines"] == 0
assert result["comment_lines"] == 0
def test_analyze_lines_todos_and_fixmes_in_comments():
"""Test that TODOs and FIXMEs are counted even in comments"""
lines = [
"# TODO: implement this",
"# FIXME: bug here",
"print('hello') # TODO: remove print",
]
result = analyze_lines(lines)
assert result["todos"] == 2
assert result["fixmes"] == 1
def test_todo_inside_string_not_counted():
lines = [
'message = "TODO: fix this later"',
]
result = analyze_lines(lines)
assert result["todos"] == 0
def test_fixme_inside_string_not_counted():
lines = [
'message = "FIXME: fix this later"',
]
result = analyze_lines(lines)
assert result["fixmes"] == 0
def test_todo_comment_is_counted():
lines = [
"# TODO: refactor this",
]
result = analyze_lines(lines)
assert result["todos"] == 1
def test_fixme_comment_is_counted():
lines = [
"# FIXME: handle this edge case",
]
result = analyze_lines(lines)
assert result["fixmes"] == 1
def test_count_todos_and_fixmes():
lines = [
"# TODO: refactor this\n",
'message = "TODO: not a comment"\n',
"# FIXME: handle this\n",
'message = "FIXME: not a comment"\n',
]
todos, fixmes = count_todos_and_fixmes(lines)
assert todos == 1
assert fixmes == 1
def test_todo_and_fixme_same_comment():
lines = [
"# TODO: FIXME: investigate this",
]
result = analyze_lines(lines)
assert result["todos"] == 1
assert result["fixmes"] == 1
# ==================== Tests for calculate_complexity ====================
def test_calculate_complexity_simple_function():
"""Test complexity of a simple function"""
code = """
def simple():
print('hello')
return True
"""
tree = ast.parse(code)
function = tree.body[0]
assert calculate_complexity(function) == 1
def test_calculate_complexity_with_if_statements():
"""Test complexity with if statements including elif"""
code = """
def with_if(x):
if x > 0:
print('positive')
elif x < 0:
print('negative')
else:
print('zero')
return x
"""
tree = ast.parse(code)
function = tree.body[0]
assert calculate_complexity(function) == 3
def test_calculate_complexity_elif():
code = """
def example(value):
if value == 1:
pass
elif value == 2:
pass
elif value == 3:
pass
"""
tree = ast.parse(code)
function = tree.body[0]
assert calculate_complexity(function) == 4
def test_calculate_complexity_with_loops():
"""Test complexity with loops"""
code = """
def with_loops(items):
for item in items:
print(item)
while True:
break
return True
"""
tree = ast.parse(code)
function = tree.body[0]
assert calculate_complexity(function) == 3
def test_calculate_complexity_with_bool_ops():
"""Test complexity with boolean operations"""
code = """
def with_bool(x, y, z):
if x and y and z:
return True
return False
"""
tree = ast.parse(code)
function = tree.body[0]
assert calculate_complexity(function) == 4
def test_calculate_complexity_with_try_except():
"""Test complexity with try/except"""
code = """
def with_try():
try:
print('try')
except Exception:
print('except')
return True
"""
tree = ast.parse(code)
function = tree.body[0]
assert calculate_complexity(function) == 2
def test_calculate_complexity_nested_function():
code = """
def outer():
def inner():
if condition:
pass
return inner
"""
tree = ast.parse(code)
outer_function = tree.body[0]
assert calculate_complexity(outer_function) == 1
def test_calculate_complexity_nested_async_function():
code = """
def outer():
async def inner():
if condition:
pass
return inner
"""
tree = ast.parse(code)
outer_function = tree.body[0]
assert calculate_complexity(outer_function) == 1
# ==================== Tests for analyze_functions ====================
def test_analyze_functions_basic():
"""Test function analysis"""
code = """
def func1():
return True
def func2(x, y):
if x > y:
return x
return y
def func3(a, b, c, d, e):
return a + b + c + d + e
"""
tree = ast.parse(code)
result = analyze_functions(tree)
assert result["functions"] == 3
assert len(result["function_details"]) == 3
assert result["function_details"][0]["name"] == "func1"
assert result["function_details"][0]["arguments"] == 0
assert result["function_details"][0]["complexity"] == 1
assert result["function_details"][0]["start_line"] == 2
def test_analyze_functions_nested():
"""Test function analysis with nested functions"""
code = """
def outer():
def inner():
return True
return inner()
"""
tree = ast.parse(code)
result = analyze_functions(tree)
assert result["functions"] == 2
def test_analyze_functions_no_functions():
"""Test file with no functions"""
code = """
print('hello')
x = 5
"""
tree = ast.parse(code)
result = analyze_functions(tree)
assert result["functions"] == 0
assert result["function_details"] == []
def test_count_function_arguments():
code = """
def example(a, b=10, *args, c=20, **kwargs):
pass
"""
tree = ast.parse(code)
function = tree.body[0]
assert count_function_arguments(function) == 5
def test_analyze_functions_async():
code = """
async def fetch_data(url):
return url
"""
tree = ast.parse(code)
result = analyze_functions(tree)
assert result["functions"] == 1
# ==================== Tests for analyze_imports ====================
def test_analyze_imports_basic():
"""Test basic import analysis"""
code = """
import os
import sys
from pathlib import Path
from datetime import datetime, timedelta
"""
tree = ast.parse(code)
result = analyze_imports(tree)
assert result["imports"] == 2
assert result["import_from"] == 2
def test_analyze_imports_none():
"""Test file with no imports"""
code = """
def test():
return True
"""
tree = ast.parse(code)
result = analyze_imports(tree)
assert result["imports"] == 0
assert result["import_from"] == 0
# ==================== Tests for analyze_control_flow ====================
def test_analyze_control_flow_basic():
"""Test control flow analysis"""
code = """
if x > 0:
print('positive')
for i in range(10):
print(i)
while x < 10:
x += 1
try:
risky_operation()
except:
handle_error()
"""
tree = ast.parse(code)
result = analyze_control_flow(tree)
assert result["if_statements"] == 1
assert result["for_loops"] == 1
assert result["while_loops"] == 1
assert result["try_blocks"] == 1
def test_analyze_control_flow_nested():
"""Test nested control flow structures"""
code = """
for i in range(10):
if i % 2 == 0:
print(i)
while i < 5:
i += 1
"""
tree = ast.parse(code)
result = analyze_control_flow(tree)
assert result["for_loops"] == 1
assert result["if_statements"] == 1
assert result["while_loops"] == 1
# ==================== Tests for analyze_classes ====================
def test_analyze_classes_basic():
"""Test class analysis"""
code = """
class MyClass:
def method1(self):
return True
class AnotherClass:
pass
"""
tree = ast.parse(code)
result = analyze_classes(tree)
assert result["classes"] == 2
def test_analyze_classes_nested():
"""Test nested classes"""
code = """
class Outer:
class Inner:
pass
"""
tree = ast.parse(code)
result = analyze_classes(tree)
assert result["classes"] == 2
# ==================== Tests for analyze_operations ====================
def test_analyze_operations_basic():
"""Test operation analysis"""
code = """
def test():
result = sum([1, 2, 3])
return result
def divide(a, b):
if b == 0:
raise ValueError("Division by zero")
return a / b
def debug():
assert x > 0, "x must be positive"
"""
tree = ast.parse(code)
result = analyze_operations(tree)
assert result["function_calls"] == 2 # sum() and ValueError()
assert result["return_statements"] == 2
assert result["exceptions_raised"] == 1
assert result["assertions"] == 1
# ==================== Tests for analyze_quality ====================
def test_analyze_quality_no_issues():
"""Test quality analysis with no issues"""
function_details = [
{
"name": "good_func",
"lines": 5,
"arguments": 2,
"complexity": 3
}
]
issues = analyze_quality(function_details)
assert len(issues) == 0
def test_analyze_quality_long_function():
"""Test long function detection"""
function_details = [
{
"name": "long_func",
"start_line": 10,
"lines": 35,
"arguments": 2,
"complexity": 3
}
]
issues = analyze_quality(function_details)
assert len(issues) == 1
assert "long function" in issues[0]
assert "starts at Line 10" in issues[0]
def test_analyze_quality_too_many_arguments():
"""Test too many arguments detection"""
function_details = [
{
"name": "args_func",
"start_line": 10,
"lines": 5,
"arguments": 6,
"complexity": 3,
}
]
issues = analyze_quality(function_details)
assert len(issues) == 1
assert "too many arguments" in issues[0]
def test_analyze_quality_high_complexity():
"""Test high complexity detection"""
function_details = [
{
"name": "complex_func",
"start_line": 15,
"lines": 5,
"arguments": 2,
"complexity": 12,
}
]
issues = analyze_quality(function_details)
assert len(issues) == 1
assert "high complexity" in issues[0]
def test_analyze_quality_multiple_issues():
"""Test detection of multiple issues in one function"""
function_details = [
{
"name": "bad_func",
"start_line": 20,
"lines": 35,
"arguments": 7,
"complexity": 15,
}
]
issues = analyze_quality(function_details)
assert len(issues) == 3
def test_display_quality_issues_with_todos_and_fixmes():
"""Test quality report displays TODO and FIXME warnings"""
metrics = {
"todos": 2,
"fixmes": 1,
"issues": [],
}
output = capture_output(display_quality_issues_metrics, metrics)
assert "TODOs: 2" in output
assert "FIXMEs: 1" in output
assert "WARNING: 2 TODO(s) found" in output
assert "WARNING: 1 FIXME(s) found" in output
def test_display_quality_issues_no_issues():
"""Test quality report when no issues exist"""
metrics = {
"todos": 0,
"fixmes": 0,
"issues": [],
}
output = capture_output(display_quality_issues_metrics, metrics)
assert "TODOs: 0" in output
assert "FIXMEs: 0" in output
assert "No issues detected" in output
# ==================== Tests for calculate_health_score ====================
def test_calculate_health_score_perfect():
"""Test health score for perfect code"""
function_details = [{"name": "good", "lines": 5, "arguments": 2, "complexity": 3}]
score = calculate_health_score(function_details, 0, 0)
assert score == 100
def test_calculate_health_score_with_issues():
"""Test health score deduction for various issues"""
function_details = [{"name": "bad", "lines": 35, "arguments": 6, "complexity": 12}]
score = calculate_health_score(function_details, 2, 1)
assert score == 84
def test_calculate_health_score_multiple_functions():
"""Test health score with multiple functions"""
function_details = [
{"name": "good", "lines": 5, "arguments": 2, "complexity": 3},
{"name": "bad", "lines": 35, "arguments": 6, "complexity": 12},
]
score = calculate_health_score(function_details, 1, 0)
assert score == 86
def test_calculate_health_score_minimum():
"""Test health score doesn't go below 0"""
function_details = [
{"name": "very_bad", "lines": 100, "arguments": 20, "complexity": 50}
]
score = calculate_health_score(function_details, 100, 100)
assert score == 0
# ==================== Tests for parse_python_file ====================
def test_parse_python_file_valid():
"""Test parsing valid Python code"""
source = """
def test():
return True
"""
result = parse_python_file(source, Path("test.py"))
assert result is not None
assert isinstance(result, ast.Module)
def test_parse_python_file_invalid():
"""Test parsing invalid Python code"""
source = """
def test()
return True
"""
old_stdout = sys.stdout
temp_file = Path("temp_output.txt")
sys.stdout = open(temp_file, 'w')
try:
result = parse_python_file(source, Path("test.py"))
sys.stdout.flush()
with open(temp_file, 'r') as f:
output = f.read()
finally:
sys.stdout = old_stdout
temp_file.unlink(missing_ok=True)
assert result is None
assert "Syntax error" in output
# ==================== Tests for analyze_file ====================
def test_analyze_file_valid(tmp_path):
"""Test file analysis with valid Python file"""
test_file = tmp_path / "test.py"
test_file.write_text("""import os
def hello(name):
# Greet the user
print(f"Hello, {name}!")
return True
class Greeter:
def greet(self):
return hello("World")
# TODO: Add more features
""")
result = analyze_file(test_file)
assert result is not None
assert result["file"].name == "test.py"
assert result["functions"] == 2
assert result["classes"] == 1
assert result["imports"] == 1
assert result["todos"] == 1
def test_analyze_file_syntax_error(tmp_path):
"""Test file analysis with syntax error"""
test_file = tmp_path / "syntax_error.py"
test_file.write_text("""def test()
return True
""")
old_stdout = sys.stdout
temp_file = Path("temp_output.txt")
sys.stdout = open(temp_file, 'w')
try:
result = analyze_file(test_file)
sys.stdout.flush()
with open(temp_file, 'r') as f:
output = f.read()
finally:
sys.stdout = old_stdout
temp_file.unlink(missing_ok=True)
assert result is None
assert "Syntax error" in output
# ==================== Tests for main function ====================
def test_main_no_arguments():
"""Test main with no arguments"""
original_argv = sys.argv.copy()
sys.argv = ["analyzer.py"]
try:
with pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 2
finally:
sys.argv = original_argv
def test_main_invalid_directory():
"""Test main with invalid directory"""
original_argv = sys.argv.copy()
sys.argv = ["analyzer.py", "/invalid/path"]
original_is_dir = Path.is_dir
try:
Path.is_dir = lambda self: False
old_stdout = sys.stdout
temp_file = Path("temp_output.txt")
sys.stdout = open(temp_file, 'w')
try:
main()
sys.stdout.flush()
with open(temp_file, 'r') as f:
output = f.read()
finally:
sys.stdout = old_stdout
temp_file.unlink(missing_ok=True)
assert "This is not a valid directory" in output
finally:
Path.is_dir = original_is_dir
sys.argv = original_argv
def test_main_valid_directory(tmp_path):
"""Test main with valid directory"""
test_file = tmp_path / "test.py"
test_file.write_text("""def test():
return True
""")
original_argv = sys.argv.copy()
sys.argv = ["analyzer.py", str(tmp_path)]
try:
old_stdout = sys.stdout
temp_file = Path("temp_output.txt")
sys.stdout = open(temp_file, 'w')
try:
main()
sys.stdout.flush()
with open(temp_file, 'r') as f:
output = f.read()
finally:
sys.stdout = old_stdout
temp_file.unlink(missing_ok=True)
assert "Python files: 1" in output
assert "CODEBASE HEALTH REPORT" in output
finally:
sys.argv = original_argv
def test_main_json_output(tmp_path):
"""Test main with JSON output enabled"""
test_file = tmp_path / "test.py"
test_file.write_text(
"""def test():
return True
"""
)
output_file = tmp_path / "codebase_report.json"
original_argv = sys.argv.copy()
original_cwd = Path.cwd()
sys.argv = ["analyzer.py", str(tmp_path), "--json"]
try:
# Change to temp directory
os.chdir(tmp_path)
main()
assert output_file.exists()
with open(output_file, encoding="utf-8") as f:
report = json.load(f)
assert "summary" in report
assert "files" in report
assert report["summary"]["python_files"] == 1
assert report["files"][0]["file"] == "test.py"
finally:
sys.argv = original_argv
os.chdir(original_cwd)
def test_main_json_duplicate_output(tmp_path):
"""Test that duplicate functions are included in JSON output"""
first = tmp_path / "first.py"
second = tmp_path / "second.py"
first.write_text(
"def add(a, b):\n"
" return a + b\n"
)
second.write_text(
"def calculate(x, y):\n"
" return x + y\n"
)
output_file = tmp_path / "codebase_report.json"
original_argv = sys.argv.copy()
original_cwd = Path.cwd()
sys.argv = ["analyzer.py", str(tmp_path), "--json"]
try:
os.chdir(tmp_path)
main()
assert output_file.exists()
with open(output_file, encoding="utf-8") as f:
report = json.load(f)
assert "duplicates" in report
assert len(report["duplicates"]) == 1
duplicate_functions = report["duplicates"][0]["functions"]
assert len(duplicate_functions) == 2
assert duplicate_functions[0]["file"] == "first.py"
assert duplicate_functions[0]["name"] == "add"
assert duplicate_functions[0]["start_line"] == 1
assert duplicate_functions[1]["file"] == "second.py"
assert duplicate_functions[1]["name"] == "calculate"
assert duplicate_functions[1]["start_line"] == 1
finally:
sys.argv = original_argv
os.chdir(original_cwd)
def test_main_json_custom_output(tmp_path):
"""Test main with a custom JSON output filename"""
test_file = tmp_path / "test.py"
test_file.write_text(
"""def test():
return True
"""
)
output_file = tmp_path / "custom_report.json"
original_argv = sys.argv.copy()
original_cwd = Path.cwd()
sys.argv = [
"analyzer.py",
str(tmp_path),
"--json",
"--output",
str(output_file),
]
try:
main()
assert output_file.exists()
with open(output_file, encoding="utf-8") as f:
report = json.load(f)
assert "summary" in report
assert "files" in report
assert report["summary"]["python_files"] == 1
assert report["files"][0]["file"] == "test.py"
finally:
sys.argv = original_argv
os.chdir(original_cwd)
# ==================== Integration Tests ====================
def test_full_analysis_flow(tmp_path):
"""Integration test with real file"""
test_file = tmp_path / "test.py"
test_file.write_text("""import sys
def calculate_average(numbers):
# Calculate average of numbers
if not numbers:
return 0
total = sum(numbers)
return total / len(numbers)
def complex_function(a, b, c, d, e, f):
# This function has too many arguments
if a > 0:
if b > 0:
if c > 0:
return a + b + c + d + e + f
return 0
# TODO: Add error handling
# FIXME: Performance issue
""")
with open(test_file, "r") as f:
lines = f.readlines()