From 5a81c1649926655181ec3636d7d5f0510adb56f9 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Wed, 8 Mar 2023 12:22:28 -0700 Subject: [PATCH 1/9] Added implementation to specify multiple tagnames --- buildtest/cli/build.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/buildtest/cli/build.py b/buildtest/cli/build.py index aa4f4a931..bee05fe5c 100644 --- a/buildtest/cli/build.py +++ b/buildtest/cli/build.py @@ -308,10 +308,14 @@ def discover_buildspecs_by_tags(buildspec_cache, tagnames): buildspecs_by_tags = {} buildspecs = [] + multiple_taglist = [] # query all buildspecs from BUILDSPEC_CACHE_FILE for tags keyword and # if it matches input_tag we add buildspec to list - + for name in tagnames: + multiple_taglist.extend(name.split(",")) + + for name in multiple_taglist: buildspecs_by_tags[name] = set() for buildspecfile in buildspec_cache["buildspecs"].keys(): From e121299a424d3637aee8f7726a596a6500a608b0 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Wed, 8 Mar 2023 12:28:55 -0700 Subject: [PATCH 2/9] Added in the unit test for multiple tags feature --- tests/cli/test_build.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/cli/test_build.py b/tests/cli/test_build.py index f7778cfc7..3f6bbe8a0 100644 --- a/tests/cli/test_build.py +++ b/tests/cli/test_build.py @@ -46,6 +46,14 @@ def test_build_by_tags(): ) cmd.build() + # testing multiple tags as comma seperated list: buildtest build --tags fail,pass --tags python,ping --tags network + cmd = BuildTest( + configuration=configuration, + tags=["fail,pass", "python,ping", "network"], + buildtest_system=system, + ) + cmd.build() + @pytest.mark.cli def test_build_rerun(): From 1d1b93063a091ef556260c8af95d9f7206301d85 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Wed, 8 Mar 2023 12:35:55 -0700 Subject: [PATCH 3/9] Added the new option to buildtest help build --- buildtest/cli/help.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/buildtest/cli/help.py b/buildtest/cli/help.py index 65827120a..e55932fb1 100644 --- a/buildtest/cli/help.py +++ b/buildtest/cli/help.py @@ -25,6 +25,10 @@ def print_build_help(): "buildtest build -t pass -t python", "Build buildspecs by tagname 'pass' and 'python'", ) + table.add_row( + "buildtest build -t pass,fail -t network", + "Build buildspecs by tagnames that are specified as comma sperated list" + ) table.add_row( "buildtest build -e -e ", "Building buildspecs by executor", From 2cfe327bd4ea1f7baf32157704f38e3365d0977a Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Wed, 8 Mar 2023 12:51:21 -0700 Subject: [PATCH 4/9] Added documentation for building by tags --- docs/gettingstarted/buildingtest.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/gettingstarted/buildingtest.rst b/docs/gettingstarted/buildingtest.rst index d05e3b1c6..9f200fd43 100644 --- a/docs/gettingstarted/buildingtest.rst +++ b/docs/gettingstarted/buildingtest.rst @@ -138,6 +138,13 @@ tags by running ``buildtest buildspec find --tags``. .. Note:: The ``--tags`` is used for discovering buildspec file and not filtering tests by tag. +You can also build by multiple tags by providing a list of tagnames as comma seperated values. In the below +example we build all tests with tag name ``pass``, ``fail`` and ``network``. Note that you can still specify ``--tags`` multiple times. + +.. dropdown:: ``buildtest build -t pass,fail -t network`` + + .. command-output:: buildtest build -t pass,fail -t network + You can combine ``--tags`` with ``--buildspec`` to discover buildspecs in a single command. buildtest will query tags and buildspecs independently and combine all discovered buildspecs together. From 94fbd86467f8f75ca7177b539840c3a4863ac546 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Wed, 8 Mar 2023 12:55:46 -0700 Subject: [PATCH 5/9] Updated a senctence in documentation for building by tags --- docs/gettingstarted/buildingtest.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/gettingstarted/buildingtest.rst b/docs/gettingstarted/buildingtest.rst index 9f200fd43..aad2eb199 100644 --- a/docs/gettingstarted/buildingtest.rst +++ b/docs/gettingstarted/buildingtest.rst @@ -138,8 +138,8 @@ tags by running ``buildtest buildspec find --tags``. .. Note:: The ``--tags`` is used for discovering buildspec file and not filtering tests by tag. -You can also build by multiple tags by providing a list of tagnames as comma seperated values. In the below -example we build all tests with tag name ``pass``, ``fail`` and ``network``. Note that you can still specify ``--tags`` multiple times. +You can also build by multiple tags by providing tagnames as comma seperated list. In the below +example we build all tests with tag names ``pass``, ``fail`` and ``network``. Note that you can still specify ``--tags`` multiple times. .. dropdown:: ``buildtest build -t pass,fail -t network`` From aaf0f1d05f36c39d96916602cd14e6ea6797366e Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Thu, 9 Mar 2023 12:04:27 -0700 Subject: [PATCH 6/9] Refactored few lines and added additional tests --- buildtest/cli/build.py | 12 +++++++----- buildtest/cli/help.py | 4 ++-- docs/gettingstarted/buildingtest.rst | 4 ++-- scripts/spack_container/doc-examples.py | 1 - tests/cli/test_build.py | 25 +++++++++++++++++++++++-- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/buildtest/cli/build.py b/buildtest/cli/build.py index bee05fe5c..3ce39e1b7 100644 --- a/buildtest/cli/build.py +++ b/buildtest/cli/build.py @@ -308,14 +308,16 @@ def discover_buildspecs_by_tags(buildspec_cache, tagnames): buildspecs_by_tags = {} buildspecs = [] - multiple_taglist = [] # query all buildspecs from BUILDSPEC_CACHE_FILE for tags keyword and # if it matches input_tag we add buildspec to list - - for name in tagnames: - multiple_taglist.extend(name.split(",")) + tagnames = [ + tag.strip() for tagname in tagnames for tag in tagname.split(",") if tag != "" + ] + + if not tagnames: + return buildspecs, buildspecs_by_tags - for name in multiple_taglist: + for name in tagnames: buildspecs_by_tags[name] = set() for buildspecfile in buildspec_cache["buildspecs"].keys(): diff --git a/buildtest/cli/help.py b/buildtest/cli/help.py index e55932fb1..225972974 100644 --- a/buildtest/cli/help.py +++ b/buildtest/cli/help.py @@ -26,8 +26,8 @@ def print_build_help(): "Build buildspecs by tagname 'pass' and 'python'", ) table.add_row( - "buildtest build -t pass,fail -t network", - "Build buildspecs by tagnames that are specified as comma sperated list" + "buildtest build -t pass,fail", + "Build buildspecs by tagnames that are specified as comma sperated list", ) table.add_row( "buildtest build -e -e ", diff --git a/docs/gettingstarted/buildingtest.rst b/docs/gettingstarted/buildingtest.rst index aad2eb199..c5705828f 100644 --- a/docs/gettingstarted/buildingtest.rst +++ b/docs/gettingstarted/buildingtest.rst @@ -138,8 +138,8 @@ tags by running ``buildtest buildspec find --tags``. .. Note:: The ``--tags`` is used for discovering buildspec file and not filtering tests by tag. -You can also build by multiple tags by providing tagnames as comma seperated list. In the below -example we build all tests with tag names ``pass``, ``fail`` and ``network``. Note that you can still specify ``--tags`` multiple times. +You can also build by multiple tags by providing tagnames as comma seperated list. In the +example below we build all tests with tag names ``pass``, ``fail`` and ``network``. .. dropdown:: ``buildtest build -t pass,fail -t network`` diff --git a/scripts/spack_container/doc-examples.py b/scripts/spack_container/doc-examples.py index d9b8326c9..2ef22832d 100644 --- a/scripts/spack_container/doc-examples.py +++ b/scripts/spack_container/doc-examples.py @@ -10,7 +10,6 @@ from buildtest.utils.file import create_dir, is_dir, is_file if __name__ == "__main__": - if getpass.getuser() != "spack" or os.getenv("HOME") != "/home/spack": sys.exit( "This script can only be run inside container: ghcr.io/buildtesters/buildtest_spack:latest" diff --git a/tests/cli/test_build.py b/tests/cli/test_build.py index 3f6bbe8a0..b680074d7 100644 --- a/tests/cli/test_build.py +++ b/tests/cli/test_build.py @@ -46,10 +46,31 @@ def test_build_by_tags(): ) cmd.build() - # testing multiple tags as comma seperated list: buildtest build --tags fail,pass --tags python,ping --tags network + # testing multiple tags as comma seperated list: buildtest build --tags fail,python --tags network cmd = BuildTest( configuration=configuration, - tags=["fail,pass", "python,ping", "network"], + tags=["fail,python", "network"], + buildtest_system=system, + ) + cmd.build() + + cmd = BuildTest( + configuration=configuration, + tags=[",,"], + buildtest_system=system, + ) + cmd.build() + + cmd = BuildTest( + configuration=configuration, + tags=["python,"], + buildtest_system=system, + ) + cmd.build() + + cmd = BuildTest( + configuration=configuration, + tags=[",python"], buildtest_system=system, ) cmd.build() From 1def40377665c0b52ab1490f7c0d99eb2b51848e Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Thu, 9 Mar 2023 12:40:27 -0700 Subject: [PATCH 7/9] Added condition for systemexit in test_build.py --- tests/cli/test_build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/cli/test_build.py b/tests/cli/test_build.py index b680074d7..e201095ca 100644 --- a/tests/cli/test_build.py +++ b/tests/cli/test_build.py @@ -59,7 +59,8 @@ def test_build_by_tags(): tags=[",,"], buildtest_system=system, ) - cmd.build() + with pytest.raises(SystemExit): + cmd.build() cmd = BuildTest( configuration=configuration, From 00e7f850b24d073081b5289bf1ccda499dc51027 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Thu, 9 Mar 2023 15:26:05 -0700 Subject: [PATCH 8/9] Updated build.py, docs and added tests --- buildtest/cli/build.py | 2 +- docs/gettingstarted/buildingtest.rst | 2 +- tests/cli/test_build.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/buildtest/cli/build.py b/buildtest/cli/build.py index 3ce39e1b7..85a5f0aba 100644 --- a/buildtest/cli/build.py +++ b/buildtest/cli/build.py @@ -311,7 +311,7 @@ def discover_buildspecs_by_tags(buildspec_cache, tagnames): # query all buildspecs from BUILDSPEC_CACHE_FILE for tags keyword and # if it matches input_tag we add buildspec to list tagnames = [ - tag.strip() for tagname in tagnames for tag in tagname.split(",") if tag != "" + tag.strip() for tagname in tagnames for tag in tagname.split(",") if tag.strip() ] if not tagnames: diff --git a/docs/gettingstarted/buildingtest.rst b/docs/gettingstarted/buildingtest.rst index c5705828f..e6de28af8 100644 --- a/docs/gettingstarted/buildingtest.rst +++ b/docs/gettingstarted/buildingtest.rst @@ -138,7 +138,7 @@ tags by running ``buildtest buildspec find --tags``. .. Note:: The ``--tags`` is used for discovering buildspec file and not filtering tests by tag. -You can also build by multiple tags by providing tagnames as comma seperated list. In the +You can specify multiple tag names as a comma separated list. In the example below we build all tests with tag names ``pass``, ``fail`` and ``network``. .. dropdown:: ``buildtest build -t pass,fail -t network`` diff --git a/tests/cli/test_build.py b/tests/cli/test_build.py index e201095ca..37c3edfa3 100644 --- a/tests/cli/test_build.py +++ b/tests/cli/test_build.py @@ -64,14 +64,14 @@ def test_build_by_tags(): cmd = BuildTest( configuration=configuration, - tags=["python,"], + tags=[",python,fail,,"], buildtest_system=system, ) cmd.build() cmd = BuildTest( configuration=configuration, - tags=[",python"], + tags=["python, fail,network ,"], buildtest_system=system, ) cmd.build() From 03b9f4372c14796ec5618c9c399655cc7fee7607 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Thu, 9 Mar 2023 15:38:52 -0700 Subject: [PATCH 9/9] Updated test --- tests/cli/test_build.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/cli/test_build.py b/tests/cli/test_build.py index 37c3edfa3..c7debbd80 100644 --- a/tests/cli/test_build.py +++ b/tests/cli/test_build.py @@ -64,14 +64,7 @@ def test_build_by_tags(): cmd = BuildTest( configuration=configuration, - tags=[",python,fail,,"], - buildtest_system=system, - ) - cmd.build() - - cmd = BuildTest( - configuration=configuration, - tags=["python, fail,network ,"], + tags=[" ,python, fail, ,,"], buildtest_system=system, ) cmd.build()