Skip to content

Commit 3d00c59

Browse files
committed
Added pytest and small fixes
1 parent 7f78460 commit 3d00c59

13 files changed

+449
-54
lines changed

.github/workflows/codestyle.yml

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ jobs:
1717
uses: actions/setup-python@v2
1818
with:
1919
python-version: "3.9"
20+
- name: Cache pip
21+
uses: actions/cache@v2
22+
with:
23+
path: ~/.cache/pip
24+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
25+
restore-keys: |
26+
${{ runner.os }}-pip-
2027
- name: Install dependencies
2128
run: |
2229
python -m pip install --upgrade pip

.github/workflows/publish.yml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
2323
restore-keys: |
2424
${{ runner.os }}-pip-
25-
${{ runner.os }}-
2625
- name: Install twine
2726
run: >-
2827
pip install -r requirements.txt

.github/workflows/test.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Python package
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Cache pip
24+
uses: actions/cache@v2
25+
with:
26+
path: ~/.cache/pip
27+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
28+
restore-keys: |
29+
${{ runner.os }}-pip-
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install -r requirements.txt
34+
- name: Test with pytest
35+
run: |
36+
pytest tests/test_api.py --api_key ${{ secrets.codeforces_api_key }} --api_secret ${{ secrets.codeforces_api_secret }}

.gitignore

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@
66
!/LICENSE
77
!/*.md
88
!/requirements.txt
9+
910
!tests/
1011
tests/*
11-
!tests/main.py
12-
!tests/conf.py.template
13-
!/codeforces_api
14-
/codeforces_api/
12+
!tests/test_api.py
13+
!tests/conftest.py
14+
15+
!codeforces_api/
16+
codeforces_api/*
17+
!codeforces_api/__init__.py
18+
!codeforces_api/api_request_maker.py
19+
!codeforces_api/api_requests.py
20+
!codeforces_api/parse_methods.py
21+
!codeforces_api/types.py
22+
!codeforces_api/version.py
23+
1524
!/.github

codeforces_api/api_request_maker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def generate_request(self, method_name, **fields):
8686
def check_return_code(self, response):
8787
"""
8888
Checks if a returned response is OK.
89-
89+
9090
If not OK Exception will be raised will additional info.
9191
"""
9292
if response["status"] != "OK":

codeforces_api/api_requests.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def user_info(self, handles):
309309
Get user.info.
310310
311311
handles should be a list of users, up to 10000.
312-
312+
313313
Returns parsed response from codeforces.com.
314314
"""
315315
if not isinstance(handles, list):
@@ -342,7 +342,7 @@ def user_rated_list(self, active_only=False):
342342
def user_rating(self, handle):
343343
"""
344344
Get user.rating.
345-
345+
346346
handle should be a string.
347347
348348
Returns parsed response from codeforces.com.
@@ -377,4 +377,3 @@ def user_status(self, handle, start=-1, count=-1):
377377
Submission.de_json(submission)
378378
for submission in self._make_request("user.status", **parameters)
379379
]
380-

codeforces_api/types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def __init__(
166166

167167
def to_dict(self):
168168
return {
169-
"hand;e": self.handle,
169+
"handle": self.handle,
170170
"email": self.email,
171171
"vk_id": self.vk_id,
172172
"open_id": self.open_id,
@@ -352,7 +352,7 @@ def de_json(cls, json_string):
352352
contest_name = obj["contestName"]
353353
handle = obj["handle"]
354354
rank = obj["rank"]
355-
rating_update_time_seconds = ["ratingUpdateTimeSeconds"]
355+
rating_update_time_seconds = obj["ratingUpdateTimeSeconds"]
356356
old_rating = obj["oldRating"]
357357
new_rating = obj["newRating"]
358358
return cls(

codeforces_api/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.3"
1+
__version__ = "2.0.4"

requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
appdirs==1.4.4
22
astroid==2.5.1
3+
atomicwrites==1.4.0
4+
attrs==20.3.0
35
black==20.8b1
46
bleach==3.3.0
57
certifi==2020.12.5
@@ -9,6 +11,7 @@ colorama==0.4.4
911
docutils==0.16
1012
idna==2.10
1113
importlib-metadata==3.7.3
14+
iniconfig==1.1.1
1215
isort==5.7.0
1316
keyring==23.0.0
1417
lazy-object-proxy==1.5.2
@@ -18,9 +21,12 @@ mypy-extensions==0.4.3
1821
packaging==20.9
1922
pathspec==0.8.1
2023
pkginfo==1.7.0
24+
pluggy==0.13.1
25+
py==1.10.0
2126
Pygments==2.8.1
2227
pylint==2.7.2
2328
pyparsing==2.4.7
29+
pytest==6.2.2
2430
pywin32-ctypes==0.2.0
2531
readme-renderer==29.0
2632
regex==2020.11.13

tests/conf.py.template

-2
This file was deleted.

tests/conftest.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Config file for tests
3+
"""
4+
import pytest
5+
6+
7+
def pytest_addoption(parser):
8+
parser.addoption(
9+
"--api_key",
10+
action="store",
11+
default="api_key",
12+
help="API key for tests",
13+
)
14+
parser.addoption(
15+
"--api_secret",
16+
action="store",
17+
default="api_secret",
18+
help="API secret for tests",
19+
)
20+
21+
22+
@pytest.fixture
23+
def api_key(request):
24+
return request.config.getoption("--api_key")
25+
26+
27+
@pytest.fixture
28+
def api_secret(request):
29+
return request.config.getoption("--api_secret")

tests/main.py

-40
This file was deleted.

0 commit comments

Comments
 (0)