コード例 #1
0
def test_line_truncation(long_text, use_truncation, config_override):

    config_override('log.truncate_console_lines', use_truncation)
    config_override('log.console_level', logbook.DEBUG)

    console = StringIO()

    with slash.Session(console_stream=console):
        logbook.debug(long_text)

    if use_truncation:
        assert long_text not in console.getvalue()
        assert long_text[:20] in console.getvalue()
    else:
        assert long_text in console.getvalue()
コード例 #2
0
ファイル: test_slash_list.py プロジェクト: Guy-Lev/slash
def test_slash_list_tests(suite, should_show_tags, suite_test):
    suite_test.add_decorator('slash.tag("bla")')
    suite.debug_info = False
    path = suite.commit()
    report_stream = StringIO()
    args = [path, '--only-tests']
    if should_show_tags:
        args.append('--show-tags')
    slash_list(args, report_stream)
    output = report_stream.getvalue()
    assert ('Tags' in output) == (should_show_tags)
コード例 #3
0
ファイル: test_slash_list.py プロジェクト: Guy-Lev/slash
def test_slash_list(suite, flag):
    suite.debug_info = False
    f = suite.slashconf.add_fixture()
    path = suite.commit()
    report_stream = StringIO()

    args = [path]
    if flag is not None:
        args.append(flag)
    slash_list(args, report_stream)
    assert report_stream.getvalue()
コード例 #4
0
ファイル: test_slash_list.py プロジェクト: guytish/slash
def test_slash_list_tests_with_or_without_tags(suite, should_show_tags,
                                               suite_test):
    suite_test.add_decorator('slash.tag("bla")')
    suite.debug_info = False
    path = suite.commit()
    report_stream = StringIO()
    args = [path, '--only-tests']
    if should_show_tags:
        args.append('--show-tags')
    slash_list(args, report_stream)
    output = report_stream.getvalue()
    assert ('Tags' in output) == (should_show_tags)
コード例 #5
0
def parametrized_func(params, param_names):
    buff = StringIO()
    formatter = CodeFormatter(buff)
    formatter.writeln('def f({}):'.format(', '.join(param_names)))
    with formatter.indented():
        formatter.writeln('pass')
    globs = {}
    exec(buff.getvalue(), globs)  # pylint: disable=exec-used
    returned = globs['f']
    for param_name in param_names:
        returned = slash.parametrize(param_name,
                                     list(params[param_name]))(returned)
    return returned
コード例 #6
0
def parametrized_func(params, param_names):
    buff = StringIO()
    formatter = CodeFormatter(buff)
    formatter.writeln('def f({0}):'.format(', '.join(param_names)))
    with formatter.indented():
        formatter.writeln('pass')
    globs = {}
    exec(buff.getvalue(), globs)
    returned = globs['f']
    for param_name in param_names:
        returned = slash.parametrize(
            param_name, list(params[param_name]))(returned)
    return returned
コード例 #7
0
def test_notify_if_slow_context(show_duration):
    output_stream = StringIO()
    reporter = ConsoleReporter(logbook.TRACE, output_stream)
    with slash.Session(console_stream=output_stream, reporter=reporter):
        with notify_if_slow_context('message',
                                    slow_seconds=0.1,
                                    end_message='End',
                                    show_duration=show_duration):
            time.sleep(1)
    output = output_stream.getvalue()
    assert 'message' in output
    assert 'End' in output
    assert ('took 0:00:01' in output) == show_duration
コード例 #8
0
ファイル: test_console_reporter.py プロジェクト: wubob/slash
def test_fancy_message(long_headline, multiline):
    output = StringIO()
    reporter = ConsoleReporter(logbook.TRACE, output)
    headline = 'some headline here'
    if long_headline:
        headline *= 80
    message = 'some message here'

    repetitions = 5
    if multiline:
        message = "\n".join(message for i in range(repetitions))
        message += '\n\n'

    reporter.report_fancy_message(headline, message)
    if long_headline:
        assert headline[:80] in output.getvalue()
    else:
        assert headline in output.getvalue()

    if multiline:
        assert output.getvalue().count(message.splitlines()[0]) == repetitions
    else:
        assert output.getvalue().count(message) == 1
コード例 #9
0
def test_slash_list_tests_relative_or_not(suite, relative):
    suite.debug_info = False
    path = suite.commit()
    report_stream = StringIO()
    args = [path]
    if relative:
        args.append('--relative-paths')
    slash_list(args, report_stream)
    output_lines = {
        _strip(line)
        for line in report_stream.getvalue().splitlines()
    } - {"Tests", "Fixtures"}
    assert output_lines
    for filename in output_lines:
        assert os.path.isabs(filename) == (not relative)
コード例 #10
0
 def _construct_fixture(self, name, scope, dependent_names):
     buff = StringIO()
     code = CodeFormatter(buff)
     code.writeln('def {}(this, {}):'.format(name,
                                             ', '.join(dependent_names)))
     with code.indented():
         for dependent_name in dependent_names:
             code.writeln(
                 'tree.check_value({0!r}, {0})'.format(dependent_name))
         code.writeln('@this.add_cleanup')
         code.writeln('def cleanup():')
         with code.indented():
             code.writeln('tree.cleanup({!r})'.format(name))
         code.writeln('return tree.make_value({!r})'.format(name))
     globs = {'tree': self}
     exec(buff.getvalue(), globs)  # pylint: disable=exec-used
     return slash.fixture(scope=scope)(globs[name])
コード例 #11
0
ファイル: test_fixture_scoping.py プロジェクト: hagai26/slash
 def _construct_fixture(self, name, scope, dependent_names):
     buff = StringIO()
     code = CodeFormatter(buff)
     code.writeln(
         'def {0}(this, {1}):'.format(name, ', '.join(dependent_names)))
     with code.indented():
         for dependent_name in dependent_names:
             code.writeln(
                 'tree.check_value({0!r}, {0})'.format(dependent_name))
         code.writeln('@this.add_cleanup')
         code.writeln('def cleanup():')
         with code.indented():
             code.writeln('tree.cleanup({0!r})'.format(name))
         code.writeln('return tree.make_value({0!r})'.format(name))
     globs = {'tree': self}
     exec(buff.getvalue(), globs)
     return slash.fixture(scope=scope)(globs[name])
コード例 #12
0
def test_slash_list_with_filtering(tmpdir):
    with tmpdir.join('test_file.py').open('w') as fp:
        _print = functools.partial(print, file=fp)
        _print()
        _print('def test_a():')
        _print('    pass')
        _print('')
        _print('def test_b():')
        _print('    pass')
        _print('')
        _print('def test_c():')
        _print('    pass')

    report_stream = StringIO()
    args = [fp.name, '-k', 'not _b', '--only-tests']
    result = slash_list(args, report_stream=report_stream)
    assert result == 0

    listed_tests = _strip(report_stream.getvalue()).splitlines()
    assert listed_tests == [
        '{}:{}'.format(fp.name, test_name)
        for test_name in ('test_a', 'test_c')
    ]
コード例 #13
0
ファイル: code_element.py プロジェクト: wubob/slash
 def source(self):
     buff = StringIO()
     f = CodeFormatter(buff)
     self.write(f)
     return buff.getvalue()
コード例 #14
0
ファイル: test_list_config.py プロジェクト: Guy-Lev/slash
def test_slash_list():
    report_stream = StringIO()
    list_config([], report_stream)
    assert report_stream.getvalue()
コード例 #15
0
def test_slash_list_config():
    report_stream = StringIO()
    list_config([], report_stream)
    assert report_stream.getvalue()
コード例 #16
0
def test_slash_list_config_with_filters():
    report_stream = StringIO()
    list_config(['log'], report_stream)
    assert 'log.root' in report_stream.getvalue()
コード例 #17
0
ファイル: code_element.py プロジェクト: Guy-Lev/slash
 def source(self):
     buff = StringIO()
     f = CodeFormatter(buff)
     self.write(f)
     return buff.getvalue()