From 5fa5aaa94933352f11bb3482814bf3a0cc9e1764 Mon Sep 17 00:00:00 2001 From: Rory Alexander Date: Fri, 4 Apr 2025 15:38:01 +0100 Subject: [PATCH 1/4] Completed list tasks --- .tasks.txt | 5 + .temp_test.txt | 5 + __pycache__/todo.cpython-312.pyc | Bin 0 -> 2867 bytes .../test_to-do.cpython-312-pytest-7.4.4.pyc | Bin 0 -> 18502 bytes test/test_list.txt | 5 + test/test_to-do.py | 127 ++++++++++++++++++ todo.py | 80 +++++++++++ todo_answers.py | 94 +++++++++++++ 8 files changed, 316 insertions(+) create mode 100644 .tasks.txt create mode 100644 .temp_test.txt create mode 100644 __pycache__/todo.cpython-312.pyc create mode 100644 test/__pycache__/test_to-do.cpython-312-pytest-7.4.4.pyc create mode 100644 test/test_list.txt create mode 100644 test/test_to-do.py create mode 100644 todo.py create mode 100644 todo_answers.py diff --git a/.tasks.txt b/.tasks.txt new file mode 100644 index 0000000..6934359 --- /dev/null +++ b/.tasks.txt @@ -0,0 +1,5 @@ +Item 1 +Item 2 +Item 3 +Item 4 +Item 5 diff --git a/.temp_test.txt b/.temp_test.txt new file mode 100644 index 0000000..6934359 --- /dev/null +++ b/.temp_test.txt @@ -0,0 +1,5 @@ +Item 1 +Item 2 +Item 3 +Item 4 +Item 5 diff --git a/__pycache__/todo.cpython-312.pyc b/__pycache__/todo.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f24222b3976f2999d96788ddcb9c8911b0080b61 GIT binary patch literal 2867 zcma)8&2JmW6`%bgm%Ah_#iB&{ORHFJOe7TS)=mvIDB#!;;(RE99n`R)g4k$Q5*2cn zm>pUoL7_y^qDtT*He5h1j3UZShJ0xMg`SG!VnsH@Y;+LNQ!b4v2QZ*h-kar;u3!Tl zf^WWl^X9#o_kOcqr&0!iGWMSzX2#=${2Mz_k=uc%Ly{ZIT+zQCuXHUz5} z{1x~=se@Q1yfeomi@*{pKTy^X1?4PRlp4~U7WST%4MJ7avewoi5vt*Dt*r?x(vF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CepaBV5 zS`DH%jNS-(d&(^yYpg-2$_N0^uJX{`OYh6v^W%^0+ygzyVRNAoW=|kuH5aVC%vTVx zUV+(|`3fR#f1OVC%L*7uDWXm>Fe<5@USeyh1(w9q?h%x+QdKSXY?OQ#lZU}u*+(=~ z!#)m40kQ`{_9BRHXNC+zWNAO9_TPQ)9o>bvs$62Qqf1~H$$;q`yC1Og(T|cJkX~FCu;f90c7P3z|5{9_i8vA%V;F1HL z=t!No+(>cRfq6VUQD?(=B8O94lP7W@fhX$pa571kgRx_-9QvN}L|si>Hf)V=YT~kC zxa@A?vQfB%3r0O-R66_^2=E2CB1|vx8v*4^PAdnW%NB{UFIgTsTgqrB^?hgaxhVyL zY%xDwn9}zp&lc2)bWXNndUD5Eb*6B-fnaX9Tb-MNKQ;hZEu*PM*uGU=gqJ8{ zHiQC*o--2)6jveuYxv%UD}|P#=8Yx}?@XyitTcmlr;8=Ll1=YD;n+|? zG|6DO$FTk|j)--)+Tawt(@n zNYg)TNT&@koh}sR>AV8*NILzq=}aE~$|0R5eXsz@AbKO{{Rln$hZCZphgx2`lnIhF z>fusX(Q5q_=4OE79=aK8=X!4L3W2wA3)ge&3ATspGBaWxsofCl|CXTlF^#UY`EL~c zrcw&XQ9n^$A~_BIS;Bc`1g&?J-Wj}^1<2uyYU)p}!ZJu0QX zpuL0*$Kc`rE#Pl7jIf;1GTA& 3 + assert score > 5 + assert score > 7 + assert score > 9 + +pytest + + diff --git a/todo.py b/todo.py new file mode 100644 index 0000000..c708511 --- /dev/null +++ b/todo.py @@ -0,0 +1,80 @@ +import argparse +import os + +TASK_FILE = ".tasks.txt" + +def add_task(task): + """Function: add_task + + Input - a task to add to the list + Return - nothing + """ + with open (TASK_FILE, "a", encoding="utf-8") as file: + file.write(task + "\n") + + +def list_tasks(): + """ + Lists the tasks in the provided task list with their index. + + Args: + list_tasks: A list of strings, where each string represents a task. + + Returns: + str: A formatted string containing the numbered tasks, or an empty string if the todo list is empty. + """ + + # read in the file TASK_FILE + with open (TASK_FILE, "r", encoding="utf-8") as file: + tasks = file.readlines() + + output_string = "Your task list:\n" + formatted_tasks = [] + for index, task in enumerate(tasks): + formatted_tasks.append(f"{index + 1}. {task}") + output_string += "".join(formatted_tasks) + print(output_string) + return output_string.rstrip('\n') + + + + + + +def remove_task(index): + + return + +def main(): + parser = argparse.ArgumentParser(description="Command-line Todo List") + parser.add_argument( + "-a", + "--add", + help="Add a new task" + ) + parser.add_argument( + "-l", + "--list", + action="store_true", + help="List all tasks") + parser.add_argument( + "-r", + "--remove", + help="Remove a task by index") + + args = parser.parse_args() + + if args.add: + add_task(args.add) + elif args.list: + tasks = list_tasks() + print(tasks) + elif args.remove: + remove_task(int(args.remove)) + else: + parser.print_help() + + +if __name__ == "__main__": + main() + diff --git a/todo_answers.py b/todo_answers.py new file mode 100644 index 0000000..ec8f4f5 --- /dev/null +++ b/todo_answers.py @@ -0,0 +1,94 @@ +""" +todo.py is a simple to-do list application that +keeps a users to-do list as a text file. + +Users can add, list or remove tasks +""" +import argparse +import os + +TASK_FILE = ".tasks.txt" + +def add_task(task): + """Function: add_task + + Input - a task to add to the list + Return - nothing + """ + with open(TASK_FILE, "a", encoding="utf-8") as file: + file.write(task + "\n") + +def list_tasks(): + """Function: list_tasks + + Input - a task to add to the list + Return - a string of the tasks on the list + """ + + output_string = "" + if os.path.exists(TASK_FILE): + with open(TASK_FILE, "r", encoding="utf-8") as file: + tasks = file.readlines() + for index, task in enumerate(tasks, start=1): + output_string += (f"{index}. {task.strip()}\n") + return output_string.strip() + + + +def remove_task(index): + """Function: remove_task + + Input - a task to add to the list + Return - nothing + """ + + if os.path.exists(TASK_FILE): + with open(TASK_FILE, "r", encoding="utf-8") as file: + tasks = file.readlines() + with open(TASK_FILE, "w", encoding="utf-8") as file: + for i, task in enumerate(tasks, start=1): + if i != index: + file.write(task) + print("Task removed.") + else: + print("No tasks found.") + + +def main(): + """Function: main + + Input - nothing + Return - nothing + """ + + parser = argparse.ArgumentParser(description="Command-line Todo List") + parser.add_argument( + "-a", + "--add", + help="Add a new task" + ) + parser.add_argument( + "-l", + "--list", + action="store_true", + help="List all tasks") + parser.add_argument( + "-r", + "--remove", + help="Remove a task by index") + + args = parser.parse_args() + + if args.add: + add_task(args.add) + elif args.list: + tasks = list_tasks() + print(tasks) + elif args.remove: + remove_task(int(args.remove)) + else: + parser.print_help() + + +if __name__ == "__main__": + main() From 525e9cbe018845ed215c2c900a039826d2a5b76a Mon Sep 17 00:00:00 2001 From: Rory Alexander Date: Fri, 4 Apr 2025 15:55:37 +0100 Subject: [PATCH 2/4] Got the list func working --- python/test/test_to-do.py | 5 ++++- python/todo.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/python/test/test_to-do.py b/python/test/test_to-do.py index 8494337..bed6601 100644 --- a/python/test/test_to-do.py +++ b/python/test/test_to-do.py @@ -15,7 +15,7 @@ class TestTodoList(): def test_list_tasks(self): todo.TASK_FILE = test_file task_list = todo.list_tasks() - expected_list ="1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5" + expected_list ="Your task list:\n1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5" assert task_list == expected_list @@ -122,3 +122,6 @@ def test_lint(self): assert score > 7 assert score > 9 +pytest + + diff --git a/python/todo.py b/python/todo.py index a04234e..c708511 100644 --- a/python/todo.py +++ b/python/todo.py @@ -9,12 +9,40 @@ def add_task(task): Input - a task to add to the list Return - nothing """ + with open (TASK_FILE, "a", encoding="utf-8") as file: + file.write(task + "\n") + def list_tasks(): - return + """ + Lists the tasks in the provided task list with their index. + + Args: + list_tasks: A list of strings, where each string represents a task. + + Returns: + str: A formatted string containing the numbered tasks, or an empty string if the todo list is empty. + """ + + # read in the file TASK_FILE + with open (TASK_FILE, "r", encoding="utf-8") as file: + tasks = file.readlines() + + output_string = "Your task list:\n" + formatted_tasks = [] + for index, task in enumerate(tasks): + formatted_tasks.append(f"{index + 1}. {task}") + output_string += "".join(formatted_tasks) + print(output_string) + return output_string.rstrip('\n') + + + + def remove_task(index): + return def main(): @@ -49,3 +77,4 @@ def main(): if __name__ == "__main__": main() + From a3bdf66d7b951662b0264c3961ede316e1de061a Mon Sep 17 00:00:00 2001 From: Rory Alexander Date: Thu, 24 Apr 2025 17:56:59 +0100 Subject: [PATCH 3/4] 4 succesful tests --- test/test_to-do.py | 36 +++++++++++++++++++----------------- todo.py | 25 ++++++++++++++++++++----- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/test/test_to-do.py b/test/test_to-do.py index bed6601..1c54528 100644 --- a/test/test_to-do.py +++ b/test/test_to-do.py @@ -27,7 +27,7 @@ def test_remove_task(self): todo.remove_task(0) # list should be the same task_list = todo.list_tasks() - expected_list ="1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5" + expected_list ="Your task list:\n1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5" assert task_list == expected_list # should also error todo.remove_task(10) @@ -37,7 +37,7 @@ def test_remove_task(self): # should not error! todo.remove_task(1) task_list = todo.list_tasks() - new_expected = "1. Item 2\n2. Item 3\n3. Item 4\n4. Item 5" + new_expected = "Your task list:\n1. Item 2\n2. Item 3\n3. Item 4\n4. Item 5" # note assert checks from 1 as we remove line 0 assert task_list == new_expected os.remove(temp_list) @@ -50,10 +50,12 @@ def test_add_task(self): todo.add_task("Item 6") task_list = todo.list_tasks() - expected_list ="1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5\n6. Item 6" + expected_list ="Your task list:\n1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5\n6. Item 6" + # add 'Your task list:' to match list_tasks function assert task_list == expected_list os.remove(temp_list) + def test_main(self): temp_list = ".tasks.txt" @@ -61,30 +63,32 @@ def test_main(self): todo.TASK_FILE = temp_list from subprocess import run - result = run(["python3","todo.py","-l"], capture_output=True, check=True) - assert len(result.stdout) == 50 - expected_list ="1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5\n" + result = run(["python","todo.py","-l"], capture_output=True, check=True) + #print(result) + assert len(result.stdout) == 72 + #changed number from 50 to account for extra characters from adding "your task list" and r before every \n + expected_list ="Your task list:\r\n1. Item 1\r\n2. Item 2\r\n3. Item 3\r\n4. Item 4\r\n5. Item 5\r\n" assert result.stdout.decode('UTF-8') == expected_list - from subprocess import run - result = run(["python3","todo.py","-a", "Item 6"], capture_output=True, check=True) + result = run(["python","todo.py","-a", "Item 6"], capture_output=True, check=True) assert len(result.stdout) == 0 from subprocess import run - result = run(["python3","todo.py","-l"], capture_output=True, check=True) - assert len(result.stdout) == 60 - expected_list ="1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5\n6. Item 6\n" + result = run(["python","todo.py","-l"], capture_output=True, check=True) + assert len(result.stdout) == 83 + expected_list ="Your task list:\r\n1. Item 1\r\n2. Item 2\r\n3. Item 3\r\n4. Item 4\r\n5. Item 5\r\n6. Item 6\r\n" assert result.stdout.decode('UTF-8') == expected_list from subprocess import run - result = run(["python3","todo.py","-r","6"], capture_output=True, check=True) + result = run(["python","todo.py","-r","6"], capture_output=True, check=True) assert len(result.stdout) < 40 from subprocess import run - result = run(["python3","todo.py","-l"], capture_output=True, check=True) - assert len(result.stdout) == 50 - expected_list ="1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5\n" + result = run(["python","todo.py","-l"], capture_output=True, check=True) + print(result) + assert len(result.stdout) == 72 + expected_list ="Your task list:\r\n1. Item 1\r\n2. Item 2\r\n3. Item 3\r\n4. Item 4\r\n5. Item 5\r\n" assert result.stdout.decode('UTF-8') == expected_list @@ -122,6 +126,4 @@ def test_lint(self): assert score > 7 assert score > 9 -pytest - diff --git a/todo.py b/todo.py index c708511..c13205e 100644 --- a/todo.py +++ b/todo.py @@ -25,6 +25,7 @@ def list_tasks(): """ # read in the file TASK_FILE + # used Gemini with open (TASK_FILE, "r", encoding="utf-8") as file: tasks = file.readlines() @@ -33,16 +34,30 @@ def list_tasks(): for index, task in enumerate(tasks): formatted_tasks.append(f"{index + 1}. {task}") output_string += "".join(formatted_tasks) - print(output_string) return output_string.rstrip('\n') - - +def remove_task(index): + """Function: remove_task + Input: index - the number of the task to remove from the list + Return: nothing + """ + if os.path.exists(TASK_FILE): + with open(TASK_FILE, "r", encoding="utf-8") as file: + tasks = file.readlines() + if 1 <= index <= len(tasks): + with open(TASK_FILE, "w", encoding="utf-8") as file: + for i, task in enumerate(tasks, start=1): + if i != index: + file.write(task) + print(f"Task at index {index} removed.") + else: + print(f"Invalid task number: {index}. Please enter a number between 1 and {len(tasks)}.") + else: + print("No tasks found.") -def remove_task(index): - + return def main(): From 70281c2163eb700d895e90a7bbda63ddd99e2d75 Mon Sep 17 00:00:00 2001 From: Rory Alexander Date: Sun, 27 Apr 2025 14:01:31 +0100 Subject: [PATCH 4/4] Final commit for Formative --- .tasks.txt | 5 ----- .temp_test.txt | 5 ----- __pycache__/todo.cpython-312.pyc | Bin 2867 -> 4053 bytes .../test_to-do.cpython-312-pytest-7.4.4.pyc | Bin 18502 -> 18567 bytes todo.py | 19 ++++++++---------- 5 files changed, 8 insertions(+), 21 deletions(-) delete mode 100644 .tasks.txt delete mode 100644 .temp_test.txt diff --git a/.tasks.txt b/.tasks.txt deleted file mode 100644 index 6934359..0000000 --- a/.tasks.txt +++ /dev/null @@ -1,5 +0,0 @@ -Item 1 -Item 2 -Item 3 -Item 4 -Item 5 diff --git a/.temp_test.txt b/.temp_test.txt deleted file mode 100644 index 6934359..0000000 --- a/.temp_test.txt +++ /dev/null @@ -1,5 +0,0 @@ -Item 1 -Item 2 -Item 3 -Item 4 -Item 5 diff --git a/__pycache__/todo.cpython-312.pyc b/__pycache__/todo.cpython-312.pyc index f24222b3976f2999d96788ddcb9c8911b0080b61..14f4c2851a76e415c8a5f8b58784055293eda14f 100644 GIT binary patch delta 1903 zcmZ`)T}%{L6ux(Uc4z;f3#=@Na*-dIRMtN%7LBG*|Jt}UiczU$9d-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bE!P3oKhQ>_r;jtGecH~#drc7GVxf@Hj*UoeUFaED+Yi0N#qq11%dgc?A z&BJox96JFY7orQ+u{??UZ~G4%!7)wn0uENT@q+aBu-7XiIF+6!2zG)3j>T4-Drm}8 ztZeC$E=*U0S89goz(;3Fuhn_AWN;TssK`#u$B)2Qi<8;{#g_={6h5$3sp%ViwdvA1 zuXDai-Ux(?Gg#)8;uL$O^Lp`&gT>(H)5&O*ycxnV!pj7MpcClA;zJHCN2e6m*!__S z*Vyg~8*_#G9(osA$doTOD_cgTCU_V&mUD+jaoCjbUh9GqXo>z^NW!Pf&t`Uwdbzo!FYtHJq-Q18L3`#@sK!|M7aQ^Zs}37;TO0TjGh0Tb diff --git a/todo.py b/todo.py index c13205e..47e749c 100644 --- a/todo.py +++ b/todo.py @@ -1,3 +1,4 @@ +""" This module handles command-line argument parsing using argparse.""" import argparse import os @@ -21,27 +22,26 @@ def list_tasks(): list_tasks: A list of strings, where each string represents a task. Returns: - str: A formatted string containing the numbered tasks, or an empty string if the todo list is empty. + str: A formatted string containing numbered tasks, or an empty string + if todo list is empty. """ # read in the file TASK_FILE # used Gemini with open (TASK_FILE, "r", encoding="utf-8") as file: tasks = file.readlines() - output_string = "Your task list:\n" formatted_tasks = [] for index, task in enumerate(tasks): - formatted_tasks.append(f"{index + 1}. {task}") + formatted_tasks.append(f"{index + 1}. {task}") output_string += "".join(formatted_tasks) return output_string.rstrip('\n') - + def remove_task(index): """Function: remove_task - Input: index - the number of the task to remove from the list - Return: nothing + Return: Nothing """ if os.path.exists(TASK_FILE): with open(TASK_FILE, "r", encoding="utf-8") as file: @@ -53,14 +53,12 @@ def remove_task(index): file.write(task) print(f"Task at index {index} removed.") else: - print(f"Invalid task number: {index}. Please enter a number between 1 and {len(tasks)}.") + print(f"Invalid task number: {index}. Please enter number between 1 and {len(tasks)}.") else: print("No tasks found.") - - return - def main(): + """ Main function to execute the program logic.""" parser = argparse.ArgumentParser(description="Command-line Todo List") parser.add_argument( "-a", @@ -92,4 +90,3 @@ def main(): if __name__ == "__main__": main() -