Example #1
0
    def test_in_dict(self):
        # for autocompletion, all attributes should exist, even if it hasn't been called.
        hub = Hub()
        hub.pop.sub.add('tests.mods')

        l_hub = testing._LazyPop(hub)
        assert 'mods' in l_hub.__dict__
Example #2
0
    def test_recursive_get(self):
        hub = Hub()
        hub.pop.sub.add('tests.mods')
        assert hub.mods
        l_hub = testing._LazyPop(hub)

        result = getattr(l_hub, 'mods.foo')
        assert result is l_hub.mods.foo
Example #3
0
    def test_recursive_subs(self):
        hub = Hub()
        hub.pop.sub.add('tests.mods')
        hub.pop.sub.add('tests.mods.nest', sub=hub.mods)
        l_hub = testing._LazyPop(hub)

        assert hub.mods.nest.basic.ret_true()

        with pytest.raises(NotImplementedError):
            l_hub.mods.nest.basic.ret_true()
Example #4
0
    def test_duplicate_hub(self):
        hub = Hub()
        hub.pop.sub.add('tests.mods')

        hub.hub = hub
        hub.mods.hub = hub
        hub.mods.foo.hub = hub

        l_hub = testing._LazyPop(hub)

        assert l_hub.hub is l_hub
        assert l_hub.mods.hub is l_hub
        assert l_hub.mods.foo.hub is l_hub
Example #5
0
    def test_duplicate_object(self):
        hub = Hub()
        hub.pop.sub.add('tests.mods')

        hub.test_val = sentinel.test_val
        hub.mods.test_val = sentinel.test_val
        hub.mods.testing.test_val = sentinel.test_val

        l_hub = testing._LazyPop(hub)

        assert isinstance(l_hub.test_val, NonCallableMock)
        assert l_hub.test_val is l_hub.mods.test_val
        assert l_hub.mods.test_val is l_hub.mods.testing.test_val
Example #6
0
    def test_var_exists_enforcement(self):
        hub = Hub()
        hub.pop.sub.add('tests.mods')

        hub.FOO = 'foo'
        hub.mods.FOO = 'foo'
        hub.mods.testing.FOO = 'foo'

        l_hub = testing._LazyPop(hub)

        for l in (l_hub, l_hub.mods, l_hub.mods.testing):
            try:
                assert isinstance(getattr(l, 'FOO'), NonCallableMagicMock)
            except Exception as e:
                raise type(e)('{}: {}'.format(
                    type(l._LazyPop__obj).__name__, str(e)))
            with pytest.raises(AttributeError):
                l_hub.BAZ