From 3ce5637946aa8698873a3080a6fa4835f490b363 Mon Sep 17 00:00:00 2001 From: Ankush Agarwal Date: Tue, 1 May 2018 14:40:17 -0700 Subject: [PATCH] Add exclude_dirs flag to jsonnet_test (#118) --- py/kubeflow/testing/test_jsonnet_formatting.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/py/kubeflow/testing/test_jsonnet_formatting.py b/py/kubeflow/testing/test_jsonnet_formatting.py index 73efec1a7e8..dc182f10753 100644 --- a/py/kubeflow/testing/test_jsonnet_formatting.py +++ b/py/kubeflow/testing/test_jsonnet_formatting.py @@ -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 @@ -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))