|
5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php |
6 | 6 |
|
7 | 7 | importos |
| 8 | +fromgitimportRepo |
| 9 | +fromunittestimportTestCase |
8 | 10 |
|
9 | 11 | GIT_REPO=os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
10 | 12 |
|
@@ -58,3 +60,99 @@ def wait(self): |
58 | 60 | return0 |
59 | 61 |
|
60 | 62 | poll=wait |
| 63 | + |
| 64 | + |
| 65 | +defwith_bare_rw_repo(func): |
| 66 | +""" |
| 67 | +Decorator providing a specially made read-write repository to the test case |
| 68 | +decorated with it. The test case requires the following signature:: |
| 69 | +def case(self, rw_repo) |
| 70 | +
|
| 71 | +The rwrepo will be a bare clone or the types rorepo. Once the method finishes, |
| 72 | +it will be removed completely. |
| 73 | +
|
| 74 | +Use this if you want to make purely index based adjustments, change refs, create |
| 75 | +heads, generally operations that do not need a working tree. |
| 76 | +""" |
| 77 | +defbare_repo_creator(self): |
| 78 | +rw_repo=None |
| 79 | +try: |
| 80 | +returnfunc(self,rw_repo) |
| 81 | +finally: |
| 82 | +pass |
| 83 | +# END cleanup |
| 84 | +# END bare repo creator |
| 85 | +bare_repo_creator.__name__=func.__name__ |
| 86 | +returnbare_repo_creator |
| 87 | + |
| 88 | +defwith_rw_repo(func,working_tree_ref='0.1.6'): |
| 89 | +""" |
| 90 | +Same as with_bare_repo, but clones the rorepo as non-bare repository, checking |
| 91 | +out the working tree at the given working_tree_ref. |
| 92 | +
|
| 93 | +This repository type is more costly due to the working copy checkout. |
| 94 | +""" |
| 95 | +defrepo_creator(self): |
| 96 | +rw_repo=None |
| 97 | +try: |
| 98 | +returnfunc(self,rw_repo) |
| 99 | +finally: |
| 100 | +pass |
| 101 | +# END cleanup |
| 102 | +# END bare repo creator |
| 103 | +repo_creator.__name__=func.__name__ |
| 104 | +returnrepo_creator |
| 105 | + |
| 106 | +defwith_rw_and_rw_remote_repo(func): |
| 107 | +""" |
| 108 | +Same as with_rw_repo, but also provides a writable remote repository from which the |
| 109 | +rw_repo has been forked. The remote repository was cloned as bare repository from |
| 110 | +the rorepo, wheras the rw repo has a working tree and was cloned from the remote repository. |
| 111 | +
|
| 112 | +The following scetch demonstrates this:: |
| 113 | + rorepo ---<bare clone>---> rw_remote_repo ---<clone>---> rw_repo |
| 114 | +
|
| 115 | +The test case needs to support the following signature:: |
| 116 | +def case(self, rw_repo, rw_remote_repo) |
| 117 | +
|
| 118 | +This setup allows you to test push and pull scenarios and hooks nicely. |
| 119 | +""" |
| 120 | +defremote_repo_creator(self): |
| 121 | +rw_repo=None |
| 122 | +rw_remote_repo=None |
| 123 | +try: |
| 124 | +returnfunc(self,rw_repo,rw_remote_repo) |
| 125 | +finally: |
| 126 | +pass |
| 127 | +# END cleanup |
| 128 | +# END bare repo creator |
| 129 | +remote_repo_creator.__name__=func.__name__ |
| 130 | +returnremote_repo_creator |
| 131 | + |
| 132 | + |
| 133 | +classTestBase(TestCase): |
| 134 | +""" |
| 135 | +Base Class providing default functionality to all tests such as: |
| 136 | +
|
| 137 | +- Utility functions provided by the TestCase base of the unittest method such as:: |
| 138 | +self.fail("todo") |
| 139 | +self.failUnlessRaises(...) |
| 140 | +
|
| 141 | +- Class level repository which is considered read-only as it is shared among |
| 142 | + all test cases in your type. |
| 143 | + Access it using:: |
| 144 | + self.rorepo# 'ro' stands for read-only |
| 145 | +
|
| 146 | + The rorepo is in fact your current project's git repo. If you refer to specific |
| 147 | + shas for your objects, be sure you choose some that are part of the immutable portion |
| 148 | + of the project history ( to assure tests don't fail for others ). |
| 149 | +""" |
| 150 | + |
| 151 | +@classmethod |
| 152 | +defsetUpAll(cls): |
| 153 | +""" |
| 154 | +Dynamically add a read-only repository to our actual type. This way |
| 155 | +each test type has its own repository |
| 156 | +""" |
| 157 | +cls.rorepo=Repo(GIT_REPO) |
| 158 | + |