# Path: charms/reactive/flags.py
# TRIGGER_CALLBACKS = {}
# class State(str):
# class StateList(object):
# def set_flag(flag, value=None):
# def clear_flag(flag):
# def toggle_flag(flag, should_set):
# def register_trigger(when=None, when_not=None, set_flag=None, clear_flag=None, callback=None):
# def _get_trigger(when, when_not):
# def _save_trigger(when, when_not, data):
# def is_flag_set(flag):
# def all_flags_set(*desired_flags):
# def any_flags_set(*desired_flags):
# def get_flags():
# def get_unset_flags(*desired_flags):
# def _get_flag_value(flag, default=None):
# def set_state(state, value=None):
# def remove_state(state):
# def toggle_state(state, should_set):
# def is_state(state):
# def all_states(*desired_states):
# def any_states(*desired_states):
# def get_states():
# def get_state(flag, default=None):
# def _manage_automatic_flags():
# def _manage_upgrade_flags():
# def _clear_triggers():


import unittest
import mock
from charms.reactive import flags




class TestTriggers(unittest.TestCase):
    def setUp(self):
        kv_p = mock.patch('charmhelpers.core.unitdata.kv')
        kv = kv_p.start()
        self.addCleanup(kv_p.stop)
        kv.return_value = MockKV()

    def test_no_triggers(self):
        assert not flags.any_flags_set('foo', 'bar', 'qux')
        flags.set_flag('foo')
        assert not flags.any_flags_set('bar', 'qux')
        flags.clear_flag('foo')
        assert not flags.any_flags_set('foo', 'bar', 'qux')

    def test_when_set(self):
        flags.register_trigger(when='foo', set_flag='bar')
        flags.set_flag('foo')

# Path: charms/reactive/flags.py
# TRIGGER_CALLBACKS = {}
# class State(str):
# class StateList(object):
# def set_flag(flag, value=None):
# def clear_flag(flag):
# def toggle_flag(flag, should_set):
# def register_trigger(when=None, when_not=None, set_flag=None, clear_flag=None, callback=None):
# def _get_trigger(when, when_not):
# def _save_trigger(when, when_not, data):
# def is_flag_set(flag):
# def all_flags_set(*desired_flags):
# def any_flags_set(*desired_flags):
# def get_flags():
# def get_unset_flags(*desired_flags):
# def _get_flag_value(flag, default=None):
# def set_state(state, value=None):
# def remove_state(state):
# def toggle_state(state, should_set):
# def is_state(state):
# def all_states(*desired_states):
# def any_states(*desired_states):
# def get_states():
# def get_state(flag, default=None):
# def _manage_automatic_flags():
# def _manage_upgrade_flags():
# def _clear_triggers():


# Path: tests/test_flags.py
import unittest
import mock
from charms.reactive import flags





class TestTriggers(unittest.TestCase):
    def setUp(self):
        kv_p = mock.patch('charmhelpers.core.unitdata.kv')
        kv = kv_p.start()
        self.addCleanup(kv_p.stop)
        kv.return_value = MockKV()

    def test_no_triggers(self):
        assert not flags.any_flags_set('foo', 'bar', 'qux')
        flags.set_flag('foo')
        assert not flags.any_flags_set('bar', 'qux')
        flags.clear_flag('foo')
        assert not flags.any_flags_set('foo', 'bar', 'qux')

    def test_when_set(self):
        flags.register_trigger(when='foo', set_flag='bar')
        flags.set_flag('foo')

        assert flags.is_flag_set('bar')