Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ef8f7cd

Browse files
Merge pull request #65 from Khrisefzm/bug-exercise-23
solve bug from exercise 23
2 parents 02c96dc + ec3675b commit ef8f7cd

File tree

1 file changed

+49
-16
lines changed
  • exercises/023-list-and-tuple

1 file changed

+49
-16
lines changed

‎exercises/023-list-and-tuple/test.py

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
1-
import io, sys, os, pytest, json, mock
2-
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1+
import pytest
32

3+
@pytest.mark.it('You should create a function named "list_and_tuple"')
4+
def test_variable_exists(app):
5+
try:
6+
assert app.list_and_tuple
7+
except AttributeError:
8+
raise AttributeError('The function "list_and_tuple" should exists')
49

5-
@pytest.mark.it('The output should be the expected for this solution')
6-
def test_output(capsys, app):
7-
fake_input = ["34,67,55,33,12,98"] #fake input
8-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
9-
app()
10-
captured = capsys.readouterr()
11-
assert captured.out == "['34', '67', '55', '33', '12', '98']\n" or "('34', '67', '55', '33', '12', '98')\n"
10+
@pytest.mark.it('The function "list_and_tuple" should return two elements')
11+
def test_function_return_two_elements(app):
12+
try:
13+
value = app.list_and_tuple()
14+
assert isinstance(value, tuple)
15+
assert len(value) == 2
16+
except AttributeError:
17+
raise AttributeError('The function "list_and_tuple" should exists')
1218

13-
@pytest.mark.it('The solution should work with other parameters')
14-
def test_output_2(capsys, app):
15-
fake_input = ["11,56,23,12,02"] #fake input
16-
with mock.patch('builtins.input', lambda x: fake_input.pop()):
17-
app()
18-
captured = capsys.readouterr()
19-
assert captured.out == "['11', '56', '23', '12', '02']\n" or "('11', '56', '23', '12', '02')\n"
19+
@pytest.mark.it('The function "list_and_tuple" should return a list first')
20+
def test_function_return_a_list(app):
21+
try:
22+
value = app.list_and_tuple()
23+
assert isinstance(value, tuple)
24+
assert isinstance(value[0], list)
25+
except AttributeError:
26+
raise AttributeError('The function "list_and_tuple" should exists')
27+
28+
@pytest.mark.it('The function "list_and_tuple" should return a tuple second')
29+
def test_function_return_a_tuple(app):
30+
try:
31+
value = app.list_and_tuple()
32+
assert isinstance(value, tuple)
33+
assert isinstance(value[1], tuple)
34+
except AttributeError:
35+
raise AttributeError('The function "list_and_tuple" should exists')
36+
37+
@pytest.mark.it('The function "list_and_tuple" should return a list and tuple with the expected values')
38+
def test_function_return_the_expected_values(app):
39+
try:
40+
value = app.list_and_tuple(1,2,3,4,5,6)
41+
assert value[0]==['1', '2', '3', '4', '5', '6']
42+
assert value[1]==('1', '2', '3', '4', '5', '6')
43+
except AttributeError:
44+
raise AttributeError('The function "list_and_tuple" should exists')
2045

46+
@pytest.mark.it('The function "list_and_tuple" should return a list and tuple with the expected values')
47+
def test_function_return_the_expected_values(app):
48+
try:
49+
value = app.list_and_tuple(7,8,9,10,11,12)
50+
assert value[0]==['7', '8', '9', '10', '11', '12']
51+
assert value[1]==('7', '8', '9', '10', '11', '12')
52+
except AttributeError:
53+
raise AttributeError('The function "list_and_tuple" should exists')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /