Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This is a basic workflow to help you get started with Actions

name: CI

on: push

jobs:
code_quality:
runs-on: ubuntu-latest
name: Checks with black, isort and possibly run tests
container: python:3.9

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run script
run: |
pip install flake8 isort pytest
pip install requests
ls -la
flake8 .
isort --check .
py.test tests
132 changes: 0 additions & 132 deletions homework1/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions homework1/requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions homework1/sample_project/calculator/calc.py

This file was deleted.

2 changes: 0 additions & 2 deletions homework1/sample_project/requirements.txt

This file was deleted.

Empty file.
15 changes: 0 additions & 15 deletions homework1/sample_project/tests/test_calculator.py

This file was deleted.

Empty file removed homework1/tasks/__init__.py
Empty file.
11 changes: 0 additions & 11 deletions homework1/tasks/task02.py

This file was deleted.

17 changes: 0 additions & 17 deletions homework1/tasks/task03.py

This file was deleted.

10 changes: 0 additions & 10 deletions homework1/tasks/task04.py

This file was deleted.

11 changes: 0 additions & 11 deletions homework1/tasks/task05.py

This file was deleted.

Empty file removed homework1/tests/__init__.py
Empty file.
10 changes: 0 additions & 10 deletions homework1/tests/some_file.txt

This file was deleted.

49 changes: 0 additions & 49 deletions homework1/tests/tests.py

This file was deleted.

File renamed without changes.
40 changes: 40 additions & 0 deletions homework4/task01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Write a function that gets file path as an argument.
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?


Write a test for that function using pytest library.
You should create files required for the testing inside the test run and
remove them after the test run.
(Opposite to previous homeworks when you used files created manually
before the test.)

Definition of done:
- function is created
- function is properly formatted
- function has positive and negative tests
- tests do a cleanup and remove remove files generated by tests

You will learn:
- how to test Exceptional cases
- how to clean up after tests
- how to check if file exists**
- how to handle*** and raise**** exceptions in test. Use sample
from the documentation.

* https://en.wikipedia.org/wiki/Interval_(mathematics)#Terminology
** https://docs.python.org/3/library/os.path.html
*** https://docs.python.org/3/tutorial/errors.html#handling-exceptions
**** https://docs.python.org/3/tutorial/errors.html#raising-exceptions
"""


def read_magic_number(path: str) -> bool:
try:
with open(path, 'r') as file:
line = file.readline()
return 1 <= float(line) < 3
except BaseException:
raise ValueError
41 changes: 41 additions & 0 deletions homework4/task02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Write a function that accepts an URL as input
and count how many letters `i` are present in the HTML by this URL.

Write a test that check that your function works.
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?


Definition of done:
- function is created
- function is properly formatted
- function has positive and negative tests
- test could be run without internet connection

You will learn:
- how to test using mocks
- how to write complex mocks
- how to raise an exception form mocks
- do a simple network requests


>>> count_dots_on_i("https://example.com/")
59

* https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen
"""

import requests
from requests import RequestException

# i misunderstood that we can use any lib for this task


def count_dots_on_i(url: str) -> int:
try:
r = requests.get(url)
return r.text.count("i")
except RequestException:
raise ValueError(f"Unreachable {url}")
Loading