[Treepkg-commits] r208 - in trunk: test treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 4 12:09:15 CEST 2009


Author: bh
Date: 2009-08-04 12:09:12 +0200 (Tue, 04 Aug 2009)
New Revision: 208

Added:
   trunk/test/test_subversion.py
Modified:
   trunk/treepkg/subversion.py
Log:
Add functions to get SVN logs and extract tag revisions from it.  Add
some tests for the log parsing.


Added: trunk/test/test_subversion.py
===================================================================
--- trunk/test/test_subversion.py	2009-08-04 10:01:56 UTC (rev 207)
+++ trunk/test/test_subversion.py	2009-08-04 10:09:12 UTC (rev 208)
@@ -0,0 +1,199 @@
+# Copyright (C) 2008, 2009 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Tests for the treepkg.subversion module"""
+
+
+import unittest
+
+from treepkg.subversion import extract_tag_revisions
+
+
+class TestTagDetector(unittest.TestCase):
+
+    def test_tag_changes_count_one_copy_command(self):
+        xml = """\
+<?xml version="1.0"?>
+<log>
+<logentry
+   revision="1001832">
+<author>tmcguire</author>
+<date>2009-07-24T11:01:19.722901Z</date>
+<paths>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/kontact/src/main.cpp</path>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/kmail/kmversion.h</path>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/korganizer/version.h</path>
+</paths>
+<msg>SVN_SILENT Update version numbers for today's release.</msg>
+</logentry>
+<logentry
+   revision="1001837">
+<author>tmcguire</author>
+<date>2009-07-24T11:02:47.403605Z</date>
+<paths>
+<path
+   copyfrom-path="/branches/kdepim/enterprise/kdepim"
+   copyfrom-rev="1001836"
+   action="A">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim</path>
+</paths>
+<msg>SVN_SILENT Tag kdepim.</msg>
+</logentry>
+<logentry
+   revision="1004164">
+<author>winterz</author>
+<date>2009-07-29T13:23:42.262028Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/scheduler.cpp</path>
+</paths>
+<msg>merge SVN commit 1004159 by winterz:
+
+Allow an attendee to decline an new invitation without getting the error
+message that the event couldn't be found in their calendar.
+kolab/issue3780
+
+</msg>
+</logentry>
+<logentry
+   revision="1004558">
+<author>winterz</author>
+<date>2009-07-30T13:34:18.385413Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/kmail/newfolderdialog.cpp</path>
+</paths>
+<msg>merge SVN commit 1004535 by tmcguire:
+
+Fix silly crash when creating a folder.
+
+kolab/issue3777
+</msg>
+</logentry>
+<logentry
+   revision="1004604">
+<author>winterz</author>
+<date>2009-07-30T15:25:19.331744Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/incidenceformatter.cpp</path>
+</paths>
+<msg>merge SVN commit 1004601 by winterz:
+
+possible fix for kolab/issue3724 and kolab/issue3780, whereby multiple
+persons having write access to a folder can confuse things for other
+users accessing that folder.
+
+</msg>
+</logentry>
+</log>
+"""
+        #
+
+        self.assertEquals(extract_tag_revisions(xml),
+                          ["1001837", "1004164", "1004558", "1004604"])
+
+
+    def test_tag_changes_count_two_copy_commands(self):
+        xml = """\
+<?xml version="1.0"?>
+<log>
+<logentry
+   revision="901832">
+<author>tmcguire</author>
+<date>2009-07-24T11:01:19.722901Z</date>
+<paths>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/kontact/src/main.cpp</path>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/kmail/kmversion.h</path>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/korganizer/version.h</path>
+</paths>
+<msg>SVN_SILENT Update version numbers for today's release.</msg>
+</logentry>
+<logentry
+   revision="901837">
+<author>tmcguire</author>
+<date>2009-07-24T11:02:47.403605Z</date>
+<paths>
+<path
+   copyfrom-path="/branches/kdepim/enterprise/kdepim"
+   copyfrom-rev="1001836"
+   action="A">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim</path>
+</paths>
+<msg>SVN_SILENT Tag kdepim.</msg>
+</logentry>
+<logentry
+   revision="1004164">
+<author>winterz</author>
+<date>2009-07-29T13:23:42.262028Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/scheduler.cpp</path>
+</paths>
+<msg>merge SVN commit 1004159 by winterz:
+
+Allow an attendee to decline an new invitation without getting the error
+message that the event couldn't be found in their calendar.
+kolab/issue3780
+
+</msg>
+</logentry>
+<logentry
+   revision="1004558">
+<author>winterz</author>
+<date>2009-07-30T13:34:18.385413Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/kmail/newfolderdialog.cpp</path>
+</paths>
+<msg>merge SVN commit 1004535 by tmcguire:
+
+Fix silly crash when creating a folder.
+
+kolab/issue3777
+</msg>
+</logentry>
+<logentry
+   revision="1004604">
+<author>winterz</author>
+<date>2009-07-30T15:25:19.331744Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/incidenceformatter.cpp</path>
+</paths>
+<msg>merge SVN commit 1004601 by winterz:
+
+possible fix for kolab/issue3724 and kolab/issue3780, whereby multiple
+persons having write access to a folder can confuse things for other
+users accessing that folder.
+
+</msg>
+</logentry>
+<logentry
+   revision="1005000">
+<author>somebody</author>
+<date>2009-07-24T12:02:47.403605Z</date>
+<paths>
+<path
+   copyfrom-path="/branches/kdepim/enterprise/kdepim"
+   copyfrom-rev="1001836"
+   action="A">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim</path>
+</paths>
+<msg>ficticious commit that looks like the earlier copy that created the tag.
+</msg>
+</logentry>
+</log>
+"""
+        #
+
+        self.assertEquals(extract_tag_revisions(xml),
+                          ["901837", "1004164", "1004558", "1004604",
+                           "1005000"])


Property changes on: trunk/test/test_subversion.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: trunk/treepkg/subversion.py
===================================================================
--- trunk/treepkg/subversion.py	2009-08-04 10:01:56 UTC (rev 207)
+++ trunk/treepkg/subversion.py	2009-08-04 10:09:12 UTC (rev 208)
@@ -10,7 +10,10 @@
 import os
 import shutil
 import re
+import StringIO
 
+from lxml import etree
+
 import run
 from cmdexpand import cmdexpand
 from util import extract_value_for_key
@@ -70,7 +73,30 @@
                               % svn_working_copy)
     return int(str_rev)
 
+def log_xml(url, base_revision):
+    """Return the log in XML of the repository at url from base_revision to HEAD
+    """
+    args = ["--revision", str(base_revision) + ":HEAD",
+            "--verbose",
+            "--xml"]
+    return run.capture_output(cmdexpand("svn log @args $url", **locals()))
 
+
+def extract_tag_revisions(xml_log):
+    """Extracts the revisions which changed an SVN tag since its creation
+    This includes the revision which created the tag and all subsequent
+    changes.  The xml_log parameter should contain the xml-Version of
+    the SVN log of the tag that includes at least the revision that
+    created the tag and all the newer revisions.
+    """
+    tree = etree.parse(StringIO.StringIO(xml_log))
+    tag_revisions = tree.xpath("logentry/@revision"
+                               "[.>=../../logentry/@revision"
+                               "[../paths/path[@copyfrom-path]]]")
+    return tag_revisions
+
+
+
 class SvnRepository(object):
 
     """Describes a subversion repository"""



More information about the Treepkg-commits mailing list