Exemple #1
0
def slash_list(args, report_stream=sys.stdout):
    _print = partial(print, file=report_stream)
    _report_error = partial(print, file=sys.stderr)

    parser = _get_parser()
    parsed_args = parser.parse_args(args)

    if not parsed_args.paths and not parsed_args.suite_files:
        parser.error('Neither test paths nor suite files were specified')

    with slash.Session() as session:
        slash.site.load()
        loader = slash.loader.Loader()
        runnables = loader.get_runnables(
            itertools.chain(parsed_args.paths,
                            iter_suite_file_paths(parsed_args.suite_files)))
        used_fixtures = set()
        for test in runnables:
            used_fixtures.update(test.get_required_fixture_objects())

        if parsed_args.only in (None, 'fixtures'):
            _report_fixtures(parsed_args, session, _print, used_fixtures)

        if parsed_args.only in (None, 'tests'):
            _report_tests(parsed_args, runnables, _print)

    if len(runnables):
        return 0
    _report_error('No tests were found!')
    return not int(parsed_args.allow_empty)
Exemple #2
0
    def __init__(self, tab_widget, action_start_suit, action_start_test,
                 action_abort):
        self.tabWidget = tab_widget

        slash.logger.handlers.insert(0, LogViewer.systemHandler)

        colorama.init()

        test_dir = 'src/tests/'
        suit_dir = 'suits/'

        action_start_test.triggered.connect(self.start_test)
        action_start_suit.triggered.connect(self.start_suit)
        action_abort.triggered.connect(SlashWrapper.abort)

        suit_filenames = get_filenames_from_dir('*.suit', suit_dir)

        self.suites = []
        self.add_test_suite('All',
                            SlashWrapper.get_tests_from_dirs([test_dir]))

        for sfn in suit_filenames:
            path_tuples = []
            path_tuples.extend(iter_suite_file_paths([suit_dir + sfn]))
            paths = [pt[0] for pt in path_tuples]
            self.add_test_suite(
                sfn.split('.')[0], SlashWrapper.get_tests_from_dirs(paths))
Exemple #3
0
def slash_list(args, report_stream=sys.stdout):
    _print = partial(print, file=report_stream)
    _report_error = partial(print, file=sys.stderr)

    parser = _get_parser()
    parsed_args = parser.parse_args(args)

    if not parsed_args.paths and not parsed_args.suite_files:
        parser.error('Neither test paths nor suite files were specified')

    with slash.Session() as session:
        slash.site.load()
        loader = slash.loader.Loader()
        runnables = loader.get_runnables(itertools.chain(parsed_args.paths, iter_suite_file_paths(parsed_args.suite_files)))
        used_fixtures = set()
        for test in runnables:
            used_fixtures.update(test.get_required_fixture_objects())

        if parsed_args.only in (None, 'fixtures'):
            _report_fixtures(parsed_args, session, _print, used_fixtures)

        if parsed_args.only in (None, 'tests'):
            _report_tests(parsed_args, runnables, _print)

    if len(runnables):
        return 0
    _report_error('No tests were found!')
    return not int(parsed_args.allow_empty)
Exemple #4
0
def test_iter_suite_paths_files_relpath(filename, paths):
    with open(filename, 'w') as f:
        for path in paths:
            relpath = os.path.relpath(path, os.path.dirname(filename))
            assert not os.path.isabs(relpath)
            f.write(relpath)
            f.write('\n')

    assert [p for p, _ in suite_files.iter_suite_file_paths([filename])] == [os.path.abspath(p) for p in paths]
def test_iter_suite_paths_files_relpath(filename, paths):
    with open(filename, 'w') as f:
        for path in paths:
            relpath = os.path.relpath(path, os.path.dirname(filename))
            assert not os.path.isabs(relpath)
            f.write(relpath)
            f.write('\n')

    assert list(iter_suite_file_paths([filename])) == [os.path.abspath(p) for p in paths]
Exemple #6
0
def slash_list(args, report_stream=sys.stdout, error_stream=sys.stderr):
    _print = partial(print, file=report_stream)

    parser = _get_parser()
    parsed_args = parser.parse_args(args)

    if parsed_args.filter_strings:
        config.root.run.filter_strings.extend(parsed_args.filter_strings)

    _print = Printer(report_stream,
                     enable_output=parsed_args.show_output,
                     force_color=parsed_args.force_color,
                     enable_color=parsed_args.enable_color,
                     error_stream=error_stream)
    try:
        slash.site.load()
        with slash.Session() as session:

            if not parsed_args.paths and not parsed_args.suite_files:
                parsed_args.paths = config.root.run.default_sources

            if not parsed_args.paths and not parsed_args.suite_files:
                parser.error(
                    'Neither test paths nor suite files were specified')

            loader = slash.loader.Loader()
            runnables = loader.get_runnables(
                itertools.chain(parsed_args.paths,
                                iter_suite_file_paths(
                                    parsed_args.suite_files)))
            used_fixtures = set()
            for test in runnables:
                used_fixtures.update(test.get_required_fixture_objects())

            if parsed_args.only in (None, 'fixtures'):
                _report_fixtures(parsed_args, session, _print, used_fixtures)

            if parsed_args.only in (None, 'tests'):
                _report_tests(parsed_args, runnables, _print)

        if bool(session.warnings.warnings) and parsed_args.warnings_as_errors:
            return -1
        if len(runnables):  # pylint: disable=len-as-condition
            return 0
    except CannotLoadTests as e:
        _print(_error_style('Could not load tests ({})'.format(e)), error=True)
        return -1
    print('No tests were found!', file=sys.stderr)
    return int(not parsed_args.allow_empty)
Exemple #7
0
def test_files_containing_files(filename, paths, use_relpath):
    filename2 = os.path.join(os.path.dirname(filename), 'file2.txt')

    with open(filename2, 'w') as f:
        f.write('\n'.join(paths[::-1]))

    if use_relpath:
        filename2 = os.path.basename(filename2)

    with open(filename, 'w') as f:
        f.write('\n'.join(paths))
        f.write('\n')
        f.write(filename2)

    assert [p for p, _ in suite_files.iter_suite_file_paths([filename])] == paths + paths[::-1]
def test_files_containing_files(filename, paths, use_relpath):
    filename2 = os.path.join(os.path.dirname(filename), 'file2.txt')

    with open(filename2, 'w') as f:
        f.write('\n'.join(paths[::-1]))

    if use_relpath:
        filename2 = os.path.basename(filename2)

    with open(filename, 'w') as f:
        f.write('\n'.join(paths))
        f.write('\n')
        f.write(filename2)

    assert list(iter_suite_file_paths([filename])) == paths + paths[::-1]
Exemple #9
0
def test_iter_suite_file_paths_nested_filter(tmpdir):

    test_filename = '/some/test/file.py'
    suite_file1 = tmpdir.join('file1.txt')
    suite_file2 = tmpdir.join('file2.txt')

    with suite_file1.open('w') as f:
        print(suite_file2, '# filter: not blue', file=f)

    with suite_file2.open('w') as f:
        print(test_filename, '# filter: green', file=f)

    [(item, filter)] = suite_files.iter_suite_file_paths([str(suite_file1)])
    assert item == test_filename
    assert filter.matches('green')
    assert not filter.matches('blue')
    assert not filter.matches('green blue')
Exemple #10
0
def test_iter_suite_paths_files_abspaths(filename, paths):
    with open(filename, 'w') as f:
        f.write('\n'.join(paths))

    assert [p
            for p, _ in suite_files.iter_suite_file_paths([filename])] == paths
Exemple #11
0
def test_iter_suite_paths_files_abspaths(filename, paths):
    with open(filename, 'w') as f:
        f.write('\n'.join(paths))

    assert list(iter_suite_file_paths([filename])) == paths