예제 #1
0
파일: test_monitor.py 프로젝트: yerejm/ttt
    def test_poll_build_test(self):
        reporter = MagicMock(spec=Reporter)
        watcher = MagicMock()
        builder = MagicMock()
        executor = MagicMock()
        watcher.poll = MagicMock(
            return_value=WatchState(set(["change"]), set(), set(), 0)
        )
        executor.test = MagicMock(return_value={"total_failed": 0})
        m = Monitor(watcher, builder, executor, [reporter], interval=0)

        m.run(step=True)

        assert "poll" in [c for c, a, kw in watcher.mock_calls]
        # build step is captured as ''
        assert [c for c, a, kw in builder.mock_calls] == [""]
        assert [c for c, a, kw in executor.mock_calls] == ["test"]
        assert [c for c, a, kw in reporter.mock_calls] == [
            "report_watchstate",
            "session_start",  # build
            "report_build_path",
            "session_end",  # build
            "session_start",  # test
            "report_results",
            "session_end",  # test
            "wait_change",
        ]
예제 #2
0
파일: test_monitor.py 프로젝트: yerejm/ttt
    def test_keyboardinterrupt_during_wait(self):
        reporter = MagicMock(spec=Reporter)
        o = watcher = builder = executor = MagicMock()
        watcher.poll = MagicMock(return_value=WatchState(set(), set(), set(), 0))
        m = Monitor(watcher, builder, executor, [reporter], interval=0)

        o.reset_mock()
        with patch("time.sleep", autospec=True, side_effect=KeyboardInterrupt):
            m.run(step=True)

        call_filter = set(["interrupt_detected", "halt"])
        calls = [c for c, a, kw in reporter.method_calls if c in call_filter]
        assert calls == ["interrupt_detected", "halt"]
예제 #3
0
파일: test_monitor.py 프로젝트: yerejm/ttt
    def test_keyboardinterrupt_during_operations(self):
        def builder():
            raise KeyboardInterrupt

        reporter = MagicMock(spec=Reporter)
        o = watcher = executor = MagicMock()
        watcher.poll = MagicMock(
            return_value=WatchState(set(["change"]), set(), set(), 0)
        )
        m = Monitor(watcher, builder, executor, [reporter], interval=0)

        o.reset_mock()
        m.run(step=True)

        assert "interrupt_detected" in set([c for c, a, kw in reporter.method_calls])
예제 #4
0
파일: test_monitor.py 프로젝트: yerejm/ttt
    def test_test_again_on_fix(self):
        reporter = MagicMock(spec=Reporter)
        o = watcher = builder = executor = MagicMock()
        watcher.poll = MagicMock(
            return_value=WatchState(set(["change"]), set(), set(), 0)
        )
        executor.test = MagicMock(return_value={"total_failed": 1})
        m = Monitor(watcher, builder, executor, [reporter], interval=0)
        m.run(step=True)

        o.reset_mock()

        executor.test = MagicMock(return_value={"total_failed": 0})

        m.run(step=True)

        assert len([c for c, a, kw in o.method_calls if c == "test"]) == 2
예제 #5
0
파일: test_reporter.py 프로젝트: yerejm/ttt
    def test_report_watchstate(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path=None, build_path=None, terminal=Terminal(stream=f)
        )

        r.report_watchstate(WatchState(["create"], ["delete"], ["modify"], 1.0))
        assert (
            f.getvalue()
            == os.linesep.join(
                [
                    termstyle.green("# CREATED create"),
                    termstyle.yellow("# MODIFIED modify"),
                    termstyle.red("# DELETED delete"),
                    "### Scan time:      1.000s",
                ]
            )
            + os.linesep
        )
예제 #6
0
파일: test_monitor.py 프로젝트: yerejm/ttt
    def test_builderror(self):
        import subprocess

        def builder():
            subprocess.check_output("false")

        reporter = MagicMock(spec=Reporter)
        o = watcher = executor = MagicMock()
        watcher.poll = MagicMock(
            return_value=WatchState(set(["change"]), set(), set(), 0)
        )
        m = Monitor(watcher, builder, executor, [reporter], interval=0)

        o.reset_mock()
        m.run(step=True)

        calls = set([c for c, a, kw in o.method_calls])
        assert "test" not in calls
        assert "report_build_failure" in [c for c, a, kw in reporter.method_calls]
예제 #7
0
파일: test_monitor.py 프로젝트: yerejm/ttt
    def test_keyboardinterrupt_during_poll(self):
        reporter = MagicMock(spec=Reporter)
        watcher = MagicMock()
        o = builder = executor = MagicMock()
        m = Monitor(watcher, builder, executor, [reporter], interval=0)

        o.reset_mock()

        watcher.poll = MagicMock(
            return_value=WatchState(set(["change"]), set(), set(), 0),
            side_effect=KeyboardInterrupt,
        )

        m.run(step=True)

        assert "poll" in [c for c, a, kw in watcher.method_calls]
        assert [c for c, a, kw in reporter.method_calls] == [
            "interrupt_detected"
        ]  # noqa