Example #1
0
def test_main():
    app = App()
    stderr = StringIO()
    debugger = Debugger(file=stderr)
    debugger.register(app)
    while app:
        app.flush()
    stderr.seek(0)
    stderr.truncate()

    assert debugger._events

    e = Event()
    app.fire(e)
    app.flush()
    stderr.seek(0)
    s = stderr.read().strip()
    assert s == str(e)
    stderr.seek(0)
    stderr.truncate()

    debugger._events = False
    assert not debugger._events

    e = Event()
    app.fire(e)

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == ""
    stderr.seek(0)
    stderr.truncate()
Example #2
0
def test_file(tmpdir):
    logfile = str(tmpdir.ensure("debug.log"))
    stderr = open(logfile, "w+")

    app = App()
    debugger = Debugger(file=stderr)
    debugger.register(app)
    while app:
        app.flush()
    stderr.seek(0)
    stderr.truncate()

    assert debugger._events

    e = Event()
    app.fire(e)
    app.flush()

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == str(e)
    stderr.seek(0)
    stderr.truncate()

    debugger._events = False
    assert not debugger._events

    e = Event()
    app.fire(e)

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == ""
    stderr.seek(0)
    stderr.truncate()
Example #3
0
def test_IgnoreChannels():
    app = App()
    stderr = StringIO()
    debugger = Debugger(file=stderr)
    debugger.register(app)
    while app:
        app.flush()
    stderr.seek(0)
    stderr.truncate()

    assert debugger._events
    debugger.IgnoreChannels.extend([("*", "test")])

    e = Event()
    app.fire(e)
    app.flush()

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == str(e)
    stderr.seek(0)
    stderr.truncate()

    e = test()
    app.fire(e)
    app.flush()

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == ""
    stderr.seek(0)
    stderr.truncate()
Example #4
0
    def testIgnoreEvents(self):
        """Test Debugger's IgnoreEvents

        Test Debugger's IgnoreEvents
        """

        manager = Manager()
        debugger = Debugger()
        foo = Foo()

        manager += debugger
        manager += foo

        debugger.IgnoreEvents.extend([Test])
        debugger.events = True

        e = Event()
        manager.send(e, "foo")
        sys.stderr.seek(0)
        s = sys.stderr.read().strip()
        self.assertEquals(s, str(e))

        sys.stderr.seek(0)
        sys.stderr.truncate()

        e = Test()
        manager.send(e, "foo")
        sys.stderr.seek(0)
        s = sys.stderr.read().strip()
        self.assertEquals(s, "")

        sys.stderr.seek(0)
        sys.stderr.truncate()
        foo.unregister()
Example #5
0
    def testDebugger(self):
        """Test Debugger

        Test Debugger
        """

        manager = Manager()
        debugger = Debugger()
        foo = Foo()

        manager += debugger
        manager += foo

        debugger.events = True
        e = Event()
        manager.send(e, "foo")
        sys.stderr.seek(0)
        s = sys.stderr.read().strip()
        self.assertEquals(s, str(e))

        sys.stderr.seek(0)
        sys.stderr.truncate()

        debugger.events = False
        e = Event()
        manager.send(e, "foo")
        sys.stderr.seek(0)
        s = sys.stderr.read().strip()
        self.assertEquals(s, "")

        sys.stderr.seek(0)
        sys.stderr.truncate()
Example #6
0
def test_Logger_debug():
    app = App()
    logger = Logger()
    debugger = Debugger(logger=logger)
    debugger.register(app)
    while app:
        app.flush()

    e = Event()
    app.fire(e)
    app.flush()

    assert logger.debug_msg == repr(e)
Example #7
0
def test_Logger_error():
    app = App()
    logger = Logger()
    debugger = Debugger(logger=logger)
    debugger.register(app)
    while app:
        app.flush()

    e = test(raiseException=True)
    app.fire(e)
    while app:
        app.flush()

    assert logger.error_msg.startswith("ERROR <handler[*][test] (App.test)> (")
Example #8
0
def test_exceptions():
    app = App()
    stderr = StringIO()
    debugger = Debugger(file=stderr)
    debugger.register(app)
    while app:
        app.flush()
    stderr.seek(0)
    stderr.truncate()

    assert debugger._events
    assert debugger._errors

    e = test(raiseException=True)
    app.fire(e)
    app.flush()

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == str(e)
    stderr.seek(0)
    stderr.truncate()

    app.flush()
    stderr.seek(0)
    s = stderr.read().strip()
    assert s.startswith("<exception[*]")
    stderr.seek(0)
    stderr.truncate()

    debugger._events = False
    debugger._errors = False

    assert not debugger._events
    assert not debugger._errors

    e = test(raiseException=True)
    app.fire(e)
    app.flush()

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == ""
    stderr.seek(0)
    stderr.truncate()

    app.flush()
    stderr.seek(0)
    s = stderr.read().strip()
    assert s == ""
Example #9
0
def test_filename(tmpdir):
    if "__pypy__" in sys.modules:
        pytest.skip("Broken on pypy")

    logfile = str(tmpdir.ensure("debug.log"))
    stderr = open(logfile, "r+")

    app = App()
    debugger = Debugger(file=logfile)
    debugger.register(app)
    while app:
        app.flush()
    stderr.seek(0)
    stderr.truncate()

    assert debugger._events

    e = Event()
    app.fire(e)
    app.flush()

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == str(e)
    stderr.seek(0)
    stderr.truncate()

    debugger._events = False
    assert not debugger._events

    e = Event()
    app.fire(e)

    stderr.seek(0)
    s = stderr.read().strip()
    assert s == ""
    stderr.seek(0)
    stderr.truncate()