Skip to content
Merged
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
65 changes: 49 additions & 16 deletions exercises/023-list-and-tuple/test.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
import io, sys, os, pytest, json, mock
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
import pytest

@pytest.mark.it('You should create a function named "list_and_tuple"')
def test_variable_exists(app):
try:
assert app.list_and_tuple
except AttributeError:
raise AttributeError('The function "list_and_tuple" should exists')

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

@pytest.mark.it('The solution should work with other parameters')
def test_output_2(capsys, app):
fake_input = ["11,56,23,12,02"] #fake input
with mock.patch('builtins.input', lambda x: fake_input.pop()):
app()
captured = capsys.readouterr()
assert captured.out == "['11', '56', '23', '12', '02']\n" or "('11', '56', '23', '12', '02')\n"
@pytest.mark.it('The function "list_and_tuple" should return a list first')
def test_function_return_a_list(app):
try:
value = app.list_and_tuple()
assert isinstance(value, tuple)
assert isinstance(value[0], list)
except AttributeError:
raise AttributeError('The function "list_and_tuple" should exists')

@pytest.mark.it('The function "list_and_tuple" should return a tuple second')
def test_function_return_a_tuple(app):
try:
value = app.list_and_tuple()
assert isinstance(value, tuple)
assert isinstance(value[1], tuple)
except AttributeError:
raise AttributeError('The function "list_and_tuple" should exists')

@pytest.mark.it('The function "list_and_tuple" should return a list and tuple with the expected values')
def test_function_return_the_expected_values(app):
try:
value = app.list_and_tuple(1,2,3,4,5,6)
assert value[0]==['1', '2', '3', '4', '5', '6']
assert value[1]==('1', '2', '3', '4', '5', '6')
except AttributeError:
raise AttributeError('The function "list_and_tuple" should exists')

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