Skip to content

Commit

Permalink
v 0.0.41 add slack_add
Browse files Browse the repository at this point in the history
  • Loading branch information
Yer1k committed Aug 9, 2024
1 parent 67aae93 commit ea69682
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="6" time="0.090" timestamp="2024-08-09T17:54:22.016303-04:00" hostname="Dingkuns-MBP.attlocal.net"><testcase classname="tests.test_extract_countries" name="test_get_contents_of_file" time="0.004" /><testcase classname="tests.test_extract_countries" name="test_get_country_dict" time="0.000" /><testcase classname="tests.test_extract_countries" name="test_print_results" time="0.001" /><testcase classname="tests.test_shopping_list" name="test_change_shopping_list" time="0.001" /><testcase classname="tests.test_slack_add" name="test_add_two_numbers" time="0.001" /><testcase classname="tests.test_the_meaning_of_life" name="test_the_meaning_of_life" time="0.001" /></testsuite></testsuites>
28 changes: 27 additions & 1 deletion python_practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,30 @@
countries = get_country_dict(country_list)
print_results(continent_name, countries)
```
![Extract countries output](./screenshots/extract_countries_output.png)
![Extract countries output](./screenshots/extract_countries_output.png)


1. Simple sum of two numbers that input from the user
```python
"""Module to add two numbers that input from the user, and print the sum of them."""


def add_two_numbers() -> None:
"""
Function to add two numbers that input from the user,
and print the sum of them.
"""
try:
number1 = int(input("Enter the first number you want to add:\n"))
number2 = int(input("Enter the second number you want to add:\n"))
except ValueError:
print("Invalid input. Please enter valid integers.")
exit(1)
nums_sum = number1 + number2
print(f"The sum of {number1} and {number2} is {nums_sum}.")


if __name__ == "__main__":
add_two_numbers()
```
![Simple sum output](./screenshots/slack_add_output.png)
Binary file added screenshots/slack_add_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/slack_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Module to add two numbers that input from the user, and print the sum of them."""


def add_two_numbers() -> None:
"""
Function to add two numbers that input from the user,
and print the sum of them.
"""
try:
number1 = int(input("Enter the first number you want to add:\n"))
number2 = int(input("Enter the second number you want to add:\n"))
except ValueError:
print("Invalid input. Please enter valid integers.")
exit(1)
nums_sum = number1 + number2
print(f"The sum of {number1} and {number2} is {nums_sum}.")


if __name__ == "__main__":
add_two_numbers()
19 changes: 19 additions & 0 deletions tests/test_slack_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Module to test the add_two_numbers function from slack_add.py."""

from unittest.mock import patch
from slack_add import add_two_numbers # type: ignore


def test_add_two_numbers() -> None:
"""
Test that the function add_two_numbers() prints the correct sum.
"""
with patch("builtins.input", side_effect=[2, 3]), patch(
"builtins.print"
) as mocked_print:
add_two_numbers()

expected_output = "The sum of 2 and 3 is 5."
actual_output = mocked_print.call_args_list[0][0][0]

assert actual_output == expected_output

0 comments on commit ea69682

Please sign in to comment.