[tor-commits] [stem/master] Fixed test_expand_path_unix, and added test_expand_path_windows

atagar at torproject.org atagar at torproject.org
Sun Jul 1 02:49:59 UTC 2012


commit c001394928e01eb9807c747fed0283c7748578f9
Author: Beck <csybeck at gmail.com>
Date:   Tue Jun 26 23:58:32 2012 +0800

    Fixed test_expand_path_unix, and added test_expand_path_windows
    
    test_expand_path_unix was changing os.path.sep in order to change the
    path seperator used by os.path.join. However, this did not work. The
    path seperator was hardcoded in os.path.join, which is posixpath.join
    on *unix systems and ntpath.join on windows. We now mock os.path.join
    to use posixpath.join or ntpath.join in different test cases.
---
 test/unit/util/system.py |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index 397ba7d..2fee30d 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -9,6 +9,8 @@ import os
 import platform
 import functools
 import unittest
+import ntpath
+import posixpath
 import stem.util.proc
 import stem.util.system as system
 import test.mocking as mocking
@@ -292,8 +294,7 @@ class TestSystem(unittest.TestCase):
     """
     
     mocking.mock(platform.system, mocking.return_value("Linux"))
-    original_path_sep = os.path.sep
-    os.path.sep = "/"
+    mocking.mock(os.path.join, posixpath.join, os.path)
     
     self.assertEquals("", system.expand_path(""))
     self.assertEquals("/tmp", system.expand_path("/tmp"))
@@ -303,5 +304,21 @@ class TestSystem(unittest.TestCase):
     self.assertEquals("/tmp/foo", system.expand_path("foo", "/tmp"))
     self.assertEquals("/tmp/foo", system.expand_path("./foo", "/tmp"))
     
-    os.path.sep = original_path_sep
-
+  def test_expand_path_windows(self):
+    """
+    Tests the expand_path function on windows. This does not exercise
+    home directory expansions since that deals with our environment
+    (that's left to integ tests).
+    """
+    
+    mocking.mock(platform.system, mocking.return_value("Windows"))
+    mocking.mock(os.path.join, ntpath.join, os.path)
+    
+    self.assertEquals("", system.expand_path(""))
+    self.assertEquals("C:\\tmp", system.expand_path("C:\\tmp"))
+    self.assertEquals("C:\\tmp", system.expand_path("C:\\tmp\\"))
+    self.assertEquals("C:\\tmp", system.expand_path(".", "C:\\tmp"))
+    self.assertEquals("C:\\tmp", system.expand_path(".\\", "C:\\tmp"))
+    self.assertEquals("C:\\tmp\\foo", system.expand_path("foo", "C:\\tmp"))
+    self.assertEquals("C:\\tmp\\foo", system.expand_path(".\\foo", "C:\\tmp"))
+    
\ No newline at end of file





More information about the tor-commits mailing list