From 1b26bca2be6136fae4e7ffa5b11bd53d13addac5 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 5 Feb 2024 10:58:23 +0000 Subject: [PATCH] Paired Challenge Exercise: design single function program --- Pipfile | 12 ++++++++ Pipfile.lock | 54 +++++++++++++++++++++++++++++++++++ lib/__init__.py | 0 lib/todo_list.py | 9 ++++++ tests/__init__.py | 0 tests/test_todo_list.py | 63 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 138 insertions(+) create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100644 lib/__init__.py create mode 100644 lib/todo_list.py create mode 100644 tests/__init__.py create mode 100644 tests/test_todo_list.py diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..d26c9f0 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +pytest = "*" + +[dev-packages] + +[requires] +python_version = "3.11" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..e4c5e9f --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,54 @@ +{ + "_meta": { + "hash": { + "sha256": "922e82e69ac92d524e9aec65cbead9fdef4cdb3fcff8f459d8998bfd7bd6a67f" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.11" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "iniconfig": { + "hashes": [ + "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", + "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374" + ], + "markers": "python_version >= '3.7'", + "version": "==2.0.0" + }, + "packaging": { + "hashes": [ + "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5", + "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7" + ], + "markers": "python_version >= '3.7'", + "version": "==23.2" + }, + "pluggy": { + "hashes": [ + "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981", + "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be" + ], + "markers": "python_version >= '3.8'", + "version": "==1.4.0" + }, + "pytest": { + "hashes": [ + "sha256:249b1b0864530ba251b7438274c4d251c58d868edaaec8762893ad4a0d71c36c", + "sha256:50fb9cbe836c3f20f0dfa99c565201fb75dc54c8d76373cd1bde06b06657bdb6" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==8.0.0" + } + }, + "develop": {} +} diff --git a/lib/__init__.py b/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/todo_list.py b/lib/todo_list.py new file mode 100644 index 0000000..ca2b93e --- /dev/null +++ b/lib/todo_list.py @@ -0,0 +1,9 @@ +# As a user +# So that I can keep track of my tasks +# I want to check if a text includes the string `#TODO`. + +def check_todo(text): + if '#TODO' in text.upper(): + return text + else: + raise Exception('No #TODO tasks') \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_todo_list.py b/tests/test_todo_list.py new file mode 100644 index 0000000..8dfec2a --- /dev/null +++ b/tests/test_todo_list.py @@ -0,0 +1,63 @@ +# As a user +# So that I can keep track of my tasks +# I want to check if a text includes the string `#TODO`. + +''' +check + +def check_todo(text): + param = (text) + text: string containing multiple things including ideally '#TODO' + + return: + string if it contains '#TODO' + + side effects: + if there isn't any '#TODO' it would return error saying there's no tasks +''' +pass + + +from lib.todo_list import check_todo +import pytest + + +''' +test to see if the text has no content +''' + +def test_check_no_content(): + + with pytest.raises(Exception) as err: + outcome = check_todo('') + error = str(err.value) + assert error == 'No #TODO tasks' + + +''' +check if the text contains '#TODO' +''' + +def test_check_todo(): + tasks = check_todo('testing to see if #TODO is detected') + assert tasks == 'testing to see if #TODO is detected' + +''' +check for the absence of #TODO +''' + +def test_check_lack_of_todo(): + + with pytest.raises(Exception) as err: + no_tasks = check_todo('testing to see if this works') + error_msg = str(err.value) + assert error_msg == 'No #TODO tasks' + + +''' +check for #TODO but not necesarily in capitals +''' + +def test_todos_in_lowerc(): + todos = check_todo('testing to see if #toDo works') + assert todos == 'testing to see if #toDo works' \ No newline at end of file