File: state.py

package info (click to toggle)
mock 1.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,572 kB
  • ctags: 533
  • sloc: python: 4,816; sh: 429; ansic: 66; makefile: 47
file content (36 lines) | stat: -rw-r--r-- 1,179 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
# -*- coding: utf-8 -*-
# vim: noai:ts=4:sw=4:expandtab

from .exception import StateError
from .trace_decorator import getLog


class State(object):
    def __init__(self):
        self._state = []
        # can be "unknown", "success" or "fail"
        self.result = "unknown"
        self.state_log = getLog("mockbuild.Root.state")

    def state(self):
        if not len(self._state):
            raise StateError("state called on empty state stack")
        return self._state[-1]

    def start(self, state):
        if state is None:
            raise StateError("start called with None State")
        self._state.append(state)
        self.state_log.info("Start: %s", state)

    def finish(self, state):
        if len(self._state) == 0:
            raise StateError("finish called on empty state list")
        current = self._state.pop()
        if state != current:
            raise StateError("state finish mismatch: current: %s, state: %s" % (current, state))
        self.state_log.info("Finish: %s", state)

    def alldone(self):
        if len(self._state) != 0:
            raise StateError("alldone called with pending states: %s" % ",".join(self._state))