diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-11-14 11:36:51 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-11-14 11:38:57 +0900 |
commit | c1b86a232383748811c6faf17f364e63e10f7dd4 (patch) | |
tree | 8f28c8e8a922ffd4165f48a1988500070936bd39 | |
parent | 98ffba1401056e2d88d3f3898b6fbf5d7d3931a4 (diff) | |
download | git-repo-c1b86a232383748811c6faf17f364e63e10f7dd4.tar.gz |
Fix inconsistent indentation
The repo coding style is to indent at 2 characters, but there are
many places where this is not followed.
Enable pylint warning "W0311: Bad indentation" and make sure all
indentation is at multiples of 2 characters.
Change-Id: I68f0f64470789ce2429ab11104d15d380a63e6a8
-rw-r--r-- | .pylintrc | 2 | ||||
-rw-r--r-- | color.py | 62 | ||||
-rw-r--r-- | git_config.py | 6 | ||||
-rwxr-xr-x | main.py | 22 | ||||
-rw-r--r-- | manifest_xml.py | 44 | ||||
-rw-r--r-- | project.py | 32 | ||||
-rw-r--r-- | subcmds/sync.py | 168 | ||||
-rw-r--r-- | subcmds/upload.py | 38 | ||||
-rw-r--r-- | tests/test_git_config.py | 82 |
9 files changed, 228 insertions, 228 deletions
@@ -53,7 +53,7 @@ load-plugins= | |||
53 | enable=RP0004 | 53 | enable=RP0004 |
54 | 54 | ||
55 | # Disable the message(s) with the given id(s). | 55 | # Disable the message(s) with the given id(s). |
56 | disable=R0903,R0912,R0913,R0914,R0915,W0141,C0111,C0103,C0323,C0322,C0324,W0603,W0703,R0911,C0301,C0302,R0902,R0904,W0142,W0212,E1101,E1103,R0201,W0201,W0122,W0232,W0311,RP0001,RP0003,RP0101,RP0002,RP0401,RP0701,RP0801 | 56 | disable=R0903,R0912,R0913,R0914,R0915,W0141,C0111,C0103,C0323,C0322,C0324,W0603,W0703,R0911,C0301,C0302,R0902,R0904,W0142,W0212,E1101,E1103,R0201,W0201,W0122,W0232,RP0001,RP0003,RP0101,RP0002,RP0401,RP0701,RP0801 |
57 | 57 | ||
58 | [REPORTS] | 58 | [REPORTS] |
59 | 59 | ||
@@ -40,47 +40,47 @@ RESET = "\033[m" # pylint: disable=W1401 | |||
40 | # backslash is not anomalous | 40 | # backslash is not anomalous |
41 | 41 | ||
42 | def is_color(s): | 42 | def is_color(s): |
43 | return s in COLORS | 43 | return s in COLORS |
44 | 44 | ||
45 | def is_attr(s): | 45 | def is_attr(s): |
46 | return s in ATTRS | 46 | return s in ATTRS |
47 | 47 | ||
48 | def _Color(fg = None, bg = None, attr = None): | 48 | def _Color(fg = None, bg = None, attr = None): |
49 | fg = COLORS[fg] | 49 | fg = COLORS[fg] |
50 | bg = COLORS[bg] | 50 | bg = COLORS[bg] |
51 | attr = ATTRS[attr] | 51 | attr = ATTRS[attr] |
52 | 52 | ||
53 | if attr >= 0 or fg >= 0 or bg >= 0: | 53 | if attr >= 0 or fg >= 0 or bg >= 0: |
54 | need_sep = False | 54 | need_sep = False |
55 | code = "\033[" #pylint: disable=W1401 | 55 | code = "\033[" #pylint: disable=W1401 |
56 | 56 | ||
57 | if attr >= 0: | 57 | if attr >= 0: |
58 | code += chr(ord('0') + attr) | 58 | code += chr(ord('0') + attr) |
59 | need_sep = True | 59 | need_sep = True |
60 | 60 | ||
61 | if fg >= 0: | 61 | if fg >= 0: |
62 | if need_sep: | 62 | if need_sep: |
63 | code += ';' | 63 | code += ';' |
64 | need_sep = True | 64 | need_sep = True |
65 | 65 | ||
66 | if fg < 8: | 66 | if fg < 8: |
67 | code += '3%c' % (ord('0') + fg) | 67 | code += '3%c' % (ord('0') + fg) |
68 | else: | 68 | else: |
69 | code += '38;5;%d' % fg | 69 | code += '38;5;%d' % fg |
70 | 70 | ||
71 | if bg >= 0: | 71 | if bg >= 0: |
72 | if need_sep: | 72 | if need_sep: |
73 | code += ';' | 73 | code += ';' |
74 | need_sep = True | 74 | need_sep = True |
75 | 75 | ||
76 | if bg < 8: | 76 | if bg < 8: |
77 | code += '4%c' % (ord('0') + bg) | 77 | code += '4%c' % (ord('0') + bg) |
78 | else: | 78 | else: |
79 | code += '48;5;%d' % bg | 79 | code += '48;5;%d' % bg |
80 | code += 'm' | 80 | code += 'm' |
81 | else: | 81 | else: |
82 | code = '' | 82 | code = '' |
83 | return code | 83 | return code |
84 | 84 | ||
85 | 85 | ||
86 | class Coloring(object): | 86 | class Coloring(object): |
diff --git a/git_config.py b/git_config.py index 6bb92003..108438f6 100644 --- a/git_config.py +++ b/git_config.py | |||
@@ -303,10 +303,10 @@ class GitConfig(object): | |||
303 | for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401 | 303 | for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401 |
304 | # Backslash is not anomalous | 304 | # Backslash is not anomalous |
305 | if '\n' in line: | 305 | if '\n' in line: |
306 | key, val = line.split('\n', 1) | 306 | key, val = line.split('\n', 1) |
307 | else: | 307 | else: |
308 | key = line | 308 | key = line |
309 | val = None | 309 | val = None |
310 | 310 | ||
311 | if key in c: | 311 | if key in c: |
312 | c[key].append(val) | 312 | c[key].append(val) |
@@ -275,17 +275,17 @@ class _UserAgentHandler(urllib.request.BaseHandler): | |||
275 | return req | 275 | return req |
276 | 276 | ||
277 | def _AddPasswordFromUserInput(handler, msg, req): | 277 | def _AddPasswordFromUserInput(handler, msg, req): |
278 | # If repo could not find auth info from netrc, try to get it from user input | 278 | # If repo could not find auth info from netrc, try to get it from user input |
279 | url = req.get_full_url() | 279 | url = req.get_full_url() |
280 | user, password = handler.passwd.find_user_password(None, url) | 280 | user, password = handler.passwd.find_user_password(None, url) |
281 | if user is None: | 281 | if user is None: |
282 | print(msg) | 282 | print(msg) |
283 | try: | 283 | try: |
284 | user = raw_input('User: ') | 284 | user = raw_input('User: ') |
285 | password = getpass.getpass() | 285 | password = getpass.getpass() |
286 | except KeyboardInterrupt: | 286 | except KeyboardInterrupt: |
287 | return | 287 | return |
288 | handler.passwd.add_password(None, url, user, password) | 288 | handler.passwd.add_password(None, url, user, password) |
289 | 289 | ||
290 | class _BasicAuthHandler(urllib.request.HTTPBasicAuthHandler): | 290 | class _BasicAuthHandler(urllib.request.HTTPBasicAuthHandler): |
291 | def http_error_401(self, req, fp, code, msg, headers): | 291 | def http_error_401(self, req, fp, code, msg, headers): |
diff --git a/manifest_xml.py b/manifest_xml.py index bb93bca3..1b954561 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -67,7 +67,7 @@ class _XmlRemote(object): | |||
67 | # urljoin will get confused if there is no scheme in the base url | 67 | # urljoin will get confused if there is no scheme in the base url |
68 | # ie, if manifestUrl is of the form <hostname:port> | 68 | # ie, if manifestUrl is of the form <hostname:port> |
69 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: | 69 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: |
70 | manifestUrl = 'gopher://' + manifestUrl | 70 | manifestUrl = 'gopher://' + manifestUrl |
71 | url = urlparse.urljoin(manifestUrl, url) | 71 | url = urlparse.urljoin(manifestUrl, url) |
72 | return re.sub(r'^gopher://', '', url) | 72 | return re.sub(r'^gopher://', '', url) |
73 | 73 | ||
@@ -349,24 +349,24 @@ class XmlManifest(object): | |||
349 | nodes = [] | 349 | nodes = [] |
350 | for node in manifest.childNodes: # pylint:disable=W0631 | 350 | for node in manifest.childNodes: # pylint:disable=W0631 |
351 | # We only get here if manifest is initialised | 351 | # We only get here if manifest is initialised |
352 | if node.nodeName == 'include': | 352 | if node.nodeName == 'include': |
353 | name = self._reqatt(node, 'name') | 353 | name = self._reqatt(node, 'name') |
354 | fp = os.path.join(include_root, name) | 354 | fp = os.path.join(include_root, name) |
355 | if not os.path.isfile(fp): | 355 | if not os.path.isfile(fp): |
356 | raise ManifestParseError, \ | 356 | raise ManifestParseError, \ |
357 | "include %s doesn't exist or isn't a file" % \ | 357 | "include %s doesn't exist or isn't a file" % \ |
358 | (name,) | 358 | (name,) |
359 | try: | 359 | try: |
360 | nodes.extend(self._ParseManifestXml(fp, include_root)) | 360 | nodes.extend(self._ParseManifestXml(fp, include_root)) |
361 | # should isolate this to the exact exception, but that's | 361 | # should isolate this to the exact exception, but that's |
362 | # tricky. actual parsing implementation may vary. | 362 | # tricky. actual parsing implementation may vary. |
363 | except (KeyboardInterrupt, RuntimeError, SystemExit): | 363 | except (KeyboardInterrupt, RuntimeError, SystemExit): |
364 | raise | 364 | raise |
365 | except Exception as e: | 365 | except Exception as e: |
366 | raise ManifestParseError( | 366 | raise ManifestParseError( |
367 | "failed parsing included manifest %s: %s", (name, e)) | 367 | "failed parsing included manifest %s: %s", (name, e)) |
368 | else: | 368 | else: |
369 | nodes.append(node) | 369 | nodes.append(node) |
370 | return nodes | 370 | return nodes |
371 | 371 | ||
372 | def _ParseManifest(self, node_list): | 372 | def _ParseManifest(self, node_list): |
@@ -404,9 +404,9 @@ class XmlManifest(object): | |||
404 | if node.nodeName == 'manifest-server': | 404 | if node.nodeName == 'manifest-server': |
405 | url = self._reqatt(node, 'url') | 405 | url = self._reqatt(node, 'url') |
406 | if self._manifest_server is not None: | 406 | if self._manifest_server is not None: |
407 | raise ManifestParseError( | 407 | raise ManifestParseError( |
408 | 'duplicate manifest-server in %s' % | 408 | 'duplicate manifest-server in %s' % |
409 | (self.manifestFile)) | 409 | (self.manifestFile)) |
410 | self._manifest_server = url | 410 | self._manifest_server = url |
411 | 411 | ||
412 | for node in itertools.chain(*node_list): | 412 | for node in itertools.chain(*node_list): |
@@ -585,14 +585,14 @@ class Project(object): | |||
585 | return self._userident_email | 585 | return self._userident_email |
586 | 586 | ||
587 | def _LoadUserIdentity(self): | 587 | def _LoadUserIdentity(self): |
588 | u = self.bare_git.var('GIT_COMMITTER_IDENT') | 588 | u = self.bare_git.var('GIT_COMMITTER_IDENT') |
589 | m = re.compile("^(.*) <([^>]*)> ").match(u) | 589 | m = re.compile("^(.*) <([^>]*)> ").match(u) |
590 | if m: | 590 | if m: |
591 | self._userident_name = m.group(1) | 591 | self._userident_name = m.group(1) |
592 | self._userident_email = m.group(2) | 592 | self._userident_email = m.group(2) |
593 | else: | 593 | else: |
594 | self._userident_name = '' | 594 | self._userident_name = '' |
595 | self._userident_email = '' | 595 | self._userident_email = '' |
596 | 596 | ||
597 | def GetRemote(self, name): | 597 | def GetRemote(self, name): |
598 | """Get the configuration for a single remote. | 598 | """Get the configuration for a single remote. |
@@ -1381,14 +1381,14 @@ class Project(object): | |||
1381 | tag_name = None | 1381 | tag_name = None |
1382 | 1382 | ||
1383 | def CheckForSha1(): | 1383 | def CheckForSha1(): |
1384 | try: | 1384 | try: |
1385 | # if revision (sha or tag) is not present then following function | 1385 | # if revision (sha or tag) is not present then following function |
1386 | # throws an error. | 1386 | # throws an error. |
1387 | self.bare_git.rev_parse('--verify', '%s^0' % self.revisionExpr) | 1387 | self.bare_git.rev_parse('--verify', '%s^0' % self.revisionExpr) |
1388 | return True | 1388 | return True |
1389 | except GitError: | 1389 | except GitError: |
1390 | # There is no such persistent revision. We have to fetch it. | 1390 | # There is no such persistent revision. We have to fetch it. |
1391 | return False | 1391 | return False |
1392 | 1392 | ||
1393 | if current_branch_only: | 1393 | if current_branch_only: |
1394 | if ID_RE.match(self.revisionExpr) is not None: | 1394 | if ID_RE.match(self.revisionExpr) is not None: |
diff --git a/subcmds/sync.py b/subcmds/sync.py index a64f2c45..df64ab09 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -197,62 +197,62 @@ later is required to fix a server side protocol bug. | |||
197 | help=SUPPRESS_HELP) | 197 | help=SUPPRESS_HELP) |
198 | 198 | ||
199 | def _FetchHelper(self, opt, project, lock, fetched, pm, sem, err_event): | 199 | def _FetchHelper(self, opt, project, lock, fetched, pm, sem, err_event): |
200 | """Main function of the fetch threads when jobs are > 1. | 200 | """Main function of the fetch threads when jobs are > 1. |
201 | 201 | ||
202 | Args: | 202 | Args: |
203 | opt: Program options returned from optparse. See _Options(). | 203 | opt: Program options returned from optparse. See _Options(). |
204 | project: Project object for the project to fetch. | 204 | project: Project object for the project to fetch. |
205 | lock: Lock for accessing objects that are shared amongst multiple | 205 | lock: Lock for accessing objects that are shared amongst multiple |
206 | _FetchHelper() threads. | 206 | _FetchHelper() threads. |
207 | fetched: set object that we will add project.gitdir to when we're done | 207 | fetched: set object that we will add project.gitdir to when we're done |
208 | (with our lock held). | 208 | (with our lock held). |
209 | pm: Instance of a Project object. We will call pm.update() (with our | 209 | pm: Instance of a Project object. We will call pm.update() (with our |
210 | lock held). | 210 | lock held). |
211 | sem: We'll release() this semaphore when we exit so that another thread | 211 | sem: We'll release() this semaphore when we exit so that another thread |
212 | can be started up. | 212 | can be started up. |
213 | err_event: We'll set this event in the case of an error (after printing | 213 | err_event: We'll set this event in the case of an error (after printing |
214 | out info about the error). | 214 | out info about the error). |
215 | """ | 215 | """ |
216 | # We'll set to true once we've locked the lock. | 216 | # We'll set to true once we've locked the lock. |
217 | did_lock = False | 217 | did_lock = False |
218 | 218 | ||
219 | # Encapsulate everything in a try/except/finally so that: | 219 | # Encapsulate everything in a try/except/finally so that: |
220 | # - We always set err_event in the case of an exception. | 220 | # - We always set err_event in the case of an exception. |
221 | # - We always make sure we call sem.release(). | 221 | # - We always make sure we call sem.release(). |
222 | # - We always make sure we unlock the lock if we locked it. | 222 | # - We always make sure we unlock the lock if we locked it. |
223 | try: | ||
223 | try: | 224 | try: |
224 | try: | 225 | start = time.time() |
225 | start = time.time() | 226 | success = project.Sync_NetworkHalf( |
226 | success = project.Sync_NetworkHalf( | 227 | quiet=opt.quiet, |
227 | quiet=opt.quiet, | 228 | current_branch_only=opt.current_branch_only, |
228 | current_branch_only=opt.current_branch_only, | 229 | clone_bundle=not opt.no_clone_bundle) |
229 | clone_bundle=not opt.no_clone_bundle) | 230 | self._fetch_times.Set(project, time.time() - start) |
230 | self._fetch_times.Set(project, time.time() - start) | 231 | |
231 | 232 | # Lock around all the rest of the code, since printing, updating a set | |
232 | # Lock around all the rest of the code, since printing, updating a set | 233 | # and Progress.update() are not thread safe. |
233 | # and Progress.update() are not thread safe. | 234 | lock.acquire() |
234 | lock.acquire() | 235 | did_lock = True |
235 | did_lock = True | 236 | |
236 | 237 | if not success: | |
237 | if not success: | 238 | print('error: Cannot fetch %s' % project.name, file=sys.stderr) |
238 | print('error: Cannot fetch %s' % project.name, file=sys.stderr) | 239 | if opt.force_broken: |
239 | if opt.force_broken: | 240 | print('warn: --force-broken, continuing to sync', |
240 | print('warn: --force-broken, continuing to sync', | 241 | file=sys.stderr) |
241 | file=sys.stderr) | 242 | else: |
242 | else: | 243 | raise _FetchError() |
243 | raise _FetchError() | ||
244 | 244 | ||
245 | fetched.add(project.gitdir) | 245 | fetched.add(project.gitdir) |
246 | pm.update() | 246 | pm.update() |
247 | except _FetchError: | 247 | except _FetchError: |
248 | err_event.set() | 248 | err_event.set() |
249 | except: | 249 | except: |
250 | err_event.set() | 250 | err_event.set() |
251 | raise | 251 | raise |
252 | finally: | 252 | finally: |
253 | if did_lock: | 253 | if did_lock: |
254 | lock.release() | 254 | lock.release() |
255 | sem.release() | 255 | sem.release() |
256 | 256 | ||
257 | def _Fetch(self, projects, opt): | 257 | def _Fetch(self, projects, opt): |
258 | fetched = set() | 258 | fetched = set() |
@@ -379,36 +379,36 @@ later is required to fix a server side protocol bug. | |||
379 | if path not in new_project_paths: | 379 | if path not in new_project_paths: |
380 | # If the path has already been deleted, we don't need to do it | 380 | # If the path has already been deleted, we don't need to do it |
381 | if os.path.exists(self.manifest.topdir + '/' + path): | 381 | if os.path.exists(self.manifest.topdir + '/' + path): |
382 | project = Project( | 382 | project = Project( |
383 | manifest = self.manifest, | 383 | manifest = self.manifest, |
384 | name = path, | 384 | name = path, |
385 | remote = RemoteSpec('origin'), | 385 | remote = RemoteSpec('origin'), |
386 | gitdir = os.path.join(self.manifest.topdir, | 386 | gitdir = os.path.join(self.manifest.topdir, |
387 | path, '.git'), | 387 | path, '.git'), |
388 | worktree = os.path.join(self.manifest.topdir, path), | 388 | worktree = os.path.join(self.manifest.topdir, path), |
389 | relpath = path, | 389 | relpath = path, |
390 | revisionExpr = 'HEAD', | 390 | revisionExpr = 'HEAD', |
391 | revisionId = None, | 391 | revisionId = None, |
392 | groups = None) | 392 | groups = None) |
393 | 393 | ||
394 | if project.IsDirty(): | 394 | if project.IsDirty(): |
395 | print('error: Cannot remove project "%s": uncommitted changes' | 395 | print('error: Cannot remove project "%s": uncommitted changes' |
396 | 'are present' % project.relpath, file=sys.stderr) | 396 | 'are present' % project.relpath, file=sys.stderr) |
397 | print(' commit changes, then run sync again', | 397 | print(' commit changes, then run sync again', |
398 | file=sys.stderr) | 398 | file=sys.stderr) |
399 | return -1 | 399 | return -1 |
400 | else: | 400 | else: |
401 | print('Deleting obsolete path %s' % project.worktree, | 401 | print('Deleting obsolete path %s' % project.worktree, |
402 | file=sys.stderr) | 402 | file=sys.stderr) |
403 | shutil.rmtree(project.worktree) | 403 | shutil.rmtree(project.worktree) |
404 | # Try deleting parent subdirs if they are empty | 404 | # Try deleting parent subdirs if they are empty |
405 | project_dir = os.path.dirname(project.worktree) | 405 | project_dir = os.path.dirname(project.worktree) |
406 | while project_dir != self.manifest.topdir: | 406 | while project_dir != self.manifest.topdir: |
407 | try: | 407 | try: |
408 | os.rmdir(project_dir) | 408 | os.rmdir(project_dir) |
409 | except OSError: | 409 | except OSError: |
410 | break | 410 | break |
411 | project_dir = os.path.dirname(project_dir) | 411 | project_dir = os.path.dirname(project_dir) |
412 | 412 | ||
413 | new_project_paths.sort() | 413 | new_project_paths.sort() |
414 | fd = open(file_path, 'w') | 414 | fd = open(file_path, 'w') |
diff --git a/subcmds/upload.py b/subcmds/upload.py index a6ada337..219c5093 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
@@ -312,23 +312,23 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
312 | 312 | ||
313 | # Check if there are local changes that may have been forgotten | 313 | # Check if there are local changes that may have been forgotten |
314 | if branch.project.HasChanges(): | 314 | if branch.project.HasChanges(): |
315 | key = 'review.%s.autoupload' % branch.project.remote.review | 315 | key = 'review.%s.autoupload' % branch.project.remote.review |
316 | answer = branch.project.config.GetBoolean(key) | 316 | answer = branch.project.config.GetBoolean(key) |
317 | 317 | ||
318 | # if they want to auto upload, let's not ask because it could be automated | 318 | # if they want to auto upload, let's not ask because it could be automated |
319 | if answer is None: | 319 | if answer is None: |
320 | sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ') | 320 | sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ') |
321 | a = sys.stdin.readline().strip().lower() | 321 | a = sys.stdin.readline().strip().lower() |
322 | if a not in ('y', 'yes', 't', 'true', 'on'): | 322 | if a not in ('y', 'yes', 't', 'true', 'on'): |
323 | print("skipping upload", file=sys.stderr) | 323 | print("skipping upload", file=sys.stderr) |
324 | branch.uploaded = False | 324 | branch.uploaded = False |
325 | branch.error = 'User aborted' | 325 | branch.error = 'User aborted' |
326 | continue | 326 | continue |
327 | 327 | ||
328 | # Check if topic branches should be sent to the server during upload | 328 | # Check if topic branches should be sent to the server during upload |
329 | if opt.auto_topic is not True: | 329 | if opt.auto_topic is not True: |
330 | key = 'review.%s.uploadtopic' % branch.project.remote.review | 330 | key = 'review.%s.uploadtopic' % branch.project.remote.review |
331 | opt.auto_topic = branch.project.config.GetBoolean(key) | 331 | opt.auto_topic = branch.project.config.GetBoolean(key) |
332 | 332 | ||
333 | branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft) | 333 | branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft) |
334 | branch.uploaded = True | 334 | branch.uploaded = True |
@@ -355,11 +355,11 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
355 | print() | 355 | print() |
356 | 356 | ||
357 | for branch in todo: | 357 | for branch in todo: |
358 | if branch.uploaded: | 358 | if branch.uploaded: |
359 | print('[OK ] %-15s %s' % ( | 359 | print('[OK ] %-15s %s' % ( |
360 | branch.project.relpath + '/', | 360 | branch.project.relpath + '/', |
361 | branch.name), | 361 | branch.name), |
362 | file=sys.stderr) | 362 | file=sys.stderr) |
363 | 363 | ||
364 | if have_errors: | 364 | if have_errors: |
365 | sys.exit(1) | 365 | sys.exit(1) |
diff --git a/tests/test_git_config.py b/tests/test_git_config.py index 5b1770e7..3d4b9970 100644 --- a/tests/test_git_config.py +++ b/tests/test_git_config.py | |||
@@ -4,49 +4,49 @@ import unittest | |||
4 | import git_config | 4 | import git_config |
5 | 5 | ||
6 | def fixture(*paths): | 6 | def fixture(*paths): |
7 | """Return a path relative to test/fixtures. | 7 | """Return a path relative to test/fixtures. |
8 | """ | 8 | """ |
9 | return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) | 9 | return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) |
10 | 10 | ||
11 | class GitConfigUnitTest(unittest.TestCase): | 11 | class GitConfigUnitTest(unittest.TestCase): |
12 | """Tests the GitConfig class. | 12 | """Tests the GitConfig class. |
13 | """ | ||
14 | def setUp(self): | ||
15 | """Create a GitConfig object using the test.gitconfig fixture. | ||
16 | """ | ||
17 | config_fixture = fixture('test.gitconfig') | ||
18 | self.config = git_config.GitConfig(config_fixture) | ||
19 | |||
20 | def test_GetString_with_empty_config_values(self): | ||
21 | """ | ||
22 | Test config entries with no value. | ||
23 | |||
24 | [section] | ||
25 | empty | ||
26 | |||
27 | """ | ||
28 | val = self.config.GetString('section.empty') | ||
29 | self.assertEqual(val, None) | ||
30 | |||
31 | def test_GetString_with_true_value(self): | ||
32 | """ | ||
33 | Test config entries with a string value. | ||
34 | |||
35 | [section] | ||
36 | nonempty = true | ||
37 | |||
38 | """ | ||
39 | val = self.config.GetString('section.nonempty') | ||
40 | self.assertEqual(val, 'true') | ||
41 | |||
42 | def test_GetString_from_missing_file(self): | ||
43 | """ | ||
44 | Test missing config file | ||
13 | """ | 45 | """ |
14 | def setUp(self): | 46 | config_fixture = fixture('not.present.gitconfig') |
15 | """Create a GitConfig object using the test.gitconfig fixture. | 47 | config = git_config.GitConfig(config_fixture) |
16 | """ | 48 | val = config.GetString('empty') |
17 | config_fixture = fixture('test.gitconfig') | 49 | self.assertEqual(val, None) |
18 | self.config = git_config.GitConfig(config_fixture) | ||
19 | |||
20 | def test_GetString_with_empty_config_values(self): | ||
21 | """ | ||
22 | Test config entries with no value. | ||
23 | |||
24 | [section] | ||
25 | empty | ||
26 | |||
27 | """ | ||
28 | val = self.config.GetString('section.empty') | ||
29 | self.assertEqual(val, None) | ||
30 | |||
31 | def test_GetString_with_true_value(self): | ||
32 | """ | ||
33 | Test config entries with a string value. | ||
34 | |||
35 | [section] | ||
36 | nonempty = true | ||
37 | |||
38 | """ | ||
39 | val = self.config.GetString('section.nonempty') | ||
40 | self.assertEqual(val, 'true') | ||
41 | |||
42 | def test_GetString_from_missing_file(self): | ||
43 | """ | ||
44 | Test missing config file | ||
45 | """ | ||
46 | config_fixture = fixture('not.present.gitconfig') | ||
47 | config = git_config.GitConfig(config_fixture) | ||
48 | val = config.GetString('empty') | ||
49 | self.assertEqual(val, None) | ||
50 | 50 | ||
51 | if __name__ == '__main__': | 51 | if __name__ == '__main__': |
52 | unittest.main() | 52 | unittest.main() |