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 )
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
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)
def test_writeln_decorator(self): f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", decorator=[bold]) assert f.getvalue() == bold("hello") + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", decorator=[bold, red]) assert f.getvalue() == red(bold("hello")) + linesep
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
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 )
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 )
def test_writeln_padding_default_width(self): f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', pad='.') assert f.getvalue() == (''.ljust(35, '.') + ' hello ' + ''.ljust(36, '.') + linesep) f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', pad='.', width=0) assert f.getvalue() == 'hello' + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', pad='.', width=200) assert f.getvalue() == (''.ljust(35, '.') + ' hello ' + ''.ljust(36, '.') + linesep)
def test_writeln_decorator(self): f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', decorator=[bold]) assert f.getvalue() == bold('hello') + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', decorator=[bold, red]) assert f.getvalue() == red(bold('hello')) + linesep
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 )
def __init__(self, source, executable, term=None): """Creates a representation of a GTest binary. :param source: Path of the test source file :param executable: Path of the test executable :param term: (optional) Terminal object to send output of test execution. Default Terminal() will send no output. """ if not source: raise Exception("Invalid source") if not executable: raise Exception("Invalid executable") self._source = source self._executable = executable self._term = term if term else Terminal() self.reset()
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 )
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
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 )
def test_writeln_line_end(self): f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", end="") assert f.getvalue() == "hello"
def test_writeln_verbosity(self): f = io.StringIO() t = Terminal(stream=f, verbosity=1) t.writeln("hello", verbose=2) assert f.getvalue() == "" f = io.StringIO() t = Terminal(stream=f, verbosity=1) t.writeln("hello", verbose=1) assert f.getvalue() == "hello" + linesep f = io.StringIO() t = Terminal(stream=f, verbosity=1) t.writeln("hello") assert f.getvalue() == "hello" + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln("2", verbose=2) t.writeln("1", verbose=1) t.writeln("hello") assert f.getvalue() == "hello" + linesep
def test_writeln(self): f = io.StringIO() t = Terminal(stream=f) t.writeln() assert f.getvalue() == linesep f = io.StringIO() t = Terminal(stream=f) t.writeln("hello") assert f.getvalue() == "hello" + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", 1) assert f.getvalue() == "hello1" + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", "world") assert f.getvalue() == "helloworld" + linesep
def test_writeln_verbosity(self): f = io.StringIO() t = Terminal(stream=f, verbosity=1) t.writeln('hello', verbose=2) assert f.getvalue() == '' f = io.StringIO() t = Terminal(stream=f, verbosity=1) t.writeln('hello', verbose=1) assert f.getvalue() == 'hello' + linesep f = io.StringIO() t = Terminal(stream=f, verbosity=1) t.writeln('hello') assert f.getvalue() == 'hello' + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln('2', verbose=2) t.writeln('1', verbose=1) t.writeln('hello') assert f.getvalue() == 'hello' + linesep
def test_write(self): f = io.StringIO() t = Terminal(stream=f) t.write("hello") assert f.getvalue() == "hello"
def test_writeln_padding(self): f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', pad='.', width=15) assert f.getvalue() == '.... hello ....' + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', 'world', pad='.', width=15) assert f.getvalue() == '. helloworld ..' + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', pad='') assert f.getvalue() == 'hello' + linesep f = io.StringIO() t = Terminal(stream=f) raised = False try: t.writeln('hello', pad='', width=15) except Exception as e: raised = e assert raised
def test_write(self): f = io.StringIO() t = Terminal(stream=f) t.write('hello') assert f.getvalue() == 'hello'
def test_writeln(self): f = io.StringIO() t = Terminal(stream=f) t.writeln() assert f.getvalue() == linesep f = io.StringIO() t = Terminal(stream=f) t.writeln('hello') assert f.getvalue() == 'hello' + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', 1) assert f.getvalue() == 'hello1' + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', 'world') assert f.getvalue() == 'helloworld' + linesep
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)
def test_writeln_padding(self): f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", pad=".", width=15) assert f.getvalue() == ".... hello ...." + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", "world", pad=".", width=15) assert f.getvalue() == ". helloworld .." + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", pad="") assert f.getvalue() == "hello" + linesep f = io.StringIO() t = Terminal(stream=f) raised = False try: t.writeln("hello", pad="", width=15) except Exception as e: raised = e assert raised
def test_writeln_line_end(self): f = io.StringIO() t = Terminal(stream=f) t.writeln('hello', end='') assert f.getvalue() == 'hello'
def test_writeln_padding_default_width(self): f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", pad=".") assert f.getvalue() == ( "".ljust(35, ".") + " hello " + "".ljust(36, ".") + linesep ) f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", pad=".", width=0) assert f.getvalue() == "hello" + linesep f = io.StringIO() t = Terminal(stream=f) t.writeln("hello", pad=".", width=200) assert f.getvalue() == ( "".ljust(35, ".") + " hello " + "".ljust(36, ".") + linesep )
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