Skip to content

Conversation

@vslyubimov
Copy link
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
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.

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}).

Choose a reason for hiding this comment

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

errors?


def my_precious_logger(text: str):

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

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 on lines 37 to 41
if line.replace('.', '', 1).isdigit() \
and not 1.0 <= float(line) < 3.0:
return True
else:
return False

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


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

file = open(file_path, "w")
file.write("5")
file.close()
assert read_magic_number(file_path)

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

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

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



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

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

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.

3 participants