commit 9ff618eebed92e5646090ce3faa802763a5f7720 Author: Damian Johnson atagar@torproject.org Date: Wed Jan 30 09:10:18 2013 -0800
Skipping newline translation for descriptor integ tests
Using a custom open() call for python 3's integ tests to prevent newline translation (and the resulting test failures). --- test/integ/descriptor/__init__.py | 23 ++++++++++++++++- test/integ/descriptor/extrainfo_descriptor.py | 12 +++------ test/integ/descriptor/networkstatus.py | 34 +++++++++++-------------- test/integ/descriptor/server_descriptor.py | 33 +++++++----------------- 4 files changed, 51 insertions(+), 51 deletions(-)
diff --git a/test/integ/descriptor/__init__.py b/test/integ/descriptor/__init__.py index d3d3063..31421f1 100644 --- a/test/integ/descriptor/__init__.py +++ b/test/integ/descriptor/__init__.py @@ -2,10 +2,18 @@ Integration tests for stem.descriptor.* contents. """
-__all__ = ["reader", "extrainfo_descriptor", "server_descriptor"] +__all__ = [ + "reader", + "extrainfo_descriptor", + "server_descriptor", + "get_resource", + "open_desc", +]
import os
+import stem.prereq + DESCRIPTOR_TEST_DATA = os.path.join(os.path.dirname(__file__), "data")
@@ -15,3 +23,16 @@ def get_resource(filename): """
return os.path.join(DESCRIPTOR_TEST_DATA, filename) + + +def open_desc(filename, absolute = False): + """ + Provides the file for a given descriptor in our data directory. + """ + + path = filename if absolute else get_resource(filename) + + if stem.prereq.is_python_3(): + return open(path, newline = '') + else: + return open(path) diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py index 5fc9b5a..0bcc23f 100644 --- a/test/integ/descriptor/extrainfo_descriptor.py +++ b/test/integ/descriptor/extrainfo_descriptor.py @@ -9,10 +9,10 @@ import os import unittest
import stem.descriptor.extrainfo_descriptor -import test.integ.descriptor import test.runner
from stem.descriptor.extrainfo_descriptor import DirResponse +from test.integ.descriptor import open_desc
class TestExtraInfoDescriptor(unittest.TestCase): @@ -21,9 +21,7 @@ class TestExtraInfoDescriptor(unittest.TestCase): Parses and checks our results against an extrainfo descriptor from metrics. """
- descriptor_path = test.integ.descriptor.get_resource("extrainfo_relay_descriptor") - - descriptor_file = open(descriptor_path) + descriptor_file = open_desc("extrainfo_relay_descriptor") descriptor_file.readline() # strip header descriptor_contents = descriptor_file.read() descriptor_file.close() @@ -72,9 +70,7 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw metrics. """
- descriptor_path = test.integ.descriptor.get_resource("extrainfo_bridge_descriptor") - - descriptor_file = open(descriptor_path) + descriptor_file = open_desc("extrainfo_bridge_descriptor") descriptor_file.readline() # strip header descriptor_contents = descriptor_file.read() descriptor_file.close() @@ -150,7 +146,7 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw test.runner.skip(self, "(no cached descriptors)") return
- with open(descriptor_path) as descriptor_file: + with open_desc(descriptor_path, absolute = True) as descriptor_file: for desc in stem.descriptor.extrainfo_descriptor._parse_file(descriptor_file): unrecognized_lines = desc.get_unrecognized_lines()
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py index 035289d..19c3d8f 100644 --- a/test/integ/descriptor/networkstatus.py +++ b/test/integ/descriptor/networkstatus.py @@ -13,7 +13,9 @@ import stem import stem.descriptor import stem.descriptor.networkstatus import stem.version -import test.integ.descriptor +import test.runner + +from test.integ.descriptor import get_resource, open_desc
class TestNetworkStatus(unittest.TestCase): @@ -40,7 +42,7 @@ class TestNetworkStatus(unittest.TestCase): return
count = 0 - with open(consensus_path) as descriptor_file: + with open_desc(consensus_path, absolute = True) as descriptor_file: document_type = stem.descriptor.networkstatus.NetworkStatusDocumentV3
for router in stem.descriptor.networkstatus._parse_file(descriptor_file, document_type): @@ -87,7 +89,7 @@ class TestNetworkStatus(unittest.TestCase): return
count = 0 - with open(consensus_path) as descriptor_file: + with open_desc(consensus_path, absolute = True) as descriptor_file: document_type = stem.descriptor.networkstatus.NetworkStatusDocumentV3
for router in stem.descriptor.networkstatus._parse_file(descriptor_file, document_type, is_microdescriptor = True): @@ -115,10 +117,10 @@ class TestNetworkStatus(unittest.TestCase): Checks if consensus documents from Metrics are parsed properly. """
- consensus_path = test.integ.descriptor.get_resource("metrics_consensus") + consensus_path = get_resource("metrics_consensus")
for specify_type in (True, False): - with open(consensus_path) as descriptor_file: + with open_desc(consensus_path, absolute = True) as descriptor_file: if specify_type: descriptors = stem.descriptor.parse_file(descriptor_file, "network-status-consensus-3 1.0", path = consensus_path) else: @@ -138,9 +140,9 @@ class TestNetworkStatus(unittest.TestCase): Checks if the bridge documents from Metrics are parsed properly. """
- consensus_path = test.integ.descriptor.get_resource("bridge_network_status") + consensus_path = get_resource("bridge_network_status")
- with open(consensus_path) as descriptor_file: + with open_desc(consensus_path, absolute = True) as descriptor_file: descriptors = stem.descriptor.parse_file(descriptor_file, path = consensus_path)
router = next(descriptors) @@ -186,7 +188,7 @@ RY22NXCwrJvSMEwiy7acC8FGysqwHRyE356+Rw6TB43g3Tno9KaHEK7MHXjSHwNs GM9hAsAMRX9Ogqhq5UjDNqEsvDKuyVeyh7unSZEOip9Zr6K/+7VsVPNb8vfBRBjo -----END SIGNATURE-----"""
- cert_path = test.integ.descriptor.get_resource("metrics_cert") + cert_path = get_resource("metrics_cert")
with open(cert_path) as cert_file: certs = stem.descriptor.parse_file(cert_file, path = cert_path) @@ -243,9 +245,7 @@ mfWcW0b+jsrXcJoCxV5IrwCDF3u1aC3diwZY6yiG186pwWbOwE41188XI2DeYPwE I/TJmV928na7RLZe2mGHCAW3VQOvV+QkCfj05VZ8CsY= -----END SIGNATURE-----"""
- consensus_path = test.integ.descriptor.get_resource("cached-consensus") - - with open(consensus_path) as descriptor_file: + with open_desc("cached-consensus") as descriptor_file: document = stem.descriptor.networkstatus.NetworkStatusDocumentV3(descriptor_file.read(), default_params = False)
self.assertEquals(3, document.version) @@ -316,9 +316,7 @@ nTA+fD8JQqpPtb8b0SnG9kwy75eS//sRu7TErie2PzGMxrf9LH0LAgMBAAE= TpQQk3nNQF8z6UIvdlvP+DnJV4izWVkQEZgUZgIVM0E= -----END SIGNATURE-----"""
- consensus_path = test.integ.descriptor.get_resource("cached-consensus-v2") - - with open(consensus_path) as descriptor_file: + with open_desc("cached-consensus-v2") as descriptor_file: descriptor_file.readline() # strip header document = stem.descriptor.networkstatus.NetworkStatusDocumentV2(descriptor_file.read())
@@ -381,9 +379,9 @@ TpQQk3nNQF8z6UIvdlvP+DnJV4izWVkQEZgUZgIVM0E= Checks if vote documents from Metrics are parsed properly. """
- vote_path = test.integ.descriptor.get_resource("metrics_vote") + vote_path = get_resource("metrics_vote")
- with open(vote_path) as descriptor_file: + with open_desc(vote_path, absolute = True) as descriptor_file: descriptors = stem.descriptor.parse_file(descriptor_file, path = vote_path)
router = next(descriptors) @@ -445,9 +443,7 @@ JZ/1HL9sHyZfo6bwaC6YSM9PNiiY6L7rnGpS7UkHiFI+M96VCMorvjm5YPs3FioJ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w= -----END SIGNATURE-----"""
- vote_path = test.integ.descriptor.get_resource("vote") - - with open(vote_path) as descriptor_file: + with open_desc("vote") as descriptor_file: document = stem.descriptor.networkstatus.NetworkStatusDocumentV3(descriptor_file.read(), default_params = False)
self.assertEquals(3, document.version) diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py index 0258dfa..8eb262a 100644 --- a/test/integ/descriptor/server_descriptor.py +++ b/test/integ/descriptor/server_descriptor.py @@ -13,9 +13,10 @@ import stem.descriptor import stem.descriptor.server_descriptor import stem.exit_policy import stem.version -import test.integ.descriptor import test.runner
+from test.integ.descriptor import open_desc +
class TestServerDescriptor(unittest.TestCase): def test_metrics_descriptor(self): @@ -23,9 +24,7 @@ class TestServerDescriptor(unittest.TestCase): Parses and checks our results against a server descriptor from metrics. """
- descriptor_path = test.integ.descriptor.get_resource("example_descriptor") - - descriptor_file = open(descriptor_path) + descriptor_file = open_desc("example_descriptor") descriptor_file.readline() # strip header descriptor_contents = descriptor_file.read() descriptor_file.close() @@ -95,9 +94,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= Parses and checks our results against a server descriptor from metrics. """
- descriptor_path = test.integ.descriptor.get_resource("metrics_server_desc_multiple") - - with open(descriptor_path) as descriptor_file: + with open_desc("metrics_server_desc_multiple") as descriptor_file: descriptors = list(stem.descriptor.parse_file(descriptor_file, "server-descriptor 1.0"))
self.assertEquals(2, len(descriptors)) @@ -113,9 +110,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= Parses a relay server descriptor from 2005. """
- descriptor_path = test.integ.descriptor.get_resource("old_descriptor") - - descriptor_file = open(descriptor_path) + descriptor_file = open_desc("old_descriptor") descriptor_file.readline() # strip header descriptor_contents = descriptor_file.read() descriptor_file.close() @@ -177,7 +172,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= test.runner.skip(self, "(no cached descriptors)") return
- with open(descriptor_path) as descriptor_file: + with open_desc(descriptor_path, absolute = True) as descriptor_file: for desc in stem.descriptor.server_descriptor._parse_file(descriptor_file): # the following attributes should be deprecated, and not appear in the wild self.assertEquals(None, desc.read_history_end) @@ -201,9 +196,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= Parses a descriptor with non-ascii content. """
- descriptor_path = test.integ.descriptor.get_resource("non-ascii_descriptor") - - descriptor_file = open(descriptor_path) + descriptor_file = open_desc("non-ascii_descriptor") descriptor_file.readline() # strip header descriptor_contents = descriptor_file.read() descriptor_file.close() @@ -243,9 +236,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= returns ('\r' entries). """
- descriptor_path = test.integ.descriptor.get_resource("cr_in_contact_line") - - descriptor_file = open(descriptor_path) + descriptor_file = open_desc("cr_in_contact_line") descriptor_file.readline() # strip header descriptor_contents = descriptor_file.read() descriptor_file.close() @@ -271,9 +262,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= where we shouldn't be. """
- descriptor_path = test.integ.descriptor.get_resource("negative_uptime") - - descriptor_file = open(descriptor_path) + descriptor_file = open_desc("negative_uptime") descriptor_file.readline() # strip header descriptor_contents = descriptor_file.read() descriptor_file.close() @@ -295,9 +284,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= Parses a bridge descriptor. """
- descriptor_path = test.integ.descriptor.get_resource("bridge_descriptor") - - descriptor_file = open(descriptor_path) + descriptor_file = open_desc("bridge_descriptor") descriptor_file.readline() # strip header descriptor_contents = descriptor_file.read() descriptor_file.close()
tor-commits@lists.torproject.org