[tor-commits] [stem/master] Helper function for getting descriptor resource paths

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


commit 02451060cf8d5fcc8834d455e0c12a24b08b876b
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed May 9 09:02:51 2012 -0700

    Helper function for getting descriptor resource paths
    
    Making a common helper function for getting the paths of resources in the
    descriptor data directory rather than making everyone figure out a
    DESCRIPTOR_TEST_DATA constant.
---
 test/integ/descriptor/__init__.py             |   11 +++++++++++
 test/integ/descriptor/extrainfo_descriptor.py |    6 ++----
 test/integ/descriptor/server_descriptor.py    |   16 +++++++---------
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/test/integ/descriptor/__init__.py b/test/integ/descriptor/__init__.py
index ec61ba7..eb8da22 100644
--- a/test/integ/descriptor/__init__.py
+++ b/test/integ/descriptor/__init__.py
@@ -4,3 +4,14 @@ Integration tests for stem.descriptor.* contents.
 
 __all__ = ["reader", "extrainfo_descriptor", "server_descriptor"]
 
+import os
+
+DESCRIPTOR_TEST_DATA = os.path.join(os.path.dirname(__file__), "data")
+
+def get_resource(filename):
+  """
+  Provides the path for a file in our descriptor data directory.
+  """
+  
+  return os.path.join(DESCRIPTOR_TEST_DATA, filename)
+
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index 8b59844..ec94d7c 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -8,9 +8,7 @@ import unittest
 
 import stem.descriptor.extrainfo_descriptor
 import test.runner
-
-my_dir = os.path.dirname(__file__)
-DESCRIPTOR_TEST_DATA = os.path.join(my_dir, "data")
+import test.integ.descriptor
 
 # 'test_cached_descriptor' is a lengthy test and uneffected by testing targets,
 # so including a flag to prevent it from being ran multiple times
@@ -30,7 +28,7 @@ class TestExtraInfoDescriptor(unittest.TestCase):
     Parses and checks our results against an extrainfo descriptor from metrics.
     """
     
-    descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "extrainfo_descriptor")
+    descriptor_path = test.integ.descriptor.get_resource("extrainfo_descriptor")
     
     descriptor_file = open(descriptor_path)
     descriptor_contents = descriptor_file.read()
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index c94c709..b43d1ee 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -10,9 +10,7 @@ import stem.control
 import stem.version
 import stem.descriptor.server_descriptor
 import test.runner
-
-my_dir = os.path.dirname(__file__)
-DESCRIPTOR_TEST_DATA = os.path.join(my_dir, "data")
+import test.integ.descriptor
 
 # 'test_cached_descriptor' is a lengthy test and uneffected by testing targets,
 # so including a flag to prevent it from being ran multiple times
@@ -36,7 +34,7 @@ class TestServerDescriptor(unittest.TestCase):
     Parses and checks our results against a server descriptor from metrics.
     """
     
-    descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "example_descriptor")
+    descriptor_path = test.integ.descriptor.get_resource("example_descriptor")
     
     descriptor_file = open(descriptor_path)
     descriptor_contents = descriptor_file.read()
@@ -107,7 +105,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     Parses a relay server descriptor from 2005.
     """
     
-    descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "old_descriptor")
+    descriptor_path = test.integ.descriptor.get_resource("old_descriptor")
     
     descriptor_file = open(descriptor_path)
     descriptor_contents = descriptor_file.read()
@@ -202,7 +200,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     Parses a descriptor with non-ascii content.
     """
     
-    descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "non-ascii_descriptor")
+    descriptor_path = test.integ.descriptor.get_resource("non-ascii_descriptor")
     
     descriptor_file = open(descriptor_path)
     descriptor_contents = descriptor_file.read()
@@ -243,7 +241,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     returns ('\r' entries).
     """
     
-    descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "cr_in_contact_line")
+    descriptor_path = test.integ.descriptor.get_resource("cr_in_contact_line")
     
     descriptor_file = open(descriptor_path)
     descriptor_contents = descriptor_file.read()
@@ -270,7 +268,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     where we shouldn't be.
     """
     
-    descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "negative_uptime")
+    descriptor_path = test.integ.descriptor.get_resource("negative_uptime")
     
     descriptor_file = open(descriptor_path)
     descriptor_contents = descriptor_file.read()
@@ -293,7 +291,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     Parses a bridge descriptor.
     """
     
-    descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "bridge_descriptor")
+    descriptor_path = test.integ.descriptor.get_resource("bridge_descriptor")
     
     descriptor_file = open(descriptor_path)
     descriptor_contents = descriptor_file.read()





More information about the tor-commits mailing list