Skip to content

Commit c46739c

Browse files
committed
Initial commit
0 parents  commit c46739c

File tree

10 files changed

+507
-0
lines changed

10 files changed

+507
-0
lines changed

.gitignore

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
# Папки, создаваемые средой разработки
132+
.idea
133+
.DS_Store
134+
.AppleDouble
135+
.LSOverride
136+
137+
*.sublime-project
138+
*.sublime-workspace
139+
140+
.vscode/
141+
*.code-workspace
142+
143+
# Local History for Visual Studio Code
144+
.history/
145+
146+
.mypy_cache

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# hw_python_oop
2+
Sprint 2. Итоговый проект.

homework.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import datetime as dt
2+
3+
4+
class Calculator:
5+
pass
6+
7+
8+
class Record:
9+
pass

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
norecursedirs = env/*
3+
addopts = -vv -p no:cacheprovider
4+
testpaths = tests/
5+
python_files = test_*.py

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest==5.3.2

setup.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
ignore =
3+
W503
4+
filename =
5+
./homework.py
6+
max-complexity = 10

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
from os.path import abspath, dirname
3+
4+
root_dir = dirname(dirname(abspath(__file__)))
5+
sys.path.append(root_dir)
6+
7+
pytest_plugins = [
8+
'tests.fixtures.fixture_data',
9+
'tests.fixtures.fixture_msg',
10+
]

tests/fixtures/fixture_data.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import random
2+
from datetime import datetime, timedelta
3+
4+
import pytest
5+
6+
try:
7+
import homework
8+
except ImportError:
9+
pass
10+
11+
12+
@pytest.fixture
13+
def init_limit():
14+
return 2500
15+
16+
17+
@pytest.fixture
18+
def data_records():
19+
amount = 150
20+
count = random.randint(30, 40)
21+
today_count = random.randint(5, 10)
22+
week_count = random.randint(5, 10) + today_count
23+
future_count = random.randint(5, 10)
24+
data = []
25+
for idx, _ in enumerate(range(count)):
26+
if idx < today_count:
27+
date = datetime.now()
28+
elif idx < week_count:
29+
date = datetime.now() - timedelta(days=random.randint(1, 6))
30+
elif idx < future_count + week_count:
31+
date = datetime.now() + timedelta(days=random.randint(1, 6))
32+
else:
33+
date = datetime(2019, 9, 1)
34+
data.append(homework.Record(amount=amount, comment=f'Test {idx}', date=date.strftime('%d.%m.%Y')))
35+
random.shuffle(data)
36+
return data, today_count * amount, week_count * amount
37+
38+
39+
@pytest.fixture
40+
def negative_calories_remained():
41+
return 'Хватит есть!'
42+
43+
44+
@pytest.fixture
45+
def positive_calories_remained():
46+
def _positive_calories_remained(limit):
47+
return f'Сегодня можно съесть что-нибудь ещё, но с общей калорийностью не более {limit} кКал'
48+
return _positive_calories_remained
49+
50+
51+
@pytest.fixture
52+
def today_cash_remained():
53+
54+
def _today_positively(currency):
55+
return f'На сегодня осталось {remained_dict[currency]} {currency_dict[currency]}'
56+
57+
def _today_negatively(currency):
58+
return f'Денег нет, держись: твой долг - {remained_dict[currency]} {currency_dict[currency]}'
59+
60+
def _today_cash_remained(remained, currency):
61+
if remained == 0:
62+
return 'Денег нет, держись'
63+
elif remained == 1:
64+
return _today_positively(currency)
65+
elif remained == -1:
66+
return _today_negatively(currency)
67+
68+
currency_dict = {
69+
'usd': 'USD',
70+
'eur': 'Euro',
71+
'rub': 'руб'
72+
}
73+
remained_dict = {
74+
'usd': '5(.0|.00|)',
75+
'eur': '4.29',
76+
'rub': '300(.0|.00|)'
77+
}
78+
return _today_cash_remained

tests/fixtures/fixture_msg.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
3+
4+
class MsgError:
5+
6+
def __init__(self, method_name, *args, **kwargs):
7+
self.result = getattr(self, method_name)(*args, **kwargs)
8+
9+
def add_class(self, class_name, child=False, parent_name=''):
10+
text = f'Добавьте класс `{class_name}`'
11+
if child:
12+
text += f', этот класс наследуется от класса `{parent_name}`'
13+
return text
14+
15+
def add_method(self, method_name, class_name):
16+
return f'Добавьте метод `{method_name}()` для класса `{class_name}`'
17+
18+
def wrong_method(self, method_name, class_name):
19+
return f'Проверьте правильность работы метода `{method_name}()` у класса `{class_name}`'
20+
21+
def dont_create_method(self, method_name, class_name):
22+
return f'`Метод `{method_name}()` не должен быть создан для класса `{class_name}`'
23+
24+
def add_attr(self, attr_name, class_name):
25+
return f'Добавьте свойство `{attr_name}` классу `{class_name}`'
26+
27+
def wrong_attr(self, attr_name, class_name, msg=''):
28+
return f'Неверное значение свойства `{attr_name}` у класса `{class_name}`{msg}'
29+
30+
def dont_create_attr(self, attr_name, class_name):
31+
return f'`Свойство `{attr_name}` не должен быть создано для класса `{class_name}`'
32+
33+
def child_method(self, child_name, parent_name):
34+
return f'`{child_name}` класс наследуется от класса `{parent_name}`'
35+
36+
37+
@pytest.fixture
38+
def msg_err():
39+
def _msg_err(msg_name, *args, **kwargs):
40+
msg = MsgError(msg_name, *args, **kwargs)
41+
return msg.result
42+
return _msg_err

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy