def test_ignore_globs_parsed_correctly() -> None: files = Files("foo.py", "!ignore.py", "!**/*", spec_path="") assert files.to_path_globs( relpath="src/python", conjunction=GlobExpansionConjunction.any_match, ) == PathGlobs(["src/python/foo.py", "!src/python/ignore.py", "!src/python/**/*"]) # Check that we maintain backwards compatibility with the `filespecs` property used by V1. assert files.filespecs == {"globs": ["foo.py"], "exclude": [{"globs": ["ignore.py", "**/*"]}]}
def test_filespec_with_excludes(self): files = Files(spec_path='') self.assertEqual({'globs': []}, files.filespecs) files = Files(exclude=['*.md'], spec_path='') self.assertEqual({ 'exclude': [{ 'globs': ['*.md'] }], 'globs': [] }, files.filespecs)
def sources_for( self, package_relative_path_globs: List[str], package_dir: str = '', ) -> EagerFilesetWithSpec: sources_field = SourcesField( address=BuildFileAddress( rel_path=os.path.join(package_dir, "BUILD"), target_name="_bogus_target_for_test", ), arg='sources', filespecs={'globs': package_relative_path_globs}, base_globs=Files(spec_path=package_dir), path_globs=PathGlobs( tuple( os.path.join(package_dir, path) for path in package_relative_path_globs), ), validate_fn=lambda _: True, ) field = self.scheduler.product_request(HydratedField, [sources_field])[0] return cast(EagerFilesetWithSpec, field.value)
def test_excludes_of_wrong_type(self): with self.assertRaises(ValueError) as cm: Files(exclude='*.md', spec_path='') self.assertEqual( 'Excludes of type `{}` are not supported: got "*.md"'.format( 'str' if PY3 else 'unicode'), str(cm.exception))
def test_excludes_of_wrong_type(self) -> None: with self.assertRaises(ValueError) as cm: Files(exclude='*.md', spec_path='') self.assertEqual( 'Excludes of type `str` are not supported: got "*.md"', str(cm.exception))