From ef5b5fb3179d487374504ed0288cbfca16a6002e Mon Sep 17 00:00:00 2001 From: Caylo Date: Wed, 13 Jul 2016 13:06:17 +0200 Subject: [PATCH 1/4] --new-pr can't be empty --- easybuild/tools/github.py | 2 ++ test/framework/options.py | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index a599b77a2b..e22b325438 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -618,6 +618,8 @@ def _easyconfigs_pr_common(paths, start_branch=None, pr_branch=None, target_acco print_msg(git_repo.git.diff(cached=True) + '\n', log=_log, prefix=False) diff_stat = git_repo.git.diff(cached=True, stat=True) + if not diff_stat: + raise EasyBuildError("No changed files found. Refused to make empty pull request.") # commit if commit_msg: diff --git a/test/framework/options.py b/test/framework/options.py index 83949c212a..53a0befab8 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -47,8 +47,8 @@ from easybuild.tools.config import DEFAULT_MODULECLASSES from easybuild.tools.config import find_last_log, get_build_log_path, get_module_syntax, module_classes from easybuild.tools.environment import modify_env -from easybuild.tools.filetools import mkdir, read_file, write_file -from easybuild.tools.github import fetch_github_token +from easybuild.tools.filetools import download_file, mkdir, read_file, write_file +from easybuild.tools.github import GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO, URL_SEPARATOR, fetch_github_token from easybuild.tools.options import EasyBuildOptions, parse_external_modules_metadata, set_tmpdir from easybuild.tools.toolchain.utilities import TC_CONST_PREFIX from easybuild.tools.run import run_cmd @@ -2350,6 +2350,34 @@ def test_new_update_pr(self): regex = re.compile(regex, re.M) self.assertTrue(regex.search(txt), "Pattern '%s' found in: %s" % (regex.pattern, txt)) + def test_empty_pr(self): + """Test use of --new-pr (dry run only) with no changes""" + if self.github_token is None: + print "Skipping test_new_pr, no GitHub token available?" + return + + # get file from develop branch + test_ecs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs') + full_url = URL_SEPARATOR.join([GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO, 'develop/easybuild/easyconfigs/z/zlib/zlib-1.2.8.eb']) + ec = download_file('zlib-1.2.8.eb', full_url, path=os.path.join(test_ecs_dir, 'zlib-1.2.8.eb'), forced=True) + + # try to open new pr with unchanged file + os.environ['EASYBUILD_GITHUB_USER'] = GITHUB_TEST_ACCOUNT + args = [ + '--new-pr', + '--experimental', + ec, + '-D', + ] + + self.mock_stdout(True) + error_msg = 'No changed files found. Refused to make empty pull request.' + self.assertErrorRegex(EasyBuildError, error_msg, self.eb_main, args, do_build=True, raise_error=True) + self.mock_stdout(False) + + os.remove(os.path.join(test_ecs_dir, 'zlib-1.2.8.eb')) + + def test_show_config(self): """"Test --show-config and --show-full-config.""" From 7f3d82342ab9d8873bdf3f2f5efce8c929146645 Mon Sep 17 00:00:00 2001 From: Caylo Date: Wed, 13 Jul 2016 17:00:48 +0200 Subject: [PATCH 2/4] fix remarks --- easybuild/tools/github.py | 3 ++- test/framework/options.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index e22b325438..6b8b2c084d 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -619,7 +619,8 @@ def _easyconfigs_pr_common(paths, start_branch=None, pr_branch=None, target_acco diff_stat = git_repo.git.diff(cached=True, stat=True) if not diff_stat: - raise EasyBuildError("No changed files found. Refused to make empty pull request.") + raise EasyBuildError("No changed files found when comparing to current develop branch." + "Refused to make empty pull request.") # commit if commit_msg: diff --git a/test/framework/options.py b/test/framework/options.py index 53a0befab8..2fff058e0e 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -48,7 +48,8 @@ from easybuild.tools.config import find_last_log, get_build_log_path, get_module_syntax, module_classes from easybuild.tools.environment import modify_env from easybuild.tools.filetools import download_file, mkdir, read_file, write_file -from easybuild.tools.github import GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO, URL_SEPARATOR, fetch_github_token +from easybuild.tools.github import GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO, URL_SEPARATOR +from easybuild.tools.github import fetch_github_token from easybuild.tools.options import EasyBuildOptions, parse_external_modules_metadata, set_tmpdir from easybuild.tools.toolchain.utilities import TC_CONST_PREFIX from easybuild.tools.run import run_cmd @@ -2358,7 +2359,8 @@ def test_empty_pr(self): # get file from develop branch test_ecs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs') - full_url = URL_SEPARATOR.join([GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO, 'develop/easybuild/easyconfigs/z/zlib/zlib-1.2.8.eb']) + full_url = URL_SEPARATOR.join([GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO, + 'develop/easybuild/easyconfigs/z/zlib/zlib-1.2.8.eb']) ec = download_file('zlib-1.2.8.eb', full_url, path=os.path.join(test_ecs_dir, 'zlib-1.2.8.eb'), forced=True) # try to open new pr with unchanged file @@ -2371,7 +2373,7 @@ def test_empty_pr(self): ] self.mock_stdout(True) - error_msg = 'No changed files found. Refused to make empty pull request.' + error_msg = "No changed files found when comparing to current develop branch." self.assertErrorRegex(EasyBuildError, error_msg, self.eb_main, args, do_build=True, raise_error=True) self.mock_stdout(False) From 5bd056ed92a17444890f8cb35cfd5980721673b7 Mon Sep 17 00:00:00 2001 From: Caylo Date: Wed, 13 Jul 2016 17:03:22 +0200 Subject: [PATCH 3/4] test in test_prefix --- test/framework/options.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/framework/options.py b/test/framework/options.py index 2fff058e0e..e25935d91f 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -2358,10 +2358,9 @@ def test_empty_pr(self): return # get file from develop branch - test_ecs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs') full_url = URL_SEPARATOR.join([GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO, 'develop/easybuild/easyconfigs/z/zlib/zlib-1.2.8.eb']) - ec = download_file('zlib-1.2.8.eb', full_url, path=os.path.join(test_ecs_dir, 'zlib-1.2.8.eb'), forced=True) + ec = download_file('zlib-1.2.8.eb', full_url, path=os.path.join(self.test_prefix, 'zlib-1.2.8.eb'), forced=True) # try to open new pr with unchanged file os.environ['EASYBUILD_GITHUB_USER'] = GITHUB_TEST_ACCOUNT @@ -2377,8 +2376,6 @@ def test_empty_pr(self): self.assertErrorRegex(EasyBuildError, error_msg, self.eb_main, args, do_build=True, raise_error=True) self.mock_stdout(False) - os.remove(os.path.join(test_ecs_dir, 'zlib-1.2.8.eb')) - def test_show_config(self): """"Test --show-config and --show-full-config.""" From 60cb24dd91fd491fa64fbae3e33388653d1971c7 Mon Sep 17 00:00:00 2001 From: Caylo Date: Thu, 14 Jul 2016 15:57:26 +0200 Subject: [PATCH 4/4] fix remarks --- test/framework/options.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/framework/options.py b/test/framework/options.py index e25935d91f..52c4458a3b 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -2354,21 +2354,22 @@ def test_new_update_pr(self): def test_empty_pr(self): """Test use of --new-pr (dry run only) with no changes""" if self.github_token is None: - print "Skipping test_new_pr, no GitHub token available?" + print "Skipping test_empty_pr, no GitHub token available?" return # get file from develop branch full_url = URL_SEPARATOR.join([GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO, 'develop/easybuild/easyconfigs/z/zlib/zlib-1.2.8.eb']) - ec = download_file('zlib-1.2.8.eb', full_url, path=os.path.join(self.test_prefix, 'zlib-1.2.8.eb'), forced=True) + ec_fn = os.path.basename(full_url) + ec = download_file(ec_fn, full_url, path=os.path.join(self.test_prefix, ec_fn)) # try to open new pr with unchanged file - os.environ['EASYBUILD_GITHUB_USER'] = GITHUB_TEST_ACCOUNT args = [ '--new-pr', '--experimental', ec, '-D', + '--github-user=%s' % GITHUB_TEST_ACCOUNT, ] self.mock_stdout(True)