Skip to content

Patch jar check #337

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

Open
wants to merge 3 commits into
base: 2022/python
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions jar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,28 @@ def test_number_functions():
raise check50.Failure(
"test_jar.py does not contain at least four valid functions"
)


@check50.check(test_student_file_passes)
def test_named_functions():
"""test_jar.py defines test_init, test_str, test_deposit, and test_withdraw"""
with open("test_jar.py") as t:
contents = t.read()

funcs = ["test_init", "test_str", "test_deposit", "test_withdraw"]
for func in funcs:
matches = re.search(rf"def\s+{func}\s*\(", contents)
if not matches:
raise check50.Failure(f"{func} not found in test_jar.py")


@check50.check(test_student_file_passes)
def test_valid_testing():
"""test_jar.py contains implemented functions"""

# https://stackoverflow.com/questions/845058/how-to-get-the-line-count-of-a-large-file-cheaply-in-python
with open("test_jar.py", "rb") as t:
num_lines = sum(1 for _ in t)

if num_lines < 20:
raise check50.Failure("test_jar.py functions not implemented")