-
Notifications
You must be signed in to change notification settings - Fork 0
Homework4 #8
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
base: master
Are you sure you want to change the base?
Homework4 #8
Conversation
| Read the first line of the file. | ||
| If first line is a number return true if number in an interval [1, 3)* | ||
| and false otherwise. | ||
| In case of any error, a ValueError should be thrown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about errors?
| Test should use Mock instead of real network interactions. | ||
|
|
||
| You can use urlopen* or any other network libraries. | ||
| In case of any network error raise ValueError("Unreachable {url}). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors?
homework4/task03.py
Outdated
|
|
||
| def my_precious_logger(text: str): | ||
|
|
||
| if (text[:5]) != 'error': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take a look at default string's methods in python
homework4/task01.py
Outdated
| if line.replace('.', '', 1).isdigit() \ | ||
| and not 1.0 <= float(line) < 3.0: | ||
| return True | ||
| else: | ||
| return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be written in one row
|
|
||
| from homework4.task01 import read_magic_number | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is tempfile library for that tasks
tests/homework4/test_task01.py
Outdated
| file = open(file_path, "w") | ||
| file.write("5") | ||
| file.close() | ||
| assert read_magic_number(file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess result should be False.. something wrong in ur function
tests/homework4/test_task01.py
Outdated
| abs_path = os.path.abspath(os.path.join(__file__, "../../..")) | ||
| file_path = os.path.join(abs_path, repository, filename) | ||
| file = open(file_path, "w") | ||
| file.write(str(randrange(1, 3))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sometimes ur func will return False, sometimes True
tests/homework4/test_task03.py
Outdated
|
|
||
|
|
||
| def test_basic_functional(): | ||
| assert my_precious_logger('hey') == sys.stderr.write("hey") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"hey" should be written into stdout... use capsys for test stdouterr
| from homework4.task04 import fizzbuzz | ||
|
|
||
|
|
||
| def test_fizzbuzz_doctest(): | ||
| """ | ||
| given n, return list | ||
| :param n: int | ||
| :return: list | ||
|
|
||
| >>> fizzbuzz(5) | ||
| ['1', '2', 'fizz', '4', 'buzz'] | ||
|
|
||
| >>> fizzbuzz(10) | ||
| ['1', '2', 'fizz', '4', 'buzz', 'fizz', '7', '8', 'fizz', 'buzz'] | ||
| """ | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import doctest | ||
|
|
||
| doctest.testmod() | ||
|
|
||
|
|
||
| def test_fizzbuzz_pytest(): | ||
| assert fizzbuzz(5) == ["1", "2", "fizz", "4", "buzz"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doctest should be written in main function.. take a look at pytest's argument to see how to run doctests
There is no test for task02 (Mock theme). For now i didn't fully understand it.
I will return to this task with a fresh look later.