How to use iter_suite_file_paths method in Slash

Best Python code snippet using slash

test_suite_files.py

Source:test_suite_files.py Github

copy

Full Screen

...7from slash.utils import suite_files8def test_iter_suite_paths_files_abspaths(filename, paths):9 with open(filename, 'w') as f:10 f.write('\n'.join(paths))11 assert [p for p, _ in suite_files.iter_suite_file_paths([filename])] == paths12 assert [p for p, _ in suite_files.iter_suite_file_paths([os.path.dirname(filename)])] == paths13def test_iter_suite_paths_files_relpath(filename, paths):14 with open(filename, 'w') as f:15 for path in paths:16 relpath = os.path.relpath(path, os.path.dirname(filename))17 assert not os.path.isabs(relpath)18 f.write(relpath)19 f.write('\n')20 assert [os.path.abspath(p) for p, _ in suite_files.iter_suite_file_paths([filename])] == [os.path.abspath(p) for p in paths]21 assert [os.path.abspath(p) for p, _ in suite_files.iter_suite_file_paths([os.path.dirname(filename)])] == [22 os.path.abspath(p) for p in paths]23def test_iter_suite_path_recursive_dirs(paths, tmpdir, filename):24 with open(filename, 'w') as f:25 f.write('\n'.join(paths[::2]))26 subdir_path = os.path.join(tmpdir, "subdir")27 os.mkdir(subdir_path)28 filename2 = os.path.join(subdir_path, 'file2.txt')29 with open(filename2, 'w') as f:30 f.write('\n'.join(paths[1::2]))31 assert [p for p, _ in suite_files.iter_suite_file_paths([tmpdir])].sort() == paths.sort()32 assert [p for p, _ in suite_files.iter_suite_file_paths([subdir_path])].sort() == paths[1::2].sort()33def test_suite_files(suite, suite_test, suite_file): # pylint: disable=unused-argument34 suite.run(args=[])35def test_suite_file_with_filter(suite, suite_test, suite_file):36 path = suite.commit()37 with suite_file.open('w') as f:38 print(path, '# filter:', suite_test.name, file=f)39 suite.run(args=[])40def test_parse_filter_string():41 suite_entry = suite_files._parse_path_filter_and_repeat('some_path.py # filter: bla') # pylint: disable=protected-access42 assert suite_entry.path == 'some_path.py'43 assert suite_entry.matcher is not None44 assert suite_entry.matcher.matches('bla')45 assert not suite_entry.matcher.matches('blooop')46@pytest.mark.parametrize("string", [47 'some_path.py #',48 'some_path.py # bbb',49 'some_path.py#'50])51def test_parse_filter_string_no_filter(string):52 suite_entry = suite_files._parse_path_filter_and_repeat(string) # pylint: disable=protected-access53 assert suite_entry.path == 'some_path.py'54 assert suite_entry.matcher is None55def test_iter_suite_file_paths_nested_filter(tmpdir):56 test_filename = '/some/test/file.py'57 suite_file1 = tmpdir.join('file1.txt')58 suite_file2 = tmpdir.join('file2.txt')59 with suite_file1.open('w') as f:60 print(suite_file2, '# filter: not blue', file=f)61 with suite_file2.open('w') as f:62 print(test_filename, '# filter: green', file=f)63 [(item, matcher)] = suite_files.iter_suite_file_paths([str(suite_file1)])64 assert item == test_filename65 assert matcher.matches('green')66 assert not matcher.matches('blue')67 assert not matcher.matches('green blue')68def test_parse_repeat_string():69 suite_entry = suite_files._parse_path_filter_and_repeat('some_path.py # repeat: 5') # pylint: disable=protected-access70 assert suite_entry.path == 'some_path.py'71 assert suite_entry.matcher is None72 assert suite_entry.repeat == 573@pytest.mark.parametrize("string", [74 'some_path.py # filter: bla, repeat: 5',75 'some_path.py # repeat: 5, filter: bla',76])77def test_parse_repeat_string_with_filter(string):78 suite_entry = suite_files._parse_path_filter_and_repeat(string) # pylint: disable=protected-access79 assert suite_entry.path == 'some_path.py'80 assert suite_entry.matcher is not None81 assert suite_entry.matcher.matches('bla')82 assert not suite_entry.matcher.matches('blooop')83 assert suite_entry.matcher is not None84 assert suite_entry.repeat == 585@pytest.fixture86def suite_file(tmpdir, suite, suite_test, config_override):87 path = suite.commit()88 suite_file_path = tmpdir.join('suite.txt')89 with suite_file_path.open('w') as f:90 f.write(suite_test.get_full_address(path))91 suite.deselect_all(exclude=[suite_test])92 config_override('run.suite_files', [str(suite_file_path)])93 return suite_file_path94@pytest.mark.parametrize('use_relpath', [True, False])95def test_files_containing_files(filename, paths, use_relpath):96 filename2 = os.path.join(os.path.dirname(filename), 'file2.txt')97 with open(filename2, 'w') as f:98 f.write('\n'.join(paths[::-1]))99 if use_relpath:100 filename2 = os.path.basename(filename2)101 with open(filename, 'w') as f:102 f.write('\n'.join(paths))103 f.write('\n')104 f.write(filename2)105 assert [p for p, _ in suite_files.iter_suite_file_paths([filename])] == paths + paths[::-1]106def test_slash_run_with_suite_file(suite, suite_test, tmpdir):107 path = suite.commit()108 with tmpdir.join('suitefile').open('w') as suite_file: # pylint: disable=redefined-outer-name109 _fill_suite_file(path, [suite_test], suite_file=suite_file)110 for t in suite:111 if t is not suite_test:112 t.expect_deselect()113 suite.run(args=[], additional_args=['-f', suite_file.name])114def test_slash_run_with_suite_file_invalid_test(suite, suite_test, tmpdir):115 path = suite.commit()116 additional_test = suite[0]117 assert additional_test is not suite_test118 with tmpdir.join('suitefile').open('w') as suite_file: # pylint: disable=redefined-outer-name119 _fill_suite_file(path, [additional_test], suite_file=suite_file, corrupt=False)...

Full Screen

Full Screen

slash_list.py

Source:slash_list.py Github

copy

Full Screen

...52 parsed_args.paths = config.root.run.default_sources53 if not parsed_args.paths and not parsed_args.suite_files:54 parser.error('Neither test paths nor suite files were specified')55 loader = slash.loader.Loader()56 runnables = loader.get_runnables(itertools.chain(parsed_args.paths, iter_suite_file_paths(parsed_args.suite_files)))57 used_fixtures = set()58 for test in runnables:59 used_fixtures.update(test.get_required_fixture_objects())60 if parsed_args.only in (None, 'fixtures'):61 _report_fixtures(parsed_args, session, _print, used_fixtures)62 if parsed_args.only in (None, 'tests'):63 _report_tests(parsed_args, runnables, _print)64 if bool(session.warnings.warnings) and parsed_args.warnings_as_errors:65 return -166 if len(runnables): # pylint: disable=len-as-condition67 return 068 except CannotLoadTests as e:69 _print(_error_style('Could not load tests ({})'.format(e)), error=True)70 return -1...

Full Screen

Full Screen

slash_run.py

Source:slash_run.py Github

copy

Full Screen

...103 suite_files = config.root.run.suite_files104 if not suite_files:105 return paths106 paths = list(paths)107 paths.extend(iter_suite_file_paths(suite_files))...

Full Screen

Full Screen

suite_files.py

Source:suite_files.py Github

copy

Full Screen

2from collections import namedtuple3from pathlib import Path4from . import pattern_matching5SuiteEntry = namedtuple('SuiteEntry', 'path, matcher, repeat')6def iter_suite_file_paths(suite_files):7 for filename in _extract_suite_files(suite_files):8 dirname = os.path.abspath(os.path.dirname(filename))9 with open(filename) as suite_file:10 for path in suite_file:11 path = path.strip()12 if not path or path.startswith("#"):13 continue14 suite_entry = _parse_path_filter_and_repeat(path)15 path = suite_entry.path16 if not os.path.isabs(path):17 path = os.path.relpath(os.path.join(dirname, path))18 if not path.endswith('.py') and '.py:' not in path and not os.path.isdir(path):19 for p, other_filter in iter_suite_file_paths([path]):20 yield p, _and_matchers(suite_entry.matcher, other_filter)21 continue22 for _ in range(suite_entry.repeat):23 yield path, suite_entry.matcher24def _extract_suite_files(suite_files):25 for entity in suite_files:26 if Path(entity).is_dir():27 yield from _extract_suite_files(Path(entity).rglob("*"))28 else:29 yield entity30def _and_matchers(a, b):31 if a is None:32 return b33 if b is None:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful