Skip to content

Homework4#8

Open
vslyubimov wants to merge 4 commits into
masterfrom
homework4
Open

Homework4#8
vslyubimov wants to merge 4 commits into
masterfrom
homework4

Conversation

@vslyubimov

Copy link
Copy Markdown
Owner

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.

@vslyubimov vslyubimov changed the title add hw4 Homework4 Oct 24, 2021
Comment thread homework4/task01.py
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about errors?

Comment thread homework4/task02.py
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}).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors?

Comment thread homework4/task03.py Outdated

def my_precious_logger(text: str):

if (text[:5]) != 'error':

Copy link
Copy Markdown

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

Comment thread 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

Copy link
Copy Markdown

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


Copy link
Copy Markdown

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

Comment thread tests/homework4/test_task01.py Outdated
file = open(file_path, "w")
file.write("5")
file.close()
assert read_magic_number(file_path)

Copy link
Copy Markdown

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

Comment thread 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)))

Copy link
Copy Markdown

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

Comment thread tests/homework4/test_task03.py Outdated


def test_basic_functional():
assert my_precious_logger('hey') == sys.stderr.write("hey")

Copy link
Copy Markdown

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

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"]

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants