File: test_stack.py

package info (click to toggle)
pastel 0.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 296 kB
  • sloc: python: 532; sh: 7; makefile: 3
file content (54 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-

import pytest

from pastel.style import Style


def test_push(stack):
    s1 = Style("white", "black")
    s2 = Style("yellow", "blue")
    stack.push(s1)
    stack.push(s2)

    assert s2 == stack.get_current()

    s3 = Style("green", "red")
    stack.push(s3)

    assert s3 == stack.get_current()


def test_pop(stack):
    s1 = Style("white", "black")
    s2 = Style("yellow", "blue")
    stack.push(s1)
    stack.push(s2)

    assert s2 == stack.pop()
    assert s1 == stack.pop()


def test_pop_empty(stack):
    assert isinstance(stack.pop(), Style)


def test_pop_not_last(stack):
    s1 = Style("white", "black")
    s2 = Style("yellow", "blue")
    s3 = Style("green", "red")
    stack.push(s1)
    stack.push(s2)
    stack.push(s3)

    assert s2 == stack.pop(s2)
    assert s1 == stack.pop()


def test_invalid_pop(stack):
    s1 = Style("white", "black")
    s2 = Style("yellow", "blue")
    stack.push(s1)

    with pytest.raises(ValueError):
        stack.pop(s2)