def test_include_works(test_project): result = frozenset(fs.filtered_walk('.', include=['ops*'])) assert result == frozenset(( 'ops', 'ops/tools', 'ops/tools/pylint.ini', 'ops/tools/pytest.ini', ))
def test_include_abspath_means_relative_to_starting_point(test_project): result = frozenset(fs.filtered_walk('.', include=['/ops*'])) assert result == frozenset(( 'ops', 'ops/tools', 'ops/tools/pylint.ini', 'ops/tools/pytest.ini', ))
def test_exclude_abspath_means_relative_to_starting_point(test_project): result = frozenset(fs.filtered_walk('.', exclude=['/ops*'])) assert result == frozenset(( 'src', 'src/pkg', 'src/pkg/__init__.py', 'pelconf.yaml', 'README.rst', ))
def test_exclude_works(test_project): result = frozenset(fs.filtered_walk('.', exclude=['*ops*'])) assert result == frozenset(( 'src', 'src/pkg', 'src/pkg/__init__.py', 'pelconf.yaml', 'README.rst', ))
def clean(exclude: List[str]): """ Remove all unnecessary files. Args: exclude (list[str]): A list of path patterns to exclude from deletion. """ pretend = context.get('pretend', False) exclude = list(exclude) + conf.get('clean.exclude', []) clean_patterns = conf.get('clean.patterns', [ '*__pycache__*', '*.py[cod]', '*.swp', "*.mypy_cache", "*.pytest_cache", "*.build", ]) if context.get('verbose'): log.info('Clean patterns:') for pattern in clean_patterns: log.info(f' <90>{pattern}') log.info('Exclude:') for pattern in exclude: log.info(f' <90>{pattern}') num_files = 0 with util.timed_block() as t: files = fs.filtered_walk(conf.proj_path(), clean_patterns, exclude) log.info('') log.info('Deleting:') for path in files: try: num_files += 1 if not isdir(path): log.info(' <91>[file] <90>{}', path) if not pretend: os.remove(path) else: log.info(' <91>[dir] <90>{}', path) if not pretend: rmtree(path) except OSError: log.info("<33>Failed to remove <90>{}", path) if pretend: msg = "Would delete <33>{}<32> files. Took <33>{}<32>s" else: msg = "Deleted <33>{}<32> files in <33>{}<32>s" log.info(msg.format(num_files, t.elapsed_s))
def test_shows_all_files(test_project): result = frozenset(fs.filtered_walk('.')) assert result == frozenset(( 'ops', 'ops/tools', 'ops/tools/pylint.ini', 'ops/tools/pytest.ini', 'src', 'src/pkg', 'src/pkg/__init__.py', 'pelconf.yaml', 'README.rst', ))
def test_raises_ValueError_if_path_is_not_a_directory(test_project): with pytest.raises(ValueError): list(fs.filtered_walk('pelconf.py'))