From 14015af4758814522de83b4877a1e5b2b48eb396 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 6 Aug 2014 15:11:01 -0600 Subject: [PATCH] Move exception into a new exceptions module Signed-off-by: Zack Cerza --- teuthology/exceptions.py | 13 +++++++++++++ teuthology/repo_utils.py | 15 +-------------- teuthology/suite.py | 3 ++- teuthology/test/test_repo_utils.py | 13 +++++++------ teuthology/worker.py | 2 +- 5 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 teuthology/exceptions.py diff --git a/teuthology/exceptions.py b/teuthology/exceptions.py new file mode 100644 index 0000000000..4ace8b43ca --- /dev/null +++ b/teuthology/exceptions.py @@ -0,0 +1,13 @@ + +class BranchNotFoundError(ValueError): + def __init__(self, branch, repo=None): + self.branch = branch + self.repo = repo + + def __str__(self): + if self.repo: + repo_str = " in repo: %s" % self.repo + else: + repo_str = "" + return "Branch '{branch}' not found{repo_str}!".format( + branch=self.branch, repo_str=repo_str) diff --git a/teuthology/repo_utils.py b/teuthology/repo_utils.py index 23182f0037..40d45530d1 100644 --- a/teuthology/repo_utils.py +++ b/teuthology/repo_utils.py @@ -6,6 +6,7 @@ import subprocess import time from .config import config +from .exceptions import BranchNotFoundError log = logging.getLogger(__name__) @@ -136,20 +137,6 @@ def reset_repo(repo_url, dest_path, branch): raise BranchNotFoundError(branch, repo_url) -class BranchNotFoundError(ValueError): - def __init__(self, branch, repo=None): - self.branch = branch - self.repo = repo - - def __str__(self): - if self.repo: - repo_str = " in repo: %s" % self.repo - else: - repo_str = "" - return "Branch '{branch}' not found{repo_str}!".format( - branch=self.branch, repo_str=repo_str) - - def validate_branch(branch): if ' ' in branch: raise ValueError("Illegal branch name: '%s'" % branch) diff --git a/teuthology/suite.py b/teuthology/suite.py index 365450dc57..fe2bd24188 100644 --- a/teuthology/suite.py +++ b/teuthology/suite.py @@ -19,7 +19,8 @@ from tempfile import NamedTemporaryFile import teuthology from . import lock from .config import config, JobConfig -from .repo_utils import enforce_repo_state, BranchNotFoundError +from .repo_utils import enforce_repo_state +from .exceptions import BranchNotFoundError log = logging.getLogger(__name__) diff --git a/teuthology/test/test_repo_utils.py b/teuthology/test/test_repo_utils.py index d85fed8dbc..75def4ced5 100644 --- a/teuthology/test/test_repo_utils.py +++ b/teuthology/test/test_repo_utils.py @@ -5,6 +5,7 @@ from pytest import raises import shutil import subprocess +from ..exceptions import BranchNotFoundError from .. import repo_utils from .. import parallel repo_utils.log.setLevel(logging.WARNING) @@ -61,7 +62,7 @@ class TestRepoUtils(object): assert os.path.exists(self.dest_path) def test_clone_repo_non_existing_branch(self): - with raises(repo_utils.BranchNotFoundError): + with raises(BranchNotFoundError): repo_utils.clone_repo(self.repo_url, self.dest_path, 'nobranch') assert not os.path.exists(self.dest_path) @@ -86,7 +87,7 @@ class TestRepoUtils(object): def test_fetch_branch_fake_branch(self): repo_utils.clone_repo(self.repo_url, self.dest_path, 'master') - with raises(repo_utils.BranchNotFoundError): + with raises(BranchNotFoundError): repo_utils.fetch_branch(self.dest_path, 'nobranch') def test_enforce_existing_branch(self): @@ -95,7 +96,7 @@ class TestRepoUtils(object): assert os.path.exists(self.dest_path) def test_enforce_non_existing_branch(self): - with raises(repo_utils.BranchNotFoundError): + with raises(BranchNotFoundError): repo_utils.enforce_repo_state(self.repo_url, self.dest_path, 'blah') assert not os.path.exists(self.dest_path) @@ -112,7 +113,7 @@ class TestRepoUtils(object): assert os.path.exists(self.dest_path) def test_enforce_multiple_calls_different_branches(self): - with raises(repo_utils.BranchNotFoundError): + with raises(BranchNotFoundError): repo_utils.enforce_repo_state(self.repo_url, self.dest_path, 'blah1') assert not os.path.exists(self.dest_path) @@ -122,7 +123,7 @@ class TestRepoUtils(object): repo_utils.enforce_repo_state(self.repo_url, self.dest_path, 'master') assert os.path.exists(self.dest_path) - with raises(repo_utils.BranchNotFoundError): + with raises(BranchNotFoundError): repo_utils.enforce_repo_state(self.repo_url, self.dest_path, 'blah2') assert not os.path.exists(self.dest_path) @@ -161,7 +162,7 @@ class TestRepoUtils(object): branch) p.spawn( raises, - repo_utils.BranchNotFoundError, + BranchNotFoundError, func, ) for result in p: diff --git a/teuthology/worker.py b/teuthology/worker.py index 24a6b6efab..01efab371f 100644 --- a/teuthology/worker.py +++ b/teuthology/worker.py @@ -13,9 +13,9 @@ from . import beanstalk from . import report from . import safepath from .config import config as teuth_config +from .exceptions import BranchNotFoundError from .kill import kill_job from .misc import read_config -from .repo_utils import BranchNotFoundError from .repo_utils import fetch_qa_suite, fetch_teuthology_branch log = logging.getLogger(__name__) -- 2.39.5