comparison hg_delta_editor.py @ 146:4da9f20aef01

Add some more coverage directives.
author Augie Fackler <durin42@gmail.com>
date Mon, 15 Dec 2008 22:48:04 -0600
parents b37c401b7f92
children 22162380c4b9
comparison
equal deleted inserted replaced
145:b37c401b7f92 146:4da9f20aef01
25 try: 25 try:
26 f, path = tempfile.mkstemp(prefix='pickling', dir=dir) 26 f, path = tempfile.mkstemp(prefix='pickling', dir=dir)
27 f = os.fdopen(f, 'w') 27 f = os.fdopen(f, 'w')
28 pickle.dump(data, f) 28 pickle.dump(data, f)
29 f.close() 29 f.close()
30 except: 30 except: #pragma: no cover
31 raise 31 raise
32 else: 32 else:
33 util.rename(path, file_path) 33 util.rename(path, file_path)
34 34
35 def stash_exception_on_self(fn): 35 def stash_exception_on_self(fn):
41 got an exception in the replay process. 41 got an exception in the replay process.
42 """ 42 """
43 def fun(self, *args, **kwargs): 43 def fun(self, *args, **kwargs):
44 try: 44 try:
45 return fn(self, *args, **kwargs) 45 return fn(self, *args, **kwargs)
46 except: 46 except: #pragma: no cover
47 if not hasattr(self, '_exception_info'): 47 if not hasattr(self, '_exception_info'):
48 self._exception_info = sys.exc_info() 48 self._exception_info = sys.exc_info()
49 raise 49 raise
50 return fun 50 return fun
51 51
73 self.repo = repo 73 self.repo = repo
74 self.path = os.path.normpath(os.path.join(self.repo.path, '..')) 74 self.path = os.path.normpath(os.path.join(self.repo.path, '..'))
75 elif path: 75 elif path:
76 self.path = path 76 self.path = path
77 self.__setup_repo(path) 77 self.__setup_repo(path)
78 else: 78 else: #pragma: no cover
79 raise TypeError("Expected either path or repo argument") 79 raise TypeError("Expected either path or repo argument")
80 80
81 self.subdir = subdir 81 self.subdir = subdir
82 if self.subdir and self.subdir[0] == '/': 82 if self.subdir and self.subdir[0] == '/':
83 self.subdir = self.subdir[1:] 83 self.subdir = self.subdir[1:]
337 self.tags.update(added_tags) 337 self.tags.update(added_tags)
338 self.branches.update(added_branches) 338 self.branches.update(added_branches)
339 self._save_metadata() 339 self._save_metadata()
340 340
341 def commit_current_delta(self): 341 def commit_current_delta(self):
342 if hasattr(self, '_exception_info'): 342 if hasattr(self, '_exception_info'): #pragma: no cover
343 traceback.print_exception(*self._exception_info) 343 traceback.print_exception(*self._exception_info)
344 raise ReplayException() 344 raise ReplayException()
345 if self.missing_plaintexts: 345 if self.missing_plaintexts:
346 raise MissingPlainTextError() 346 raise MissingPlainTextError()
347 files_to_commit = self.current_files.keys() 347 files_to_commit = self.current_files.keys()
439 continue 439 continue
440 parent_ctx = self.repo.changectx(ha) 440 parent_ctx = self.repo.changectx(ha)
441 def del_all_files(*args): 441 def del_all_files(*args):
442 raise IOError 442 raise IOError
443 # True here meant nuke all files, shouldn't happen with branch closing 443 # True here meant nuke all files, shouldn't happen with branch closing
444 if self.commit_branches_empty[branch]: 444 if self.commit_branches_empty[branch]: #pragma: no cover
445 assert False, 'Got asked to commit non-closed branch as empty with no files. Please report this issue.' 445 assert False, 'Got asked to commit non-closed branch as empty with no files. Please report this issue.'
446 extra = {} 446 extra = {}
447 if branch: 447 if branch:
448 extra['branch'] = branch 448 extra['branch'] = branch
449 current_ctx = context.memctx(self.repo, 449 current_ctx = context.memctx(self.repo,
697 source = cStringIO.StringIO(base) 697 source = cStringIO.StringIO(base)
698 target = cStringIO.StringIO() 698 target = cStringIO.StringIO()
699 self.stream = target 699 self.stream = target
700 700
701 handler, baton = delta.svn_txdelta_apply(source, target, None) 701 handler, baton = delta.svn_txdelta_apply(source, target, None)
702 if not callable(handler): 702 if not callable(handler): #pragma: no cover
703 # TODO(augie) Raise a real exception, don't just fail an assertion. 703 # TODO(augie) Raise a real exception, don't just fail an assertion.
704 assert False, 'handler not callable, bindings are broken' 704 assert False, 'handler not callable, bindings are broken'
705 def txdelt_window(window): 705 def txdelt_window(window):
706 try: 706 try:
707 if not self._is_path_valid(self.current_file): 707 if not self._is_path_valid(self.current_file):
708 return 708 return
709 handler(window, baton) 709 handler(window, baton)
710 # window being None means commit this file 710 # window being None means commit this file
711 if not window: 711 if not window:
712 self.current_files[self.current_file] = target.getvalue() 712 self.current_files[self.current_file] = target.getvalue()
713 except core.SubversionException, e: 713 except core.SubversionException, e: #pragma: no cover
714 if e.message == 'Delta source ended unexpectedly': 714 if e.message == 'Delta source ended unexpectedly':
715 self.missing_plaintexts.add(self.current_file) 715 self.missing_plaintexts.add(self.current_file)
716 else: 716 else: #pragma: no cover
717 self._exception_info = sys.exc_info() 717 self._exception_info = sys.exc_info()
718 raise 718 raise
719 except: 719 except: #pragma: no cover
720 print len(base), self.current_file 720 print len(base), self.current_file
721 self._exception_info = sys.exc_info() 721 self._exception_info = sys.exc_info()
722 raise 722 raise
723 return txdelt_window 723 return txdelt_window
724 724