Skip to content

add testing for tasks practice #319

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 1 commit into
base: 2025/x
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions tasks/.cs50.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
check50:
files: &check50_files
- !exclude "*"
- !require tasks.py
61 changes: 61 additions & 0 deletions tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import check50
from re import escape

@check50.check()
def exists():
"""tasks.py exists"""
check50.exists("tasks.py")
check50.include("testing.py", "monday.txt")

@check50.check(exists)
def test_correct_input():
"""correctly accepts two command-line inputs"""
check50.run("python3 tasks.py").exit(code=1)

@check50.check(exists)
def test_print_add():
"""correctly prints added task"""
output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David"
check50.run("python3 tasks.py monday.txt").stdin("add Call David", prompt=True).stdout(regex(output), output).kill()

@check50.check(exists)
def test_case_add():
"""disregards the case of add"""
output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David"
check50.run("python3 tasks.py monday.txt").stdin("aDd Call David", prompt=True).stdout(regex(output), output).kill()

@check50.check(exists)
def test_add_txt():
"""test"""
check50.run("python3 testing.py get_level")

@check50.check(exists)
def test_print_remove():
"""correctly prints list after removal"""
output = "1. Rip a Phonebook"
check50.run("python3 tasks.py monday.txt").stdin("remove Attend Lecture", prompt=True).stdout(regex(output), output).kill()

@check50.check(exists)
def test_case_remove():
"""disregards the case of remove"""
output = "1. Rip a Phonebook"
check50.run("python3 tasks.py monday.txt").stdin("rEMoVe Attend Lecture", prompt=True).stdout(regex(output), output).kill()

@check50.check(exists)
def test_invalid_remove():
"""correctly exits when no match to remove"""
check50.run("python3 tasks.py monday.txt").stdin("remove Feed the Cat", prompt=True).exit(code=1)

@check50.check(exists)
def test_just_command():
"""correctly exits when no description"""
check50.run("python3 tasks.py monday.txt").stdin("add", prompt=True).exit(code=1)

@check50.check(exists)
def test_invalid_command():
"""correctly exits when invalid command"""
check50.run("python3 tasks.py monday.txt").stdin("edit Rip a Phonebook", prompt=True).exit(code=1)

def regex(text):
"""match case-sensitively with any characters on either side"""
return rf"^.*{escape(text)}.*$"
2 changes: 2 additions & 0 deletions tasks/monday.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Attend Lecture
Rip a Phonebook
16 changes: 16 additions & 0 deletions tasks/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from tasks import add_task, remove_task, txt_length, update_txt
import sys

def main():

argument = sys.argv[1]
tasks = ['Attend Lecture', 'Rip a Phonebook']
description = sys.argv[3]
filepath = sys.argv[1]

if argument == "add":
tasks.add_task(tasks, description, filepath)
print(tasks.txt_length(filepath))

if __name__ == "__main__":
main()