Ejemplo n.º 1
0
def test_runner_log(patches):
    run = runner.Runner("path1", "path2", "path3")
    patched = patches("logging.getLogger",
                      "logging.StreamHandler",
                      "LogFilter",
                      ("Runner.log_level", dict(new_callable=PropertyMock)),
                      ("Runner.name", dict(new_callable=PropertyMock)),
                      prefix="tools.base.runner")

    with patched as (m_logger, m_stream, m_filter, m_level, m_name):
        loggers = (MagicMock(), MagicMock())
        m_stream.side_effect = loggers
        assert run.log == m_logger.return_value
    assert (list(m_logger.return_value.setLevel.call_args) == [
        (m_level.return_value, ), {}
    ])
    assert (list(list(c) for c in m_stream.call_args_list) == [[(sys.stdout, ),
                                                                {}],
                                                               [(sys.stderr, ),
                                                                {}]])
    assert (list(loggers[0].setLevel.call_args) == [(logging.DEBUG, ), {}])
    assert (list(loggers[0].addFilter.call_args) == [(m_filter.return_value, ),
                                                     {}])
    assert (list(loggers[1].setLevel.call_args) == [(logging.WARN, ), {}])
    assert (list(
        list(c) for c in m_logger.return_value.addHandler.call_args_list) == [[
            (loggers[0], ), {}
        ], [(loggers[1], ), {}]])
    assert "log" in run.__dict__
Ejemplo n.º 2
0
def test_runner_log(patches):
    run = runner.Runner("path1", "path2", "path3")
    patched = patches(
        "logging.getLogger",
        "LogFilter",
        "coloredlogs",
        "verboselogs", ("Runner.log_level", dict(new_callable=PropertyMock)),
        ("Runner.log_level_styles", dict(new_callable=PropertyMock)),
        ("Runner.log_field_styles", dict(new_callable=PropertyMock)),
        ("Runner.log_fmt", dict(new_callable=PropertyMock)),
        ("Runner.name", dict(new_callable=PropertyMock)),
        prefix="tools.base.runner")

    with patched as patchy:
        (m_logger, m_filter, m_color, m_verb, m_level, m_lstyle, m_fstyle,
         m_fmt, m_name) = patchy
        assert run.log == m_logger.return_value

    assert (list(m_verb.install.call_args) == [(), {}])
    assert (list(m_logger.return_value.setLevel.call_args) == [
        (m_level.return_value, ), {}
    ])
    assert (list(m_logger.return_value.setLevel.call_args) == [
        (m_level.return_value, ), {}
    ])
    assert (list(m_color.install.call_args) == [(), {
        'fmt': m_fmt.return_value,
        'isatty': True,
        'field_styles': m_fstyle.return_value,
        'level': 'DEBUG',
        'level_styles': m_lstyle.return_value,
        'logger': m_logger.return_value
    }])
    assert "log" in run.__dict__
Ejemplo n.º 3
0
def test_checker_path():
    run = runner.Runner("path1", "path2", "path3")
    cwd_mock = patch("tools.base.runner.os.getcwd")

    with cwd_mock as m_cwd:
        assert run.path == m_cwd.return_value

    assert (list(m_cwd.call_args) == [(), {}])
Ejemplo n.º 4
0
def test_runner_cleanup(patches):
    run = runner.Runner()
    patched = patches("Runner._cleanup_tempdir", prefix="tools.base.runner")

    with patched as (m_temp, ):
        assert not run.cleanup()

    assert (list(m_temp.call_args) == [(), {}])
Ejemplo n.º 5
0
def test_runner_parser(patches):
    run = runner.Runner("path1", "path2", "path3")
    patched = patches("argparse.ArgumentParser",
                      "Runner.add_arguments",
                      prefix="tools.base.runner")
    with patched as (m_parser, m_add_args):
        assert run.parser == m_parser.return_value

    assert (list(m_parser.call_args) == [(), {"allow_abbrev": False}])
    assert (list(m_add_args.call_args) == [(m_parser.return_value, ), {}])
    assert "parser" in run.__dict__
Ejemplo n.º 6
0
def test_runner_constructor(patches):
    patched = patches("BaseRunner.__init__", prefix="tools.base.runner")
    args = [f"ARG{i}" for i in range(0, 3)]
    kwargs = {f"K{i}": f"V{i}" for i in range(0, 3)}

    with patched as (m_super, ):
        m_super.return_value = None
        run = runner.Runner(*args, **kwargs)

    assert isinstance(run, runner.BaseRunner)
    assert (list(m_super.call_args) == [tuple(args), kwargs])
Ejemplo n.º 7
0
def test_runner_log_level(patches):
    run = runner.Runner("path1", "path2", "path3")
    patched = patches("dict", ("Runner.args", dict(new_callable=PropertyMock)),
                      prefix="tools.base.runner")
    with patched as (m_dict, m_args):
        assert run.log_level == m_dict.return_value.__getitem__.return_value

    assert (list(m_dict.call_args) == [(runner.LOG_LEVELS, ), {}])
    assert (list(m_dict.return_value.__getitem__.call_args) == [
        (m_args.return_value.log_level, ), {}
    ])
    assert "log_level" in run.__dict__
Ejemplo n.º 8
0
def test_runner_add_arguments():
    run = runner.Runner("path1", "path2", "path3")
    parser = MagicMock()

    assert run.add_arguments(parser) is None

    assert (list(list(c) for c in parser.add_argument.call_args_list) == [
        [('--log-level', '-l'), {
            'choices': ['debug', 'info', 'warn', 'error'],
            'default': 'info',
            'help': 'Log level to display'
        }],
    ])
Ejemplo n.º 9
0
def test_runner_extra_args():
    run = runner.Runner("path1", "path2", "path3")
    parser_mock = patch("tools.base.runner.Runner.parser",
                        new_callable=PropertyMock)

    with parser_mock as m_parser:
        assert run.extra_args == m_parser.return_value.parse_known_args.return_value.__getitem__.return_value

    assert (list(m_parser.return_value.parse_known_args.call_args) == [
        (('path1', 'path2', 'path3'), ), {}
    ])
    assert (list(m_parser.return_value.parse_known_args.return_value.
                 __getitem__.call_args) == [(1, ), {}])
    assert "extra_args" in run.__dict__
Ejemplo n.º 10
0
def test_checker_stdout(patches):
    run = runner.Runner("path1", "path2", "path3")

    patched = patches("logging",
                      ("Runner.log_level", dict(new_callable=PropertyMock)),
                      prefix="tools.base.runner")

    with patched as (m_log, m_level):
        assert run.stdout == m_log.getLogger.return_value

    assert (list(m_log.getLogger.call_args) == [('stdout', ), {}])
    assert (list(m_log.getLogger.return_value.setLevel.call_args) == [
        (m_level.return_value, ), {}
    ])
    assert (list(m_log.StreamHandler.call_args) == [(sys.stdout, ), {}])
    assert (list(m_log.Formatter.call_args) == [('%(message)s', ), {}])
    assert (list(m_log.StreamHandler.return_value.setFormatter.call_args) == [
        (m_log.Formatter.return_value, ), {}
    ])
    assert (list(m_log.getLogger.return_value.addHandler.call_args) == [
        (m_log.StreamHandler.return_value, ), {}
    ])
Ejemplo n.º 11
0
def test_runner_constructor():
    run = runner.Runner("path1", "path2", "path3")
    assert run._args == ("path1", "path2", "path3")
Ejemplo n.º 12
0
def test_runner_add_arguments(patches):
    run = runner.Runner("path1", "path2", "path3")
    assert run.add_arguments("PARSER") is None
Ejemplo n.º 13
0
def test_runner_constructor():
    run = runner.Runner("path1", "path2", "path3")
    assert run._args == ("path1", "path2", "path3")
    assert run.log_field_styles == runner.LOG_FIELD_STYLES
    assert run.log_level_styles == runner.LOG_LEVEL_STYLES
    assert run.log_fmt == runner.LOG_FMT