From 29a2b45fb45ffe4110fcb27fe06ec0a24ae294dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 12 Apr 2016 13:34:41 +0200 Subject: [PATCH] [scm-wrapper] Report when file wrapper did not match anything MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- pungi/wrappers/scm.py | 4 ++++ tests/test_scm.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pungi/wrappers/scm.py b/pungi/wrappers/scm.py index 66e66599..b3ec6e14 100644 --- a/pungi/wrappers/scm.py +++ b/pungi/wrappers/scm.py @@ -76,6 +76,8 @@ class FileWrapper(ScmBase): if scm_root: raise ValueError("FileWrapper: 'scm_root' should be empty.") dirs = glob.glob(scm_dir) + if not dirs: + raise RuntimeError('No directories matched, can not export.') for i in dirs: _copy_all(i, target_dir) @@ -83,6 +85,8 @@ class FileWrapper(ScmBase): if scm_root: raise ValueError("FileWrapper: 'scm_root' should be empty.") files = glob.glob(scm_file) + if not files: + raise RuntimeError('No files matched, can not export.') for i in files: target_path = os.path.join(target_dir, os.path.basename(i)) shutil.copy2(i, target_path) diff --git a/tests/test_scm.py b/tests/test_scm.py index 8c9b33fd..624381a5 100755 --- a/tests/test_scm.py +++ b/tests/test_scm.py @@ -69,6 +69,24 @@ class FileSCMTestCase(unittest.TestCase): self.assertTrue(os.path.isfile(os.path.join(self.destdir, 'first'))) self.assertTrue(os.path.isfile(os.path.join(self.destdir, 'second'))) + def test_get_missing_file(self): + with self.assertRaises(RuntimeError) as ctx: + scm.get_file_from_scm({'scm': 'file', + 'repo': None, + 'file': 'this-is-really-not-here.txt'}, + self.destdir) + + self.assertIn('No files matched', str(ctx.exception)) + + def test_get_missing_dir(self): + with self.assertRaises(RuntimeError) as ctx: + scm.get_dir_from_scm({'scm': 'file', + 'repo': None, + 'dir': 'this-is-really-not-here'}, + self.destdir) + + self.assertIn('No directories matched', str(ctx.exception)) + class GitSCMTestCase(unittest.TestCase): def setUp(self):