Open
Conversation
icanhardcode
suggested changes
Oct 26, 2021
| 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. |
| 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}). |
homework4/task03.py
Outdated
|
|
||
| def my_precious_logger(text: str): | ||
|
|
||
| if (text[:5]) != 'error': |
There was a problem hiding this comment.
take a look at default string's methods in python
homework4/task01.py
Outdated
Comment on lines
+37
to
+41
| if line.replace('.', '', 1).isdigit() \ | ||
| and not 1.0 <= float(line) < 3.0: | ||
| return True | ||
| else: | ||
| return False |
|
|
||
| from homework4.task01 import read_magic_number | ||
|
|
||
|
|
There was a problem hiding this comment.
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.
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.
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.
"hey" should be written into stdout... use capsys for test stdouterr
Comment on lines
+1
to
+25
| 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.
doctest should be written in main function.. take a look at pytest's argument to see how to run doctests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.