Exemplo n.º 1
0
    def test_report_multiple_failed(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path='/path',
                             build_path=None,
                             terminal=Terminal(stream=f))

        results = {
                'total_runtime': 2.09,
                'total_passed': 0,
                'total_failed': 2,
                'failures': [
                    [
                        'fail1',
                        [
                             '/path/to/file:12: blah',
                             'results line 2',
                             'results line 3',
                             'results line 4',
                        ], [], FAILED
                    ],
                    [
                        'fail2',
                        [
                             '/path/to/file:102: blah',
                             'results line 2',
                             'results line 3',
                             'results line 4',
                        ], [], FAILED
                    ],
                ]
            }
        r.report_results(results)
        expected = [
            '================================== FAILURES ==================================', # noqa
            termstyle.bold(termstyle.red(
            '___________________________________ fail1 ____________________________________' # noqa
            )),
            '/path/to/file:12: blah',
            'results line 2',
            'results line 3',
            'results line 4',
            termstyle.bold(termstyle.red(
            '_________________________________ to/file:12 _________________________________' # noqa
            )),
            termstyle.bold(termstyle.red(
            '___________________________________ fail2 ____________________________________' # noqa
            )),
            '/path/to/file:102: blah',
            'results line 2',
            'results line 3',
            'results line 4',
            termstyle.bold(termstyle.red(
            '________________________________ to/file:102 _________________________________' # noqa
            )),
            termstyle.bold(termstyle.red(
            '===================== 2 failed, 0 passed in 2.09 seconds =====================' # noqa
            )),
            ]
        actual = f.getvalue().splitlines()
        assert actual == expected
Exemplo n.º 2
0
    def test_wait_change(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path="watch_path",
            build_path="build_path",
            terminal=Terminal(stream=f),
            timestamp=lambda: "timestamp",
        )

        r.wait_change()
        assert (
            f.getvalue()
            == termstyle.bold(
                "".ljust(28, "#") + " waiting for changes " + "".ljust(29, "#")
            )
            + os.linesep
            + termstyle.bold("### Since:      timestamp")
            + os.linesep
            + termstyle.bold("### Watching:   watch_path")
            + os.linesep
            + termstyle.bold("### Build at:   build_path")
            + os.linesep
            + termstyle.bold("### Using {}:  {}".format(__progname__, __version__))
            + os.linesep
        )
Exemplo n.º 3
0
    def test_path_stripping_in_test_failure_last_line(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path='/path/to/watch',
                             build_path='/path/to/build',
                             terminal=Terminal(stream=f))

        failures = [[
                        'core.ok',
                        [
                            '/path/to/watch/test/test_core.cc:12: Failure',
                            'Value of: 2',
                            'Expected: ok()',
                            'Which is: 42',
                        ], [], FAILED
                    ]]
        r.report_failures(failures)
        expected = [
            '================================== FAILURES ==================================', # noqa
            termstyle.bold(termstyle.red(
            '__________________________________ core.ok ___________________________________' # noqa
            )),
            '/path/to/watch/test/test_core.cc:12: Failure',
            'Value of: 2',
            'Expected: ok()',
            'Which is: 42',
            termstyle.bold(termstyle.red(
            '____________________________ test/test_core.cc:12 ____________________________', # noqa
            )),
            ]
        actual = f.getvalue().splitlines()
        assert actual == expected
Exemplo n.º 4
0
    def test_interrupt_detected(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path=None, build_path=None, terminal=Terminal(stream=f)
        )

        r.interrupt_detected()
        assert f.getvalue() == (os.linesep + "Interrupt again to exit." + os.linesep)
Exemplo n.º 5
0
    def test_halt(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path=None,
                             build_path=None,
                             terminal=Terminal(stream=f))

        r.halt()
        assert f.getvalue() == os.linesep + 'Watching stopped.' + os.linesep
Exemplo n.º 6
0
    def test_halt(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path=None, build_path=None, terminal=Terminal(stream=f)
        )

        r.halt()
        assert f.getvalue() == os.linesep + "Watching stopped." + os.linesep
Exemplo n.º 7
0
    def test_report_build_path(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path='watch_path',
                             build_path='build_path',
                             terminal=Terminal(stream=f))

        r.report_build_path()
        assert f.getvalue() == (termstyle.bold('### Building:   build_path')
                                + os.linesep)
Exemplo n.º 8
0
    def test_interrupt_detected(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path=None,
                             build_path=None,
                             terminal=Terminal(stream=f))

        r.interrupt_detected()
        assert f.getvalue() == (os.linesep + 'Interrupt again to exit.'
                                + os.linesep)
Exemplo n.º 9
0
    def test_report_with_stdout_and_stderr_in_additional_output(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path="/path", build_path=None, terminal=Terminal(stream=f)
        )

        results = {
            "total_runtime": 2.09,
            "total_passed": 0,
            "total_failed": 1,
            "failures": [
                [
                    "fail1",
                    [
                        "extra line 1",
                        "extra line 2",
                        "/path/to/file:12: blah",
                        "results line 1",
                        "results line 2",
                        "results line 3",
                    ],
                    [],
                    FAILED,
                ],
            ],
        }
        r.report_results(results)
        expected = [
            "================================== FAILURES ==================================",  # noqa
            termstyle.bold(
                termstyle.red(
                    "___________________________________ fail1 ____________________________________"  # noqa
                )
            ),
            "/path/to/file:12: blah",
            "results line 1",
            "results line 2",
            "results line 3",
            "----------------------------- Additional output ------------------------------",  # noqa
            "extra line 1",
            "extra line 2",
            termstyle.bold(
                termstyle.red(
                    "_________________________________ to/file:12 _________________________________"  # noqa
                )
            ),
            termstyle.bold(
                termstyle.red(
                    "===================== 1 failed, 0 passed in 2.09 seconds ====================="  # noqa
                )
            ),
        ]
        actual = f.getvalue().splitlines()
        assert actual == expected
Exemplo n.º 10
0
    def test_session_start(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path=None,
                             build_path=None,
                             terminal=Terminal(stream=f))

        r.session_start('test')
        assert f.getvalue() == (termstyle.bold(''.ljust(28, '=')
                                               + ' test session starts '
                                               + ''.ljust(29, '='))
                                + os.linesep)
Exemplo n.º 11
0
    def test_report_build_path(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path="watch_path",
            build_path="build_path",
            terminal=Terminal(stream=f),
        )

        r.report_build_path()
        assert f.getvalue() == (
            termstyle.bold("### Building:   build_path") + os.linesep
        )
Exemplo n.º 12
0
    def test_session_start(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path=None, build_path=None, terminal=Terminal(stream=f)
        )

        r.session_start("test")
        assert f.getvalue() == (
            termstyle.bold(
                "".ljust(28, "=") + " test session starts " + "".ljust(29, "=")
            )
            + os.linesep
        )
Exemplo n.º 13
0
    def test_report_interrupt(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path='watch_path',
                             build_path='build_path',
                             terminal=Terminal(stream=f))

        try:
            raise KeyboardInterrupt()
        except KeyboardInterrupt as e:
            r.report_interrupt(e)

        assert f.getvalue() == (''.ljust(29, '!')
                                + ' KeyboardInterrupt '
                                + ''.ljust(30, '!')
                                + os.linesep)
Exemplo n.º 14
0
    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
Exemplo n.º 15
0
    def test_report_interrupt(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path="watch_path",
            build_path="build_path",
            terminal=Terminal(stream=f),
        )

        try:
            raise KeyboardInterrupt()
        except KeyboardInterrupt as e:
            r.report_interrupt(e)

        assert f.getvalue() == (
            "".ljust(29, "!") + " KeyboardInterrupt " + "".ljust(30, "!") + os.linesep
        )
Exemplo n.º 16
0
    def test_report_with_stdout_and_stderr_in_additional_output(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path='/path',
                             build_path=None,
                             terminal=Terminal(stream=f))

        results = {
                'total_runtime': 2.09,
                'total_passed': 0,
                'total_failed': 1,
                'failures': [
                    [
                        'fail1',
                        [
                            'extra line 1',
                            'extra line 2',
                            '/path/to/file:12: blah',
                            'results line 1',
                            'results line 2',
                            'results line 3',
                        ], [], FAILED
                    ],
                ]
            }
        r.report_results(results)
        expected = [
            '================================== FAILURES ==================================', # noqa
            termstyle.bold(termstyle.red(
            '___________________________________ fail1 ____________________________________' # noqa
            )),
            '/path/to/file:12: blah',
            'results line 1',
            'results line 2',
            'results line 3',
            '----------------------------- Additional output ------------------------------', # noqa
            'extra line 1',
            'extra line 2',
            termstyle.bold(termstyle.red(
            '_________________________________ to/file:12 _________________________________' # noqa
            )),
            termstyle.bold(termstyle.red(
            '===================== 1 failed, 0 passed in 2.09 seconds =====================' # noqa
            )),
            ]
        actual = f.getvalue().splitlines()
        assert actual == expected
Exemplo n.º 17
0
    def test_report_all_passed(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path=None,
                             build_path=None,
                             terminal=Terminal(stream=f))

        results = {
                'total_runtime': 2.09,
                'total_passed': 1,
                'total_failed': 0,
                'failures': []
                }
        r.report_results(results)
        assert f.getvalue() == (
            termstyle.bold(termstyle.green(''.ljust(26, '=')
                           + ' 1 passed in 2.09 seconds '
                           + ''.ljust(26, '=')))
            + os.linesep)
Exemplo n.º 18
0
    def test_wait_change(self):
        f = io.StringIO()
        r = TerminalReporter(watch_path='watch_path',
                             build_path='build_path',
                             terminal=Terminal(stream=f),
                             timestamp=lambda: 'timestamp')

        r.wait_change()
        assert f.getvalue() == termstyle.bold(
                    ''.ljust(28, '#') +
                    ' waiting for changes ' +
                    ''.ljust(29, '#')
                ) + os.linesep + termstyle.bold(
                    '### Since:      timestamp'
                ) + os.linesep + termstyle.bold(
                    '### Watching:   watch_path'
                ) + os.linesep + termstyle.bold(
                    '### Build at:   build_path'
                ) + os.linesep
Exemplo n.º 19
0
    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
        )
Exemplo n.º 20
0
    def test_path_stripping_in_test_failure_last_line(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path="/path/to/watch",
            build_path="/path/to/build",
            terminal=Terminal(stream=f),
        )

        failures = [
            [
                "core.ok",
                [
                    "/path/to/watch/test/test_core.cc:12: Failure",
                    "Value of: 2",
                    "Expected: ok()",
                    "Which is: 42",
                ],
                [],
                FAILED,
            ]
        ]
        r.report_failures(failures)
        expected = [
            "================================== FAILURES ==================================",  # noqa
            termstyle.bold(
                termstyle.red(
                    "__________________________________ core.ok ___________________________________"  # noqa
                )
            ),
            "/path/to/watch/test/test_core.cc:12: Failure",
            "Value of: 2",
            "Expected: ok()",
            "Which is: 42",
            termstyle.bold(
                termstyle.red(
                    "____________________________ test/test_core.cc:12 ____________________________",  # noqa
                )
            ),
        ]
        actual = f.getvalue().splitlines()
        assert actual == expected
Exemplo n.º 21
0
    def test_report_all_passed(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path=None, build_path=None, terminal=Terminal(stream=f)
        )

        results = {
            "total_runtime": 2.09,
            "total_passed": 1,
            "total_failed": 0,
            "failures": [],
        }
        r.report_results(results)
        assert f.getvalue() == (
            termstyle.bold(
                termstyle.green(
                    "".ljust(26, "=") + " 1 passed in 2.09 seconds " + "".ljust(26, "=")
                )
            )
            + os.linesep
        )
Exemplo n.º 22
0
def create_monitor(watch_path=None, patterns=None, **kwargs):
    """Creates a monitor and its subordinate objects.

    By default, one reporter object is created to output to the terminal.
    An optional IRC reporter may be created if irc_server is provided.

    :param watch_path: (optional) the root of the source tree, either relative
        or absolute. If not provided, the current working directory is assumed
        to be the root of the source tree.
    :param patterns: (optional) a list of file names or patterns that identify
        the files to be tracked. By default, all files are tracked unless this
        list is specified and not empty.
    :param build_path: (optional) the desired build path. May be relative. If
        not provided, it will be generated from the watch path.
    :param generator: (optional) the cmake build system generator
    :param defines: (optional) list of var=val strings for CMake's -D option
    :param irc_server: (optional) the IRC server host if an IRC reporter is
        required.
    :param irc_port (optional) the IRC server port. Has no meaning without
        irc_server.
    :param irc_channel (optional) the IRC channel to join once connected. Has
        no meaning without irc_server.
    :param irc_nick (optional) the IRC nickname to use once connected. Has
        no meaning without irc_server.
    """
    build_config = kwargs.pop("config", None)
    generator = kwargs.pop("generator", None)
    watch_path = make_watch_path(watch_path)
    build_path = make_build_path(kwargs.pop("build_path", None), watch_path,
                                 build_config)
    term = Terminal(stream=sys.stdout)
    exclusions = kwargs.pop("exclude", [])
    watcher = Watcher(watch_path, build_path, patterns, exclusions, term)

    run_tests = kwargs.pop("test", False)
    defines = kwargs.pop("define", [])
    clean = kwargs.pop("clean", False)
    if run_tests:
        if defines is None:
            defines = []
        defines.append("ENABLE_TESTS=ON")
    builder = create_builder(watch_path, build_path, generator, build_config,
                             defines, term, clean)

    reporters = [TerminalReporter(watch_path, build_path)]

    irc_server = kwargs.pop("irc_server", None)
    if irc_server:
        irc = IRCClient(
            (kwargs.pop("irc_channel", None)
             or "#{}-{}".format(__progname__, os.path.basename(watch_path))),
            (kwargs.pop("irc_nick", None)
             or "{}_{}".format(platform.system(), build_config)),
            irc_server,
            kwargs.pop("irc_port", None),
        )
        # print('{}@{}:{}/{}'.format(
        #     irc._nickname, irc.server.host, irc.server.port, irc.channel)
        # )
        r = IRCReporter(irc)
        reporters.append(r)

    executor = Executor() if run_tests else None
    return Monitor(watcher, builder, executor, reporters)
Exemplo n.º 23
0
    def test_report_multiple_failed(self):
        f = io.StringIO()
        r = TerminalReporter(
            watch_path="/path", build_path=None, terminal=Terminal(stream=f)
        )

        results = {
            "total_runtime": 2.09,
            "total_passed": 0,
            "total_failed": 2,
            "failures": [
                [
                    "fail1",
                    [
                        "/path/to/file:12: blah",
                        "results line 2",
                        "results line 3",
                        "results line 4",
                    ],
                    [],
                    FAILED,
                ],
                [
                    "fail2",
                    [
                        "/path/to/file:102: blah",
                        "results line 2",
                        "results line 3",
                        "results line 4",
                    ],
                    [],
                    FAILED,
                ],
            ],
        }
        r.report_results(results)
        expected = [
            "================================== FAILURES ==================================",  # noqa
            termstyle.bold(
                termstyle.red(
                    "___________________________________ fail1 ____________________________________"  # noqa
                )
            ),
            "/path/to/file:12: blah",
            "results line 2",
            "results line 3",
            "results line 4",
            termstyle.bold(
                termstyle.red(
                    "_________________________________ to/file:12 _________________________________"  # noqa
                )
            ),
            termstyle.bold(
                termstyle.red(
                    "___________________________________ fail2 ____________________________________"  # noqa
                )
            ),
            "/path/to/file:102: blah",
            "results line 2",
            "results line 3",
            "results line 4",
            termstyle.bold(
                termstyle.red(
                    "________________________________ to/file:102 _________________________________"  # noqa
                )
            ),
            termstyle.bold(
                termstyle.red(
                    "===================== 2 failed, 0 passed in 2.09 seconds ====================="  # noqa
                )
            ),
        ]
        actual = f.getvalue().splitlines()
        assert actual == expected