[tor-commits] [stem/master] Letting runner's get_test_dir() provide resources

atagar at torproject.org atagar at torproject.org
Mon May 14 00:14:27 UTC 2012


commit 46fb6b272e45ab8c569e1439a53a985c5a8d827d
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed May 9 08:54:26 2012 -0700

    Letting runner's get_test_dir() provide resources
    
    The most common use of the integ runner's get_test_dir() method is to get a
    path for resources in that directory. Providing an optional argument to get
    that path rather than making the caller use os.join().
---
 test/integ/connection/authentication.py       |    2 +-
 test/integ/descriptor/extrainfo_descriptor.py |    5 ++---
 test/integ/descriptor/reader.py               |    6 +++---
 test/integ/descriptor/server_descriptor.py    |    5 ++---
 test/integ/util/conf.py                       |    2 +-
 test/runner.py                                |   14 ++++++++++----
 6 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py
index c209d2b..9d912b3 100644
--- a/test/integ/connection/authentication.py
+++ b/test/integ/connection/authentication.py
@@ -236,7 +236,7 @@ class TestAuthenticate(unittest.TestCase):
     """
     
     auth_type = stem.connection.AuthMethod.COOKIE
-    auth_value = os.path.join(test.runner.get_runner().get_test_dir(), "fake_cookie")
+    auth_value = test.runner.get_runner().get_test_dir("fake_cookie")
     
     # we need to create a 32 byte cookie file to load from
     fake_cookie = open(auth_value, "w")
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index 74ac7fb..8b59844 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -22,8 +22,7 @@ class TestExtraInfoDescriptor(unittest.TestCase):
   
   def setUp(self):
     if self.is_cached_descriptors_available is None:
-      test_dir = test.runner.get_runner().get_test_dir()
-      descriptor_path = os.path.join(test_dir, "cached-extrainfo")
+      descriptor_path = test.runner.get_runner().get_test_dir("cached-extrainfo")
       self.is_cached_descriptors_available = os.path.exists(descriptor_path)
   
   def test_metrics_descriptor(self):
@@ -78,7 +77,7 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
     additions.
     """
     
-    descriptor_path = os.path.join(test.runner.get_runner().get_test_dir(), "cached-extrainfo")
+    descriptor_path = test.runner.get_runner().get_test_dir("cached-extrainfo")
     
     if not self.is_cached_descriptors_available:
       self.skipTest("(no cached descriptors)")
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 0d4a638..81635e0 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -24,7 +24,7 @@ DESCRIPTOR_TEST_DATA = os.path.join(my_dir, "data")
 TAR_DESCRIPTORS = None
 
 def _get_processed_files_path():
-  return os.path.join(test.runner.get_runner().get_test_dir(), "descriptor_processed_files")
+  return test.runner.get_runner().get_test_dir("descriptor_processed_files")
 
 def _make_processed_files_listing(contents):
   """
@@ -372,7 +372,7 @@ class TestDescriptorReader(unittest.TestCase):
     # types are solely based on file extensions so making something that looks
     # like an png image
     
-    test_path = os.path.join(test.runner.get_runner().get_test_dir(), "test.png")
+    test_path = test.runner.get_runner().get_test_dir("test.png")
     
     try:
       test_file = open(test_path, "w")
@@ -399,7 +399,7 @@ class TestDescriptorReader(unittest.TestCase):
     Listens for a file that's skipped because we lack read permissions.
     """
     
-    test_path = os.path.join(test.runner.get_runner().get_test_dir(), "secret_file")
+    test_path = test.runner.get_runner().get_test_dir("secret_file")
     
     try:
       test_file = open(test_path, "w")
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index a74e4eb..c94c709 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -28,8 +28,7 @@ class TestServerDescriptor(unittest.TestCase):
     # Noting if they exist or not since some tests need them.
     
     if self.is_cached_descriptors_available is None:
-      test_dir = test.runner.get_runner().get_test_dir()
-      descriptor_path = os.path.join(test_dir, "cached-descriptors")
+      descriptor_path = test.runner.get_runner().get_test_dir("cached-descriptors")
       self.is_cached_descriptors_available = os.path.exists(descriptor_path)
   
   def test_metrics_descriptor(self):
@@ -166,7 +165,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     additions.
     """
     
-    descriptor_path = os.path.join(test.runner.get_runner().get_test_dir(), "cached-descriptors")
+    descriptor_path = test.runner.get_runner().get_test_dir("cached-descriptors")
     
     if not self.is_cached_descriptors_available:
       self.skipTest("(no cached descriptors)")
diff --git a/test/integ/util/conf.py b/test/integ/util/conf.py
index 13d0579..a429f2a 100644
--- a/test/integ/util/conf.py
+++ b/test/integ/util/conf.py
@@ -46,7 +46,7 @@ Why are those arrows",
 coming my way?!?"""
 
 def _get_test_config_path():
-  return os.path.join(test.runner.get_runner().get_test_dir(), "integ_test_cfg")
+  return test.runner.get_runner().get_test_dir("integ_test_cfg")
 
 def _make_config(contents):
   """
diff --git a/test/runner.py b/test/runner.py
index 034f1e5..5ee9098 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -346,18 +346,24 @@ class Runner:
     
     return self._custom_opts
   
-  def get_test_dir(self):
+  def get_test_dir(self, resource = None):
     """
-    Provides the absolute path for our testing directory.
+    Provides the absolute path for our testing directory or a file within it.
+    
+    Arguments:
+      resource (str) - file within our test directory to provide the path for
     
     Returns:
-      str with our test direcectory path
+      str with our test direcectory's absolute path or that of a file within it
     
     Raises:
       RunnerStopped if we aren't running
     """
     
-    return self._get("_test_dir")
+    if resource:
+      return os.path.join(self._get("_test_dir"), resource)
+    else:
+      return self._get("_test_dir")
   
   def get_torrc_path(self):
     """





More information about the tor-commits mailing list