当前位置: 首页>>代码示例>>Python>>正文


Python models.Switch类代码示例

本文整理汇总了Python中gutter.client.models.Switch的典型用法代码示例。如果您正苦于以下问题:Python Switch类的具体用法?Python Switch怎么用?Python Switch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Switch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_switch_state_can_be_changed

    def test_switch_state_can_be_changed(self):
        switch = Switch("foo")
        old_state = switch.state

        switch.state = Switch.states.GLOBAL
        eq_(switch.state, Switch.states.GLOBAL)
        ok_(old_state is not switch.state)
开发者ID:disqus,项目名称:gutter,代码行数:7,代码来源:test_models.py

示例2: test_can_register_signals_and_get_notified

    def test_can_register_signals_and_get_notified(self):
        signals.switch_registered.connect(self.callback.switch_added)
        signals.switch_unregistered.connect(self.callback.switch_removed)
        signals.switch_updated.connect(self.callback.switch_updated)

        eq_(self.callback.register_calls, [])
        eq_(self.callback.unregister_calls, [])
        eq_(self.callback.update_calls, [])

        switch = Switch("foo")

        self.manager.register(switch)
        eq_(self.callback.register_calls, [switch])

        self.manager.unregister(switch.name)
        eq_(self.callback.unregister_calls, [switch])

        self.manager.register(switch)
        eq_(self.callback.register_calls, [switch, switch])

        switch.state = Switch.states.GLOBAL
        self.manager.update(switch)

        change = self.callback.update_calls[0]
        eq_(change[0], switch)
        changes = change[1]
        eq_(changes["state"], dict(current=Switch.states.GLOBAL, previous=Switch.states.DISABLED))
开发者ID:cabiad,项目名称:gutter,代码行数:27,代码来源:test_integration.py

示例3: test_retrieved_switches_can_be_updated

    def test_retrieved_switches_can_be_updated(self):
        switch = Switch("foo")
        self.manager.register(switch)

        self.assertEquals(self.manager.switch("foo").name, "foo")

        switch.state = Switch.states.GLOBAL
        switch.save()

        self.assertEquals(self.manager.switch("foo").state, Switch.states.GLOBAL)
开发者ID:cabiad,项目名称:gutter,代码行数:10,代码来源:test_integration.py

示例4: test_switches_are_still_equal_with_different_managers

    def test_switches_are_still_equal_with_different_managers(self):
        a = Switch("a")
        b = Switch("a")

        eq_(a, b)

        a.manager = "foo"
        b.manager = "bar"

        eq_(a, b)
开发者ID:disqus,项目名称:gutter,代码行数:10,代码来源:test_models.py

示例5: add_switch

    def add_switch(self, name, condition=None, *conditions, **kwargs):
        switch = Switch(name, compounded=kwargs.get("compounded", False))
        switch.state = kwargs.get("state", Switch.states.SELECTIVE)
        conditions = list(conditions)

        if condition:
            conditions.append(condition)

        [switch.conditions.append(c) for c in conditions]
        kwargs.get("manager", self.manager).register(switch)
        return switch
开发者ID:cabiad,项目名称:gutter,代码行数:11,代码来源:test_integration.py

示例6: test_legacy_unpickle

    def test_legacy_unpickle(self):
        d = EncodingDict()

        parent = Switch('a')
        switch = Switch('a:b')

        children = [
            Switch('a:b:c'),
            Switch('a:b:d'),
        ]

        [setattr(child, 'parent', switch) for child in children]

        switch.children = children
        switch.parent = parent

        decoded_switch = d._decode(d._encode(switch))
        self.assertEquals(decoded_switch.name, switch.name)
        self.assertEquals(decoded_switch.parent, switch.parent.name)
        self.assertListEqual([child.name for child in children], decoded_switch.children)
开发者ID:faulkner,项目名称:gutter,代码行数:20,代码来源:test_models.py

示例7: test_retrieved_switches_can_be_updated

    def test_retrieved_switches_can_be_updated(self):
        switch = Switch('foo')
        self.manager.register(switch)

        switch.name = 'steve'
        switch.save()

        self.assertRaises(ValueError, self.manager.switch, 'foo')
        self.assertEquals(self.manager.switch('steve').name, 'steve')

        switch.name = 'bob'
        switch.state = Switch.states.GLOBAL
        switch.save()

        self.assertEquals(self.manager.switch('bob').name, 'bob')
        self.assertEquals(
            self.manager.switch('bob').state,
            Switch.states.GLOBAL
        )
        self.assertRaises(ValueError, self.manager.switch, 'steve')
开发者ID:DamianZaremba,项目名称:gutter,代码行数:20,代码来源:test_integration.py

示例8: test_can_register_signals_and_get_notified

    def test_can_register_signals_and_get_notified(self):
        signals.switch_registered.connect(self.callback.switch_added)
        signals.switch_unregistered.connect(self.callback.switch_removed)
        signals.switch_updated.connect(self.callback.switch_updated)

        eq_(self.callback.register_calls, [])
        eq_(self.callback.unregister_calls, [])
        eq_(self.callback.update_calls, [])

        switch = Switch('foo')

        self.manager.register(switch)
        eq_(self.callback.register_calls, [switch])

        self.manager.unregister(switch.name)
        eq_(self.callback.unregister_calls, [switch])

        self.manager.register(switch)
        eq_(self.callback.register_calls, [switch, switch])

        switch.name = 'a new name'
        switch.state = Switch.states.GLOBAL
        self.manager.update(switch)

        change = self.callback.update_calls[0]
        eq_(change[0], switch)
        changes = change[1]
        eq_(changes['name'], dict(current='a new name', previous='foo'))
        eq_(changes['state'], dict(current=Switch.states.GLOBAL, previous=Switch.states.DISABLED))

        switch.name = 'from save() call'
        switch.save()

        change = self.callback.update_calls[1]
        eq_(change[0], switch)
        changes = change[1]
        eq_(changes['name'], dict(current='from save() call', previous='a new name'))
开发者ID:DamianZaremba,项目名称:gutter,代码行数:37,代码来源:test_integration.py

示例9: build_and_register_switch

 def build_and_register_switch(self, name, enabled_for=False):
     switch = Switch(name)
     switch.enabled_for = mock.Mock(return_value=enabled_for)
     self.manager.register(switch)
     return switch
开发者ID:disqus,项目名称:gutter,代码行数:5,代码来源:test_models.py

示例10: test_switch_name_is_immutable

 def test_switch_name_is_immutable(self):
     switch = Switch("foo")
     with self.assertRaises(AttributeError):
         switch.name = "bar"
开发者ID:disqus,项目名称:gutter,代码行数:4,代码来源:test_models.py

示例11: test_switch_enabed_for_skips_switch_active_signal_when_not_enabled

 def test_switch_enabed_for_skips_switch_active_signal_when_not_enabled(self, signal):
     switch = Switch("foo", state=Switch.states.DISABLED)
     eq_(switch.enabled_for("causing input"), False)
     eq_(signal.call.called, False)
开发者ID:disqus,项目名称:gutter,代码行数:4,代码来源:test_models.py

示例12: test_switch_enabed_for_calls_switch_active_signal_when_enabled

 def test_switch_enabed_for_calls_switch_active_signal_when_enabled(self, signal):
     switch = Switch("foo", state=Switch.states.GLOBAL)
     ok_(switch.enabled_for("causing input"))
     signal.call.assert_called_once_with(switch, "causing input")
开发者ID:disqus,项目名称:gutter,代码行数:4,代码来源:test_models.py

示例13: test_switch_enabed_for_calls_switch_checked_signal

 def test_switch_enabed_for_calls_switch_checked_signal(self, signal):
     switch = Switch("foo")
     switch.enabled_for(True)
     signal.call.assert_called_once_with(switch)
开发者ID:disqus,项目名称:gutter,代码行数:4,代码来源:test_models.py

示例14: test_switch_enabed_for_skips_switch_active_signal_when_not_enabled

 def test_switch_enabed_for_skips_switch_active_signal_when_not_enabled(self, signal):
     switch = Switch('foo', manager='manager', state=Switch.states.DISABLED)
     eq_(switch.enabled_for('causing input'), False)
     eq_(signal.call.called, False)
开发者ID:gabrielpjordao,项目名称:gutter,代码行数:4,代码来源:test_models.py

示例15: test_switch_enabed_for_calls_switch_active_signal_when_enabled

 def test_switch_enabed_for_calls_switch_active_signal_when_enabled(self, signal):
     switch = Switch('foo', manager='manager', state=Switch.states.GLOBAL)
     ok_(switch.enabled_for('causing input'))
     signal.call.assert_called_once_with(switch, 'causing input')
开发者ID:gabrielpjordao,项目名称:gutter,代码行数:4,代码来源:test_models.py


注:本文中的gutter.client.models.Switch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。