[tor-commits] [stem/master] Removing tag from version comparisons

atagar at torproject.org atagar at torproject.org
Fri Dec 9 18:03:00 UTC 2011


commit 98ad681bc05d91b596ceebb8f46e04f1f8598b84
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Dec 9 10:01:27 2011 -0800

    Removing tag from version comparisons
    
    As Sebastian pointed out, the version-spec says "The status tag is purely
    informational". Removing it from comparison operations so versions like
    "1.2.3.4-foo" and "1.2.3.4-bar" will evaluate to being equal.
---
 run_tests.py         |    2 +-
 stem/version.py      |    6 ++++--
 test/unit/version.py |    6 +++---
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index eee52ff..206de76 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -35,7 +35,7 @@ DIVIDER = "=" * 70
 # (name, class) tuples for all of our unit and integration tests
 UNIT_TESTS = (("stem.socket.ControlMessage", test.unit.socket.control_message.TestControlMessage),
               ("stem.socket.ControlLine", test.unit.socket.control_line.TestControlLine),
-              ("stem.types.Version", test.unit.version.TestVerion),
+              ("stem.types.Version", test.unit.version.TestVersion),
               ("stem.connection.ProtocolInfoResponse", test.unit.connection.protocolinfo.TestProtocolInfoResponse),
               ("stem.util.enum", test.unit.util.enum.TestEnum),
               ("stem.util.system", test.unit.util.system.TestSystem),
diff --git a/stem/version.py b/stem/version.py
index d417934..214e06a 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -131,7 +131,7 @@ class Version:
   def __cmp__(self, other):
     """
     Simple comparison of versions. An undefined patch level is treated as zero
-    and status tags are compared lexically (as per the version spec).
+    and status tags are not included in comparisions (as per the version spec).
     """
     
     if not isinstance(other, Version):
@@ -147,7 +147,9 @@ class Version:
     my_status = self.status if self.status else ""
     other_status = other.status if other.status else ""
     
-    return cmp(my_status, other_status)
+    # not including tags in comparisons because the spec declares them to be
+    # 'purely informational'
+    return 0
 
 Requirement = stem.util.enum.Enum(
   ("GETINFO_CONFIG_TEXT", Version("0.2.2.7-alpha")),
diff --git a/test/unit/version.py b/test/unit/version.py
index 2845ad3..7cff127 100644
--- a/test/unit/version.py
+++ b/test/unit/version.py
@@ -5,7 +5,7 @@ Unit tests for the stem.version.Version parsing and class.
 import unittest
 import stem.version
 
-class TestVerion(unittest.TestCase):
+class TestVersion(unittest.TestCase):
   """
   Tests methods and functions related to 'stem.version.Version'.
   """
@@ -53,7 +53,7 @@ class TestVerion(unittest.TestCase):
     self.assert_version_is_greater("0.2.2.3-tag", "0.1.2.3-tag")
     self.assert_version_is_greater("0.1.3.3-tag", "0.1.2.3-tag")
     self.assert_version_is_greater("0.1.2.4-tag", "0.1.2.3-tag")
-    self.assert_version_is_greater("0.1.2.3-ugg", "0.1.2.3-tag")
+    self.assert_version_is_equal("0.1.2.3-ugg", "0.1.2.3-tag")
     self.assert_version_is_equal("0.1.2.3-tag", "0.1.2.3-tag")
     
     # checks that a missing patch level equals zero
@@ -61,7 +61,7 @@ class TestVerion(unittest.TestCase):
     self.assert_version_is_equal("0.1.2-tag", "0.1.2.0-tag")
     
     # checks for missing patch or status
-    self.assert_version_is_greater("0.1.2.3-tag", "0.1.2.3")
+    self.assert_version_is_equal("0.1.2.3-tag", "0.1.2.3")
     self.assert_version_is_greater("0.1.2.3-tag", "0.1.2-tag")
     self.assert_version_is_greater("0.1.2.3-tag", "0.1.2")
     



More information about the tor-commits mailing list