Beispiel #1
0
def test_menu_module():
    from tomate_gtk.widgets.menu import TrayIconMenu

    assert sorted(MenuModule.providers.keys()) == sorted(
        ['view.menu', 'trayicon.menu'])

    graph = Graph()
    MenuModule().add_to(graph)

    provider = graph.providers['view.menu']

    assert 'view.menu' in graph.providers.keys()

    assert isinstance(provider, FactoryProvider)
    assert provider.scope == SingletonScope

    assert provider.dependencies == {
        'lazy_proxy': 'tomate.proxy',
        'about': 'view.about',
        'preference': 'view.preference'
    }

    graph.register_instance('tomate.view', Mock())

    assert isinstance(graph.get('trayicon.menu'), TrayIconMenu)
Beispiel #2
0
def app():
    config = Configurator()
    config.include('pyramid_wiring')

    graph = Graph()
    graph.register_scope(RequestScope, RequestScope())
    class Counter(object):
        def __init__(self):
            self.count = 1
    graph.register_provider('counter', FactoryProvider(Counter, scope=RequestScope))
    config.set_object_graph(graph)

    def count(request, counter=injected('counter')):
        # Increment the counter
        count = counter.count
        counter.count += 1

        # Get the counter from the graph again and make sure it's the same
        assert graph.get('counter') is counter

        return count
    config.add_route('count', '/count')
    config.add_view(count, route_name='count', renderer='string')

    return TestApp(config.make_wsgi_app())
Beispiel #3
0
def get_application():
    graph = Graph()
    graph.register_scope(RequestScope, RequestScope())
    graph.register_instance(Graph, graph)
    GuestbookModule().add_to(graph)
    graph.validate()
    return graph.get('wsgi.application')
Beispiel #4
0
    def test_module(self):
        from tomate.signals import SignalsProvider, TomateNamespace

        graph = Graph()

        self.assertEqual(['tomate.signals'], SignalsProvider.providers.keys())
        SignalsProvider().add_to(graph)

        provider = graph.providers['tomate.signals']

        self.assertIsInstance(provider, InstanceProvider)
        self.assertEqual(provider.scope, None)
        self.assertEqual(provider.dependencies, {})

        self.assertIsInstance(graph.get('tomate.signals'), TomateNamespace)
Beispiel #5
0
def test_view_mapping(view):
    config = Configurator()
    config.include('pyramid_wiring')

    # Create a graph with the message.
    graph = Graph()
    graph.register_instance('hello', "Hello, world!")
    config.set_object_graph(graph)

    # Add the view.
    config.add_route('test', '/')
    args = dict(route_name='test', renderer='string')
    if hasattr(view, 'attr'):
        args['attr'] = 'attr'
    config.add_view(view, **args)

    app = TestApp(config.make_wsgi_app())
    assert app.get('/').body == b"Hello, world!"
Beispiel #6
0
    def test_module(self):
        from tomate.config import Config, ConfigProvider

        graph = Graph()

        self.assertEqual(['tomate.config'], ConfigProvider.providers.keys())
        ConfigProvider().add_to(graph)

        self.assertIn('config.parser', graph.providers.keys())

        provider = graph.providers['tomate.config']

        self.assertIsInstance(provider, FactoryProvider)
        self.assertEqual(provider.scope, SingletonScope)
        self.assertEqual(provider.dependencies,
                         dict(parser='config.parser', signals='tomate.signals'))

        graph.register_instance('tomate.signals', Mock())
        self.assertIsInstance(graph.get('tomate.config'), Config)
Beispiel #7
0
def test_menu_module():
    from tomate_gtk.widgets.menu import TrayIconMenu

    assert sorted(MenuModule.providers.keys()) == sorted(['view.menu', 'trayicon.menu'])

    graph = Graph()
    MenuModule().add_to(graph)

    provider = graph.providers['view.menu']

    assert 'view.menu' in graph.providers.keys()

    assert isinstance(provider, FactoryProvider)
    assert provider.scope == SingletonScope

    assert provider.dependencies == {'lazy_proxy': 'tomate.proxy',
                                     'about': 'view.about',
                                     'preference': 'view.preference'}

    graph.register_instance('tomate.view', Mock())

    assert isinstance(graph.get('trayicon.menu'), TrayIconMenu)
Beispiel #8
0
    def test_factory(self, *args):
        from tomate.app import Application, application_factory

        graph = Graph()
        graph.register_factory('tomate.view', Mock)
        graph.register_factory('tomate.config', Mock)
        graph.register_factory('tomate.plugin', Mock)

        graph.register_factory('tomate.app', Application)

        app = application_factory(graph)
        self.assertIsInstance(app, Application)

        with patch('tomate.app.dbus.SessionBus.return_value.request_name',
                   return_value=dbus.bus.REQUEST_NAME_REPLY_EXISTS):
            dbus_app = application_factory(graph)
            self.assertIsInstance(dbus_app, dbus.Interface)
Beispiel #9
0
    def test_module(self):
        from tomate.session import Session, SessionProvider

        graph = Graph()

        self.assertEqual(['tomate.session'], SessionProvider.providers.keys())
        SessionProvider().add_to(graph)

        provider = graph.providers['tomate.session']

        self.assertIsInstance(provider, FactoryProvider)
        self.assertEqual(provider.scope, SingletonScope)
        self.assertEqual(provider.dependencies,
                         dict(signals='tomate.signals',
                              config='tomate.config',
                              timer='tomate.timer'))

        graph.register_instance('tomate.signals', Mock())
        graph.register_instance('tomate.timer', Mock())
        graph.register_instance('tomate.config', Mock())
        self.assertIsInstance(graph.get('tomate.session'), Session)
Beispiel #10
0
def test_module():
    from tomate_gtk.view import ViewModule

    assert list(ViewModule.providers.keys()) == ['tomate.view']

    graph = Graph()
    ViewModule().add_to(graph)
    provider = graph.providers['tomate.view']

    assert isinstance(provider, FactoryProvider)
    assert SingletonScope == provider.scope

    dependencies = dict(session='tomate.session',
                        events='tomate.events',
                        config='tomate.config',
                        graph=Graph,
                        toolbar='view.toolbar',
                        timerframe='view.timerframe',
                        taskbutton='view.taskbutton')

    assert provider.dependencies == dependencies
Beispiel #11
0
def graph() -> Graph:
    g = Graph()
    g.register_instance(Graph, g)
    return g
Beispiel #12
0
def test_module():
    graph = Graph()

    scan_to_graph(["tomate.pomodoro.graph"], graph)

    assert isinstance(graph.get(Graph), Graph)
def graph() -> Graph:
    instance = Graph()
    instance.register_instance(Graph, instance)
    return instance
 def configure(self, bus: Bus, graph: Graph) -> None:
     super().configure(bus, graph)
     self.config = graph.get("focusyn.config")
Beispiel #15
0
from wiring import Graph
from wiring.scanning import register

graph = Graph()
register.instance(Graph)(graph)