Skip to content

Commit

Permalink
Add exclude_dirs flag to jsonnet_test (kubeflow#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankush Agarwal authored and k8s-ci-robot committed May 1, 2018
1 parent 906dc27 commit 3ce5637
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion py/kubeflow/testing/test_jsonnet_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def parse_args():
type=str,
help=("The root directory of the source tree. Defaults to current "
"directory."))
parser.add_argument(
"--exclude_dirs",
default="",
type=str,
help="Comma separated directories which should be excluded from the test")
args, _ = parser.parse_known_args()
return args

Expand All @@ -36,16 +41,24 @@ def is_formatted(file_name):
finally:
os.remove(outfile)

def is_excluded(file_name, exclude_dirs):
for exclude_dir in exclude_dirs:
if file_name.startswith(exclude_dir):
return True
return False

def test_jsonnet_formatting(test_case): # pylint: disable=redefined-outer-name
logging.info('Running test_jsonnet_formatting')
args = parse_args()
exclude_dirs = []
if args.exclude_dirs:
exclude_dirs = args.exclude_dirs.split(',')
for dirpath, _, filenames in os.walk(args.src_dir):
jsonnet_files = fnmatch.filter(filenames, '*.jsonnet')
libsonnet_files = fnmatch.filter(filenames, '*.libsonnet')
for file_name in itertools.chain(jsonnet_files, libsonnet_files):
full_path = os.path.join(dirpath, file_name)
if not is_formatted(full_path):
if not is_excluded(full_path, exclude_dirs) and not is_formatted(full_path):
test_case.add_failure_info("ERROR : {0} is not formatted".format(full_path))


Expand Down

0 comments on commit 3ce5637

Please sign in to comment.