Exemplo n.º 1
0
"""
    transitions.extensions.states
    -----------------------------

    This module contains mix ins which can be used to extend state functionality.
"""

from threading import Timer
import logging
import inspect

from transitions.core import MachineError, listify, State
from transitions.compat import property, NullHandler

_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(NullHandler())


class Tags(State):
    """ Allows states to be tagged.
        Attributes:
            tags (list): A list of tag strings. `State.is_<tag>` may be used
                to check if <tag> is in the list.
    """
    def __init__(self, *args, **kwargs):
        """
        Args:
            **kwargs: If kwargs contains `tags`, assign them to the attribute.
        """
        self.tags = kwargs.pop('tags', [])
        super(Tags, self).__init__(*args, **kwargs)
Exemplo n.º 2
0
from threading import Thread
import logging

from transitions.extensions import MachineFactory
from transitions.tests.test_nesting import TestNestedTransitions as TestsNested
from transitions.tests.test_core import TestTransitions as TestCore
from transitions.tests.utils import Stuff, DummyModel, SomeContext
from transitions.compat import NullHandler

try:
    from unittest.mock import MagicMock
except ImportError:
    from mock import MagicMock

logger = logging.getLogger(__name__)
logger.addHandler(NullHandler())


def heavy_processing():
    time.sleep(1)


def heavy_checking():
    time.sleep(0.5)
    return False


class TestLockedTransitions(TestCore):
    def setUp(self):
        self.machine_cls = MachineFactory.get_predefined(locked=True)
        self.stuff = Stuff(machine_cls=self.machine_cls)