[tor-commits] [stem/master] Sorting tor versions lexically

atagar at torproject.org atagar at torproject.org
Sun Jul 22 05:48:17 UTC 2012


commit 43db1dea2487ed7517c8be3f44a315fdeac731a8
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jul 21 19:55:51 2012 -0700

    Sorting tor versions lexically
    
    According to the version spec we should "compare them lexically as ASCII byte
    strings". This seems a little weird since it means a reverse alphabetical order
    (ie 'Z' comes before 'A') but oh well.
---
 stem/version.py      |   14 +++++++++++---
 test/unit/version.py |    4 ++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/stem/version.py b/stem/version.py
index bc377af..087efa9 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -159,9 +159,17 @@ class Version(object):
       if my_version > other_version: return 1
       elif my_version < other_version: return -1
     
-    # not including tags in comparisons because the spec declares them to be
-    # 'purely informational'
-    return 0
+    # According to the version spec...
+    #
+    #   If we *do* encounter two versions that differ only by status tag, we
+    #   compare them lexically as ASCII byte strings.
+    
+    my_status = self.status if self.status else ""
+    other_status = other.status if other.status else ""
+    
+    if my_status > other_status: return 1
+    elif my_status < other_status: return -1
+    else: return 0
 
 class VersionRequirements(object):
   """
diff --git a/test/unit/version.py b/test/unit/version.py
index 618b483..cfda02c 100644
--- a/test/unit/version.py
+++ b/test/unit/version.py
@@ -82,7 +82,7 @@ class TestVersion(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_equal("0.1.2.3-ugg", "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-tag", "0.1.2.3-tag")
     
     # checks that a missing patch level equals zero
@@ -90,7 +90,7 @@ class TestVersion(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_equal("0.1.2.3-tag", "0.1.2.3")
+    self.assert_version_is_greater("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