[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Fix version parser to ignore git hashes



commit ec9101e44c74ea6e0144c970b0e675dddc3a9aee
Author: Ravi Chandra Padmala <neenaoffline@xxxxxxxxx>
Date:   Fri Mar 23 04:55:48 2012 +0530

    Fix version parser to ignore git hashes
    
    get_system_tor_version strips the git hash
    add test for get_system_tor_version
    remove testcase which doesn't comply with the new version parsing code
---
 stem/version.py      |    2 +-
 test/unit/version.py |   28 +++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/stem/version.py b/stem/version.py
index 74ca8f2..12d12c9 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -57,7 +57,7 @@ def get_system_tor_version(tor_cmd = "tor"):
       
       if last_line.startswith("Tor version ") and last_line.endswith("."):
         try:
-          version_str = last_line[12:-1]
+          version_str = last_line[12:12 + last_line[12:].find(' ')]
           VERSION_CACHE[tor_cmd] = Version(version_str)
         except ValueError, exc:
           raise IOError(exc)
diff --git a/test/unit/version.py b/test/unit/version.py
index 5ba7a62..df9e693 100644
--- a/test/unit/version.py
+++ b/test/unit/version.py
@@ -4,8 +4,31 @@ Unit tests for the stem.version.Version parsing and class.
 
 import unittest
 import stem.version
+import stem.util.system
+
+import test.mocking as mocking
+
+
+TOR_VERSION_OUTPUT = """Mar 22 23:09:37.088 [notice] Tor v0.2.2.35 \
+(git-73ff13ab3cc9570d). This is experimental software. Do not rely on it for \
+strong anonymity. (Running on Linux i686)
+Tor version 0.2.2.35 (git-73ff13ab3cc9570d)."""
 
 class TestVersion(unittest.TestCase):
+  def tearDown(self):
+    mocking.revert_mocking()
+  
+  def test_get_system_tor_version(self):
+    def _mock_call(command):
+      if command == "tor --version":
+        return TOR_VERSION_OUTPUT.splitlines()
+      else:
+        raise ValueError("stem.util.system.call received an unexpected command")
+
+    mocking.mock(stem.util.system.call, _mock_call)
+    version = stem.version.get_system_tor_version()
+    self.assert_versions_match(version, 0, 2, 2, 35, None)
+    
   def test_parsing(self):
     """
     Tests parsing by the Version class constructor.
@@ -13,9 +36,6 @@ class TestVersion(unittest.TestCase):
     
     # valid versions with various number of compontents to the version
     
-    version = stem.version.Version("0.1.2.3-tag (git-7dcd105be34a4f44)")
-    self.assert_versions_match(version, 0, 1, 2, 3, "tag (git-7dcd105be34a4f44)")
-    
     version = stem.version.Version("0.1.2.3-tag")
     self.assert_versions_match(version, 0, 1, 2, 3, "tag")
     
@@ -50,7 +70,6 @@ class TestVersion(unittest.TestCase):
     
     # check for basic incrementing in each portion
     self.assert_version_is_greater("1.1.2.3-tag", "0.1.2.3-tag")
-    self.assert_version_is_greater("1.1.2.3-tag (git-7dcd105be34a4f44)", "0.1.2.3-tag (git-7dcd105be34a4f44)")
     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")
@@ -87,7 +106,6 @@ class TestVersion(unittest.TestCase):
     """
     
     # checks conversion with various numbers of arguments
-    self.assert_string_matches("0.1.2.3-tag (git-7dcd105be34a4f44)")
     self.assert_string_matches("0.1.2.3-tag")
     self.assert_string_matches("0.1.2.3")
     self.assert_string_matches("0.1.2")



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits