Adeodato Simó wrote:
Today I finally found some time and energy to spend on this, and I'd
like to hear comments about this approach. Basically, it breaks down to:
- it is oriented to test target backends acting on certain source repo
- such source repos are specified as a series of Changesets, with a
couple wrappers to make their creation more straightforward
- a mock source backend is introduced, that instead of being driven by
an underlying VCS, it's driven by that series of Changesets, propagating
the proper actions to the filesystem
Hi,
You know, I really like the idea!-) Thanks a lot!!
To follow, a couple of things I'd like to be done in a different way:
+from vcpx.changes import (Changeset as OldChangeset,
+ ChangesetEntry as OldChangesetEntry)
We should avoid using Python 2.4 idioms when possible, to let the tests
run under 2.3 as well. Also, in the sake of clarity, I'd call the
"parent" classes somewhat different from "OldXXX", maybe even keeping
the original name and calling the derivatives as "MockXXX", consistent
with the other classes (MockRepository, MockWD...)
+class MockWorkingDir(UpdatableSourceWorkingDir):
+ def __init__(self, *args, **kwargs):
+ super(MockWorkingDir, self).__init__(*args, **kwargs)
+ self.rev_offset = 0
+
+ def _getUpstreamChangesets(self, sincerev):
+ return self.CHANGESETS[sincerev-self.rev_offset:]
From where is .CHANGESETS coming down? Also, I don't like the confusion
introduced by me in a few places and reinforced by Yann in his work on
the git backend on attributes naming convention:
* upper case attributes was intended to indicate a class variable, but
ordinary instance attributes should be all lower case, maybe with
underscores to separate single words (I plan to go thru the code and
rename such occurrence, as I already anticipated to Yann)
* method names should be came case, and start with an underscore to
denote an internal method (not to be called by external classes) or
with a lower case letter.
+class Changeset(OldChangeset):
+ def __init__(self, log, entries):
+ super(Changeset, self).__init__(Changeset.Rev.next(),
Changeset.Date.next(), None, log, entries)
+
+ def Rev():
+ initial = 0
+
+ while True:
+ initial += 1
+ yield initial
+
+ def Date():
+ initial = datetime.now(UTC)
+ step = timedelta(seconds=1)
+
+ while True:
+ initial += step
+ yield initial
+
+ Rev = Rev()
+ Date = Date()
+
+###
+
+class ChangesetEntry(OldChangesetEntry):
+ def __init__(self, action, name, old_name=None, new_contents=None):
+ super(ChangesetEntry, self).__init__(name)
+
+ self.isdir = False
+ self.old_name = old_name
+ self.action_kind = action
+ self.new_contents = new_contents
+
+ if self.name[-1] == '/':
+ self.isdir = True
+ self.name = self.name[:-1]
+
+ def apply(self, where):
+ name = os.path.join(where, self.name)
+ if self.action_kind == self.ADDED:
+ if self.isdir:
+ os.makedirs(name)
+ else:
+ dirname = os.path.dirname(name)
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+ f = file(name, 'w')
Shouldn't be the new file containint `new_contents` here?
+ f.close()
+ elif self.action_kind == self.DELETED:
+ if os.path.exists(name):
+ if self.isdir:
+ rmtree(name)
+ else:
+ os.unlink(name)
+ elif self.action_kind == self.RENAMED:
+ old_name = os.path.join(where, self.old_name)
+ if os.path.exists(oldname):
+ os.rename(old_name, name)
+ elif self.action_kind == self.UPDATED:
+ f = file(name, 'w')
+ f.write(self.new_contents)
This should test against "self.new_contents is not None"
+ f.close()
+ else:
+ raise "Unkown ChangesetEntry.action_kind: %s" %
(str(self.action_kind),)
+
Ok, that's it for now, as I have to leave. I'll do another round on
review this afternoon,
thanks a lot again,
ciao, lele.
_______________________________________________
Tailor mailing list
[email protected]
http://lists.zooko.com/mailman/listinfo/tailor