* Lele Gaifax [Sun, 16 Jul 2006 11:32:18 +0200]:

> To follow, a couple of things I'd like to be done in a different way:

Ok. :)

> >+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.

Ah, I wasn't aware this was python2.4-specific.

> 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...)

Okay, I've done that. See attached rev. 1198.

                                 * * *

> >+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:]

> 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.

Sure, renamed self.CHANGESETS to self.changesets.

> From where is .CHANGESETS coming down?

Well, this is probably the ugliest part: the user of the MockWorkingDir
has to assign it (see FixedBugs.run_tailor). I'm afraid I couldn't think
of any other way to pass the list of changesets to the class...

I've now made it a property that will yell if an empty MockWorkingDir is
tried to be used. Suggestions about how to implement this more elegantly
welcome.

See attached rev. 1199 for both changes.

                                 * * *

> >+###
> >+
> >+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?

Uhm, fair enough.

> >+                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"

Oops. Fixed both issues. Since it can specify initial contents, I've
renamed new_contents to simply contents; and for update, if no content
is specified, we just open the file in append mode as to update the
modified timestamp.

See attached rev. 1200.

Cheers,

-- 
Adeodato Simó                                     dato at net.com.org.es
Debian Developer                                  adeodato at debian.org
 
                  Listening to: The Rolling Stones - Waiting On A Friend
------------------------------------------------------------
revno: 1198
committer: Adeodato Simó <[EMAIL PROTECTED]>
branch nick: tailor.mock
timestamp: Sun 2006-07-16 21:25:15 +0200
message:
  vcpx/repository/mock.py:
      - don't reuse Changeset and ChangesetEntry for class names, use
        MockChangeset and MockChangesetEntry instead.
  
  vcpx/tests/fixed_bugs.py:
      - adapt to the above change.
  
  (Suggested by Lele)
=== modified file 'vcpx/repository/mock.py'
--- vcpx/repository/mock.py     
+++ vcpx/repository/mock.py     
@@ -18,8 +18,7 @@
 from vcpx.tzinfo import UTC
 from vcpx.repository import Repository
 from vcpx.source import UpdatableSourceWorkingDir
-from vcpx.changes import (Changeset as OldChangeset,
-                          ChangesetEntry as OldChangesetEntry)
+from vcpx.changes import Changeset, ChangesetEntry
 
 ###
 
@@ -55,9 +54,10 @@
 
 ###
 
-class Changeset(OldChangeset):
+class MockChangeset(Changeset):
     def __init__(self, log, entries):
-        super(Changeset, self).__init__(Changeset.Rev.next(), 
Changeset.Date.next(), None, log, entries)
+        super(MockChangeset, self).__init__(MockChangeset.Rev.next(),
+                MockChangeset.Date.next(), None, log, entries)
 
     def Rev():
         initial = 0
@@ -79,9 +79,9 @@
 
 ###
 
-class ChangesetEntry(OldChangesetEntry):
+class MockChangesetEntry(ChangesetEntry):
     def __init__(self, action, name, old_name=None, new_contents=None):
-        super(ChangesetEntry, self).__init__(name)
+        super(MockChangesetEntry, self).__init__(name)
 
         self.isdir        = False
         self.old_name     = old_name

=== modified file 'vcpx/tests/fixed_bugs.py'
--- vcpx/tests/fixed_bugs.py    
+++ vcpx/tests/fixed_bugs.py    
@@ -4,7 +4,8 @@
 
 from vcpx.config import Config
 from vcpx.tailor import Tailorizer
-from vcpx.repository.mock import Changeset, ChangesetEntry as Entry
+from vcpx.repository.mock import MockChangeset as Changeset, \
+                                 MockChangesetEntry as Entry
 
 class FixedBugs(TestCase):
     """Ensure already fixed bugs don't get reintroduced"""

------------------------------------------------------------
revno: 1199
committer: Adeodato Simó <[EMAIL PROTECTED]>
branch nick: tailor.mock
timestamp: Sun 2006-07-16 21:31:56 +0200
message:
  vcpx/repository/mock.py:
      - rename self.CHANGESETS to self.changesets, since it's an instance
        (not class) variable.
      - set self.changesets to [] in __init__, and make it a property that
        raises a TailorBug exception if trying to access it and still empty.
  
  vcpx/tests/fixed_bugs.py:
      - adapt to the above change.
  
  (Suggested by Lele)
=== modified file 'vcpx/repository/mock.py'
--- vcpx/repository/mock.py     
+++ vcpx/repository/mock.py     
@@ -33,9 +33,10 @@
     def __init__(self, *args, **kwargs):
         super(MockWorkingDir, self).__init__(*args, **kwargs)
         self.rev_offset = 0
+        self.changesets = []
 
     def _getUpstreamChangesets(self, sincerev):
-        return self.CHANGESETS[sincerev-self.rev_offset:]
+        return self.changesets[sincerev-self.rev_offset:]
 
     def _applyChangeset(self, changeset):
         for e in changeset.entries:
@@ -45,12 +46,22 @@
 
     def _checkoutUpstreamRevision(self, revision):
         if revision == 'INITIAL':
-            cset = self.CHANGESETS[0]
+            cset = self.changesets[0]
             self.rev_offset = cset.revision - 1
             self._applyChangeset(cset)
             return cset
         else:
             raise "Don't know what to do!"
+
+    def _get_changesets(self):
+        if not self.__changesets:
+            raise "Tailor bug (please report): attempted to use empty 
MockWorkingDir!"
+        return self.__changesets
+
+    def _set_changesets(self, changesets):
+        self.__changesets = changesets
+
+    changesets = property(_get_changesets, _set_changesets)
 
 ###
 

=== modified file 'vcpx/tests/fixed_bugs.py'
--- vcpx/tests/fixed_bugs.py    
+++ vcpx/tests/fixed_bugs.py    
@@ -57,7 +57,7 @@
             test_dir = join(self.test_dir, vcs)
             config   = Config(StringIO(self.CONFIG % vars()), {})
             project  = Tailorizer(test_name, config)
-            project.workingDir().source.CHANGESETS = self.CHANGESETS
+            project.workingDir().source.changesets = self.CHANGESETS
             project()
 
     ###

------------------------------------------------------------
revno: 1200
committer: Adeodato Simó <[EMAIL PROTECTED]>
branch nick: tailor.mock
timestamp: Sun 2006-07-16 21:42:51 +0200
message:
  vcpx/repository/mock.py:
      - MockChangesetEntry: rename new_contents to contents.
      - MockChangesetEntry.apply: write contents for added files as well.
      - MockChangesetEntry.apply: check that contents are non-None before
        writing them on update; if they are, just update the timestamp of
        the file.
  
  vcpx/tests/fixed_bugs.py:
      - adapt to the above s/new_contents/contents/ change.
  
  (Suggested by Lele)
=== modified file 'vcpx/repository/mock.py'
--- vcpx/repository/mock.py     
+++ vcpx/repository/mock.py     
@@ -91,13 +91,13 @@
 ###
 
 class MockChangesetEntry(ChangesetEntry):
-    def __init__(self, action, name, old_name=None, new_contents=None):
+    def __init__(self, action, name, old_name=None, contents=None):
         super(MockChangesetEntry, self).__init__(name)
 
-        self.isdir        = False
-        self.old_name     = old_name
-        self.action_kind  = action
-        self.new_contents = new_contents
+        self.isdir       = False
+        self.contents    = contents
+        self.old_name    = old_name
+        self.action_kind = action
 
         if self.name[-1] == '/':
             self.isdir = True
@@ -113,6 +113,8 @@
                 if not os.path.exists(dirname):
                     os.makedirs(dirname)
                 f = file(name, 'w')
+                if self.contents is not None:
+                    f.write(self.contents)
                 f.close()
         elif self.action_kind == self.DELETED:
             if os.path.exists(name):
@@ -125,8 +127,11 @@
             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)
+            if self.contents is not None:
+                f = file(name, 'w')
+                f.write(self.contents)
+            else: # update timestamp
+                f = file(name, 'w+')
             f.close()
         else:
             raise "Unkown ChangesetEntry.action_kind: %s" % 
(str(self.action_kind),)

=== modified file 'vcpx/tests/fixed_bugs.py'
--- vcpx/tests/fixed_bugs.py    
+++ vcpx/tests/fixed_bugs.py    
@@ -86,7 +86,7 @@
             ]),
             Changeset("Add (cp) a2 and modify a2/b/c",
                 [ Entry(Entry.ADDED, 'a2/b/c'),
-                  Entry(Entry.UPDATED, 'a2/b/c', new_contents='foo')
+                  Entry(Entry.UPDATED, 'a2/b/c', contents='foo')
             ]),
         ]
         self.run_tailor()

_______________________________________________
Tailor mailing list
[email protected]
http://lists.zooko.com/mailman/listinfo/tailor

Reply via email to