Skip to content

Commit

Permalink
code added check valid arguments for glob, test added as well
Browse files Browse the repository at this point in the history
Testing Done:
added 2 tests on invalid argument and all glob tests passed.

intend to rewrite the test to include checking exception messages.

Bugs closed: 2126

Reviewed at https://rbcommons.com/s/twitter/r/2750/
  • Loading branch information
wisechengyi authored and fkorotkov committed Sep 3, 2015
1 parent 162db21 commit fb595b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/python/pants/backend/core/wrapped_globs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __getitem__(self, index):


class FilesetRelPathWrapper(object):
KNOWN_PARAMETERS = frozenset(['exclude', 'follow_links'])

@classmethod
@manual.builddict(factory=True)
Expand All @@ -71,8 +72,15 @@ def __call__(self, *args, **kwargs):
root = os.path.normpath(os.path.join(get_buildroot(), self._rel_path))

excludes = kwargs.pop('exclude', [])

if isinstance(excludes, string_types):
raise ValueError("Expected exclude parameter to be a list of globs, lists, or strings")
raise ValueError("Expected exclude parameter to be a list of globs, lists, or strings")

# making sure there is no unknown argument(s)
unknown_args = set(kwargs.keys()) - self.KNOWN_PARAMETERS

if unknown_args:
raise ValueError('Unexpected arguments while parsing globs: {}'.format(', '.join(unknown_args)))

for i, exclude in enumerate(excludes):
if isinstance(exclude, string_types):
Expand Down
10 changes: 10 additions & 0 deletions tests/python/pants_test/backend/core/test_wrapped_globs.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ def test_glob_exclude_string_in_list(self):
self.add_to_build_file('y/BUILD', 'java_library(name="y", sources=globs("*.java", exclude=["fleem.java"]))')
self.context().scan(self.build_root)

def test_glob_invalid_keyword(self):
self.add_to_build_file('y/BUILD', 'java_library(name="y", sources=globs("*.java", invalid_keyword=["fleem.java"]))')
with self.assertRaises(AddressLookupError):
self.context().scan(self.build_root)

def test_glob_invalid_keyword_along_with_valid_ones(self):
self.add_to_build_file('y/BUILD', 'java_library(name="y", sources=globs("*.java", follow_links=True, invalid_keyword=["fleem.java"]))')
with self.assertRaises(AddressLookupError):
self.context().scan(self.build_root)

def test_subdir_glob(self):
self.add_to_build_file('y/BUILD', 'java_library(name="y", sources=globs("dir/*.scala"))')
self.context().scan(self.build_root)
Expand Down

0 comments on commit fb595b6

Please sign in to comment.