{"id":22121435,"url":"https://github.com/ericsalesdeandrade/number-logic","last_synced_at":"2025-07-25T13:32:01.797Z","repository":{"id":40418213,"uuid":"436275938","full_name":"ericsalesdeandrade/number-logic","owner":"ericsalesdeandrade","description":"Simple example of Unit Testing with PyTest","archived":false,"fork":false,"pushed_at":"2022-10-07T21:02:02.000Z","size":29,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-03-10T03:56:55.424Z","etag":null,"topics":["pytest","python","tdd-python","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericsalesdeandrade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-08T14:24:44.000Z","updated_at":"2022-10-02T22:14:20.000Z","dependencies_parsed_at":"2023-01-19T14:32:37.959Z","dependency_job_id":null,"html_url":"https://github.com/ericsalesdeandrade/number-logic","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsalesdeandrade%2Fnumber-logic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsalesdeandrade%2Fnumber-logic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsalesdeandrade%2Fnumber-logic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsalesdeandrade%2Fnumber-logic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericsalesdeandrade","download_url":"https://codeload.github.com/ericsalesdeandrade/number-logic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227581751,"owners_count":17789308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytest","python","tdd-python","unit-testing"],"created_at":"2024-12-01T14:40:02.921Z","updated_at":"2024-12-01T14:40:03.483Z","avatar_url":"https://github.com/ericsalesdeandrade.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Number Logic and Unit Testing with PyTest\nby Eric Sales De Andrade (9 May 2022)\n\nThis is an exercise to find 3 numbers in a list whose sum totals a pre-defined value.\n\nThe solution is written in Python 3.8.5 and tested using the `pytest` module. Below are instructions how to setup your environment in the `How To Run` section. \n\n## Repo \nThe Repo contains\n1. Python Module `number_logic` containing a script `number_logic.py` with the core logic with clear explanation of each function.\n2. Input files containing data in the `number-logic/number_logic/src/input` folder. \n3. Unit tests (functionality and exception/error handling checks) under the `tests` folder.\n\n## How To Run\n###---------------------------------------------\n### Step 1 - Prepare your local environment\n\n#### Install Python and Virtual Environment\nAs a first step you'll need to prepare a Python environment. \n\nMac OS X comes pre installed with Python 2.7, but you'll need to upgrade to `Python 3.8.5`\n\nYou can do this with Anaconda (useful for creating a virtual environment) or just install it directly from the web. This link may be useful - https://python.land/installing-python\n\nFollow these instructions for creating a Virtual Environment with Anaconda - https://www.geeksforgeeks.org/set-up-virtual-environment-for-python-using-anaconda/\n\n#### Install Requirements\nThe code uses the `pytest` module so you'll need to install it via pip. To install pip kindly follow the instructions here - https://www.makeuseof.com/tag/install-pip-for-python/\n\nOnce you've installed python and pip please navigate to the Root Directory `Wayflyer_ESDA` and run the below command\n```\npip install -r requirements.txt\n```\n\n###---------------------------------------------\n\n### Step 2 - Run Module `number_logic`\nFrom the Root Directory run\n```\npython number_logic\n```\n\nYou should get a similar response as below\n```\nNumber Class Initialised!\nReading Input File from /Users/ericsda/PycharmProjects/Wayflyer_ESDA/num_logic/src/input/input1_short_version.txt\nValid File found\nThe 3 numbers that sum up to 2020 are [979, 366, 675]\nThe multiplication of the 3 numbers is 241861950\n241861950\n```\n\nNow lets run the Unit Test\n###---------------------------------------------\n\n### Step 3 - Run Unit Tests\n```\npytest ./tests/unit/test_number_logic.py -v -s\n```\n\nIf the tests pass, you should get a response\n```\n============================================================================================ test session starts ============================================================================================\nplatform darwin -- Python 3.8.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /usr/local/anaconda3/envs/eric_dev/bin/python\ncachedir: .pytest_cache\nrootdir: /Users/ericsda/PycharmProjects/Wayflyer_ESDA\ncollected 7 items                                                                                                                                                                                           \n\ntests/test_number_logic.py::test_read_input_file PASSED                                                                                                                                               [ 14%]\ntests/test_number_logic.py::test_read_input_file_exception PASSED                                                                                                                                     [ 28%]\ntests/test_number_logic.py::test_convert_str_int PASSED                                                                                                                                               [ 42%]\ntests/test_number_logic.py::test_convert_str_int_exception PASSED                                                                                                                                     [ 57%]\ntests/test_number_logic.py::test_check_sum PASSED                                                                                                                                                     [ 71%]\ntests/test_number_logic.py::test_multiply_values PASSED                                                                                                                                               [ 85%]\ntests/test_number_logic.py::test_multiply_values_exception PASSED                                                                                                                                     [100%]\n\n============================================================================================= 7 passed in 0.02s =============================================================================================\n```\n###-----------------------------------------------------------------------------------------\n\n### Congratulations you've run and tested the code successfully\n###-----------------------------------------------------------------------------------------\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericsalesdeandrade%2Fnumber-logic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericsalesdeandrade%2Fnumber-logic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericsalesdeandrade%2Fnumber-logic/lists"}