Skip to content

Commit ab57000

Browse files
committed
test: Add tests with pytest and tox
1 parent 2de015d commit ab57000

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

test/test_api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
import codeforces
3+
4+
class TestCall(object):
5+
def test_undefined_method(self):
6+
with pytest.raises(codeforces.error.CodeforcesAPIError):
7+
method = "undefined.method"
8+
codeforces.api.call(method)
9+
10+
def test_unauth_method(self):
11+
method = "user.info"
12+
handles = "python-codeforces"
13+
14+
codeforces.api.call(method, handles=handles)
15+
16+
key = "0d905168ea10217dd91472e861bf8c80932f060e"
17+
secret = "3d3872085b0255159381a1884e9f66d5213ba796"
18+
codeforces.api.call(method, key=key, secret=secret, handles=handles)
19+
20+
def test_auth_method(self):
21+
method = "user.friends"
22+
23+
key = "0d905168ea10217dd91472e861bf8c80932f060e"
24+
secret = "3d3872085b0255159381a1884e9f66d5213ba796"
25+
codeforces.api.call(method, key=key, secret=secret)
26+
27+
with pytest.raises(codeforces.error.CodeforcesAPIError):
28+
codeforces.api.call(method)

test/test_problem.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
import codeforces
3+
4+
class TestGetInfo(object):
5+
def test_normal_problem(self):
6+
contest_id = 1
7+
index = 'A'
8+
9+
title, time_limit, memory_limit, sample_tests = codeforces.problem.get_info(contest_id, index)
10+
11+
assert(title == 'A. Theatre Square')
12+
assert(time_limit == '1 second')
13+
assert(memory_limit == '256 megabytes')
14+
assert(list(sample_tests) == [('6 6 4', '4')])

tox.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# tox (https://tox.readthedocs.io/) is a tool for running tests
2+
# in multiple virtualenvs. This configuration file will run the
3+
# test suite on all supported python versions. To use it, "pip install tox"
4+
# and then run "tox" from this directory.
5+
6+
[tox]
7+
envlist = py36,py37
8+
9+
[testenv]
10+
deps =
11+
pytest
12+
commands =
13+
pytest

0 commit comments

Comments
 (0)