apycotlib: give a more useful error when a project env has no repository stable
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 02 May 2013 16:54:45 +0200
branchstable
changeset 920 d5aa45f491cf
parent 916 c4e0dc323528
child 921 7e2fab53d5c8
apycotlib: give a more useful error when a project env has no repository Replaces AttributeError: 'NoneType' object has no attribute 'type' with Exception: Project environment foo has no repository
_apycotlib/atest.py
test/unittest_task.py
--- a/_apycotlib/atest.py	Wed May 15 11:03:37 2013 +0200
+++ b/_apycotlib/atest.py	Thu May 02 16:54:45 2013 +0200
@@ -122,6 +122,8 @@
             return self._repositories[pe.eid]
         except KeyError:
             from apycotlib.repositories import get_repository
+            if not pe.repository:
+                raise Exception('Project environment %s has no repository' % pe.dc_title())
             repdef = {'repository': pe.repository,
                       'path': pe.vcs_path,
                       'branch': self.branch}
--- a/test/unittest_task.py	Wed May 15 11:03:37 2013 +0200
+++ b/test/unittest_task.py	Thu May 02 16:54:45 2013 +0200
@@ -14,7 +14,6 @@
 from apycotlib.atest import Test as BaseTest
 from apycotlib.repositories import SVNRepository
 
-
 # manage temporary repo
 def setUpModule():
     for repo in ('badpkg2_svn', 'goodpkg_svn'):
@@ -98,6 +97,9 @@
     def apycot_process_environment(self):
         return {}
 
+    def dc_title(self):
+        return self.name
+
 # mock objects ################################################################
 
 class CleanRaisePreprocessor:
@@ -378,6 +380,13 @@
         # default should be the branch name (as none is defined)
         self.assertEqual(repo.branch, 'default')
 
+    def test_missing_repo(self):
+        dep = Environment('babar', repository=None)
+        test = Test(TestConfig('yo', dependencies=(dep,)),
+                    MockTestWriter(), {},
+                    checkers=[SuccessTestChecker()])
+        self.assertRaises(Exception, test.apycot_repository, dep)
+
 
 class EnvironmentTrackerMixinTC(TestCase):