-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_stack.py
42 lines (34 loc) · 930 Bytes
/
test_stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pytest
from stack import Stack
from stack import EmptyStackError
@pytest.fixture(scope='function')
def create_stack():
test_stack = Stack()
test_stack.push(1)
test_stack.push(2)
test_stack.push(3)
return test_stack
def test_init():
test_stack = Stack()
assert test_stack is not None
with pytest.raises(EmptyStackError):
test_stack.pop()
def test_pop(create_stack):
"""test pop"""
test_stack = create_stack
assert test_stack.pop() == 3
assert test_stack.pop() == 2
assert test_stack.pop() == 1
with pytest.raises(EmptyStackError):
test_stack.pop()
def test_push():
"""test push"""
test_stack = Stack()
with pytest.raises(EmptyStackError):
test_stack.pop()
test_stack.push(3)
test_stack.push(2)
test_stack.push(1)
assert test_stack.pop() == 1
assert test_stack.pop() == 2
assert test_stack.pop() == 3