|
6 | 6 |
|
7 | 7 | importglob
|
8 | 8 | importio
|
| 9 | +importos |
| 10 | +fromunittestimportmock |
9 | 11 |
|
10 | 12 | fromgitimport (
|
11 | 13 | GitConfigParser
|
@@ -238,6 +240,103 @@ def check_test_value(cr, value):
|
238 | 240 | withGitConfigParser(fpa,read_only=True)ascr:
|
239 | 241 | check_test_value(cr,tv)
|
240 | 242 |
|
| 243 | +@with_rw_directory |
| 244 | +deftest_conditional_includes_from_git_dir(self,rw_dir): |
| 245 | +# Initiate repository path |
| 246 | +git_dir=osp.join(rw_dir,"target1","repo1") |
| 247 | +os.makedirs(git_dir) |
| 248 | + |
| 249 | +# Initiate mocked repository |
| 250 | +repo=mock.Mock(git_dir=git_dir) |
| 251 | + |
| 252 | +# Initiate config files. |
| 253 | +path1=osp.join(rw_dir,"config1") |
| 254 | +path2=osp.join(rw_dir,"config2") |
| 255 | +template="[includeIf\"{}:{}\"]\n path={}\n" |
| 256 | + |
| 257 | +withopen(path1,"w")asstream: |
| 258 | +stream.write(template.format("gitdir",git_dir,path2)) |
| 259 | + |
| 260 | +# Ensure that config is ignored if no repo is set. |
| 261 | +withGitConfigParser(path1)asconfig: |
| 262 | +assertnotconfig._has_includes() |
| 263 | +assertconfig._included_paths()== [] |
| 264 | + |
| 265 | +# Ensure that config is included if path is matching git_dir. |
| 266 | +withGitConfigParser(path1,repo=repo)asconfig: |
| 267 | +assertconfig._has_includes() |
| 268 | +assertconfig._included_paths()== [("path",path2)] |
| 269 | + |
| 270 | +# Ensure that config is ignored if case is incorrect. |
| 271 | +withopen(path1,"w")asstream: |
| 272 | +stream.write(template.format("gitdir",git_dir.upper(),path2)) |
| 273 | + |
| 274 | +withGitConfigParser(path1,repo=repo)asconfig: |
| 275 | +assertnotconfig._has_includes() |
| 276 | +assertconfig._included_paths()== [] |
| 277 | + |
| 278 | +# Ensure that config is included if case is ignored. |
| 279 | +withopen(path1,"w")asstream: |
| 280 | +stream.write(template.format("gitdir/i",git_dir.upper(),path2)) |
| 281 | + |
| 282 | +withGitConfigParser(path1,repo=repo)asconfig: |
| 283 | +assertconfig._has_includes() |
| 284 | +assertconfig._included_paths()== [("path",path2)] |
| 285 | + |
| 286 | +# Ensure that config is included with path using glob pattern. |
| 287 | +withopen(path1,"w")asstream: |
| 288 | +stream.write(template.format("gitdir","**/repo1",path2)) |
| 289 | + |
| 290 | +withGitConfigParser(path1,repo=repo)asconfig: |
| 291 | +assertconfig._has_includes() |
| 292 | +assertconfig._included_paths()== [("path",path2)] |
| 293 | + |
| 294 | +# Ensure that config is ignored if path is not matching git_dir. |
| 295 | +withopen(path1,"w")asstream: |
| 296 | +stream.write(template.format("gitdir","incorrect",path2)) |
| 297 | + |
| 298 | +withGitConfigParser(path1,repo=repo)asconfig: |
| 299 | +assertnotconfig._has_includes() |
| 300 | +assertconfig._included_paths()== [] |
| 301 | + |
| 302 | +@with_rw_directory |
| 303 | +deftest_conditional_includes_from_branch_name(self,rw_dir): |
| 304 | +# Initiate mocked branch |
| 305 | +branch=mock.Mock() |
| 306 | + type(branch).name=mock.PropertyMock(return_value="/foo/branch") |
| 307 | + |
| 308 | +# Initiate mocked repository |
| 309 | +repo=mock.Mock(active_branch=branch) |
| 310 | + |
| 311 | +# Initiate config files. |
| 312 | +path1=osp.join(rw_dir,"config1") |
| 313 | +path2=osp.join(rw_dir,"config2") |
| 314 | +template="[includeIf\"onbranch:{}\"]\n path={}\n" |
| 315 | + |
| 316 | +# Ensure that config is included is branch is correct. |
| 317 | +withopen(path1,"w")asstream: |
| 318 | +stream.write(template.format("/foo/branch",path2)) |
| 319 | + |
| 320 | +withGitConfigParser(path1,repo=repo)asconfig: |
| 321 | +assertconfig._has_includes() |
| 322 | +assertconfig._included_paths()== [("path",path2)] |
| 323 | + |
| 324 | +# Ensure that config is included is branch is incorrect. |
| 325 | +withopen(path1,"w")asstream: |
| 326 | +stream.write(template.format("incorrect",path2)) |
| 327 | + |
| 328 | +withGitConfigParser(path1,repo=repo)asconfig: |
| 329 | +assertnotconfig._has_includes() |
| 330 | +assertconfig._included_paths()== [] |
| 331 | + |
| 332 | +# Ensure that config is included with branch using glob pattern. |
| 333 | +withopen(path1,"w")asstream: |
| 334 | +stream.write(template.format("/foo/**",path2)) |
| 335 | + |
| 336 | +withGitConfigParser(path1,repo=repo)asconfig: |
| 337 | +assertconfig._has_includes() |
| 338 | +assertconfig._included_paths()== [("path",path2)] |
| 339 | + |
241 | 340 | deftest_rename(self):
|
242 | 341 | file_obj=self._to_memcache(fixture_path('git_config'))
|
243 | 342 | withGitConfigParser(file_obj,read_only=False,merge_includes=False)ascw:
|
|