Skip to content

Commit d2f0fa6

Browse files
committed
add Attribute check to count_calls(); fixes #5
1 parent bc36263 commit d2f0fa6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Added
1515

16-
- leaderboard functionality via function attribute (#1)
16+
- leaderboard functionality via test function (#1)
1717
- regex auditing (from `jmu_gradescope_utils`)
1818
- `count_while_loops()` function in audit.py
1919
- `REQUIREMENTS_TXT` configuration option (#2)
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
### Fixed
2525

2626
- allow students to submit any type of file (#4)
27+
- `count_calls()` also counts methods (#5)
2728

2829
### Changed
2930

jmu_pytest_utils/audit.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def count_calls(filename, func_id):
6969
7070
Args:
7171
filename (str): The source file to parse.
72-
func_id (str): Function name (Ex: "print").
72+
func_id (str): Function/method name (Ex: "print").
7373
7474
Returns:
7575
int: Number of times the function is called.
@@ -81,8 +81,12 @@ def count_calls(filename, func_id):
8181
count = 0
8282
for node in ast.walk(tree):
8383
if isinstance(node, ast.Call):
84+
# plain function calls
8485
if isinstance(node.func, ast.Name) and node.func.id == func_id:
8586
count += 1
87+
# method/attribute calls
88+
if isinstance(node.func, ast.Attribute) and node.func.attr == func_id:
89+
count += 1
8690
return count
8791

8892

0 commit comments

Comments
 (0)