def test_pop(): stack = Stack() stack.push([1, 3, 4]) assert stack.pop() == 4 assert stack.items == [1, 3] stack = Stack() with pytest.raises(Exception): stack.pop()
def __decode(self, stream: CBORStream, handler): stack = Stack() stack.push(MajorType()) while not stack.isEmpty(): top = stack.pop() if type(top) == str and top == 'break': # should be ArrayInf, MapInfValue, MapInfKey # ByteStringInf, TextStringInf inf_type = stack.pop() self.close_inf(inf_type, handler) else: new_states = top.run(stream, handler) if new_states: stack.push(new_states)
def test_is_empty(): stack = Stack() assert stack.isEmpty() is True stack = Stack() stack.push(10) assert stack.isEmpty() is False
def test_size(): stack = Stack() stack.push(5) assert stack.size() == 1 stack.push([6, 7]) assert stack.size() == 3
def test_peek(): stack = Stack() stack.push([1, 3, 4]) assert stack.peek() == 4 assert stack.items == [1, 3, 4]
def test_init(): stack = Stack() assert stack.items == []
def test_push_array(): stack = Stack() stack.push([3, 4]) assert stack.items == [3, 4] stack.push(['test', [5, 6]]) assert stack.items == [3, 4, 'test', [5, 6]]
def test_push(): stack = Stack() stack.push(5) assert stack.items == [5] stack.push('test') assert stack.items == [5, 'test']