Opened 10 years ago
Last modified 10 years ago
#11610 closed enhancement
Move Changeset, Node and Repository classes to model.py — at Version 6
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.1.2 |
Component: | version control | Version: | |
Severity: | normal | Keywords: | |
Cc: | Jun Omae | Branch: | |
Release Notes: |
Git and Mercurial raise a |
||
API Changes: |
|
||
Internal Changes: |
Description
As discussed in #11609, move theChangeset
, Node
and Repository
classes to a new model.py
module in trac/versioncontrol
.
Change History (6)
comment:1 by , 10 years ago
Status: | new → assigned |
---|
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Some additional experimental changes in log:rjollos.git:t11610
The classes in the abc
module were utilized in #11581. There are other classes in the repository which are made abstract by raising NotImplementedError
s in methods, but the ABCMeta
class forces subclasses to adhere to the contract (comment:2:ticket:11581), and more clearly identifies the base classes as abstract.
Some unit tests are currently failing due to:
GitRepository
doesn't implementedget_path_history
(#9775):====================================================================== ERROR: test_node_get_history_with_empty_commit (tracopt.versioncontrol.git.tests.PyGIT.NormalTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/user/Workspace/tracdev/teo-rjollos.git/tracopt/versioncontrol/git/tests/PyGIT.py", line 251, in test_node_get_history_with_empty_commit repos = self.env.get_repository('gitrepos') File "/home/user/Workspace/tracdev/teo-rjollos.git/trac/env.py", line 567, in get_repository return RepositoryManager(self).get_repository(reponame) File "/home/user/Workspace/tracdev/teo-rjollos.git/trac/versioncontrol/api.py", line 575, in get_repository repoinfo.copy()) File "/home/user/Workspace/tracdev/teo-rjollos.git/tracopt/versioncontrol/git/git_fs.py", line 280, in get_repository use_committer_time=self.use_committer_time, TypeError: Can't instantiate abstract class GitRepository with abstract methods get_path_history
- A
Mock
object can't be created directly from a base class withabstractmethods
. It is possible that we need to modifyMock
in order to deal with abstract base classes. I'm not sure yet what is the best approach to take on this.====================================================================== ERROR: test_clean_sync (trac.versioncontrol.tests.cache.CacheTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/user/Workspace/tracdev/teo-rjollos.git/trac/versioncontrol/tests/cache.py", line 158, in test_clean_sync youngest_rev=2) File "/home/user/Workspace/tracdev/teo-rjollos.git/trac/versioncontrol/tests/cache.py", line 54, in get_repos next_rev=(lambda x: int(x) < youngest_rev and x + 1 \ File "/home/user/Workspace/tracdev/teo-rjollos.git/trac/test.py", line 94, in Mock mock = cls(*initargs) TypeError: Can't instantiate abstract class Mock with abstract methods close, get_changes, get_changeset, get_node, get_oldest_rev, get_path_history, get_youngest_rev, next_rev, normalize_path, normalize_rev, previous_rev, rev_older_than
follow-up: 5 comment:4 by , 10 years ago
Changeset
is instantiated directly in CachedRepository. I fixed the failing test by instead instantiating the derived class. The only place I see the object used is: tags/trac-1.0.1/trac/versioncontrol/api.py@:662,674#L657. So now a GitChangeset
, SubversionChangeset
or other derived type is passed to the change listener. Are there any possible negative consequences to this that I'm not seeing?
As for creating Mock
instances of ABCs, it seemed most straightforward to just remove the abstract methods from the class. Like any other methods in a mocked object, an AttributeError
will be raised if methods omitted from the Mock
are utilized in a function under test.
Latest changes added to log:rjollos.git:t11610.
comment:5 by , 10 years ago
Cc: | added |
---|
Changeset
is instantiated directly in CachedRepository. I fixed the failing test by instead instantiating the derived class. The only place I see the object used is: tags/trac-1.0.1/trac/versioncontrol/api.py@:662,674#L657. So now aGitChangeset
,SubversionChangeset
or other derived type is passed to the change listener. Are there any possible negative consequences to this that I'm not seeing?
I think it would be good to create CachedChangeset
instance rather than Changeset
. Also, sync_changeset
method is for only cached repository. Then, GitChangeset
and SubversionChangeset
never be passed to the change listener.
See [058936ed/jomae.git].
As for creating
Mock
instances of ABCs, it seemed most straightforward to just remove the abstract methods from the class. Like any other methods in a mocked object, anAttributeError
will be raised if methods omitted from theMock
are utilized in a function under test.
We could add support for ABCMeta
class as base class of Mock. See [8f55ca19/jomae.git].
comment:6 by , 10 years ago
Those changes look good, thanks. Committed to trunk in [12782:12783].
We'll need to implement get_path_history
in the MercurialPlugin's Repository
subclass. I don't have the necessary permission to push to the branch.
-
tracext/hg/backend.py
# HG changeset patch # User ryan.j.ollos # Date 1400115750 25200 # Branch 1.0 # Node ID 251cde2ad7fdddbfbde7542bccd2a2f4a129b9c9 # Parent 21bb3cc19977ee1f5e546fc21f440ebfd6231404 Implemented abstract method `get_path_history`, which currently displays just a `TracError`. Refs #11610, #9775. diff -r 21bb3cc19977 -r 251cde2ad7fd tracext/hg/backend.py
a b 33 33 from trac.util import arity 34 34 from trac.util.datefmt import FixedOffset, utc 35 35 from trac.util.text import exception_to_unicode, shorten_line, to_unicode 36 from trac.util.translation import domain_functions36 from trac.util.translation import _, domain_functions 37 37 from trac.versioncontrol.api import Changeset, Node, Repository, \ 38 38 IRepositoryConnector, RepositoryManager, \ 39 39 NoSuchChangeset, NoSuchNode … … 747 747 def get_youngest_rev(self): 748 748 return self.changectx().hex() 749 749 750 def get_path_history(self, path, rev=None, limit=None): 751 raise TracError(_("Unsupported \"Show only adds and deletes\"")) 752 750 753 def previous_rev(self, rev, path=''): # FIXME: path ignored for now 751 754 for p in self.changectx(rev).parents(): 752 755 if p:
Looking it at it more closely now, it could be that the reason the classes are in
api.py
rather thanmodel.py
is that they are abstract classes.