commit 0faa9dc5af392bad7a4c0fa73e28a5c186b65e9c Author: Damian Johnson atagar@torproject.org Date: Wed Apr 5 11:02:01 2017 -0700
Replace skip helper with builtin
Long ago I added a skip helper because python 2.6 doesn't have this method. Now that we vend a TimedTestRunner we can add this capability directly to that. This will make removal of python 2.6 support easier later (all we gotta do is drop the unnecessary return statements). --- stem/util/test_tools.py | 7 ++ test/integ/control/base_controller.py | 9 +-- test/integ/control/controller.py | 9 ++- test/integ/descriptor/extrainfo_descriptor.py | 3 +- test/integ/descriptor/microdescriptor.py | 3 +- test/integ/descriptor/networkstatus.py | 9 ++- test/integ/descriptor/remote.py | 3 +- test/integ/descriptor/server_descriptor.py | 3 +- test/integ/installation.py | 7 +- test/integ/manual.py | 3 +- test/integ/process.py | 3 +- test/integ/util/connection.py | 7 +- test/integ/util/proc.py | 19 +++--- test/integ/util/system.py | 97 ++++++++++++++------------- test/integ/version.py | 7 +- test/unit/descriptor/export.py | 5 +- test/unit/descriptor/reader.py | 11 ++- test/unit/installation.py | 6 +- test/unit/manual.py | 12 ++-- test/unit/tutorial_examples.py | 3 +- test/util.py | 25 ++----- 21 files changed, 109 insertions(+), 142 deletions(-)
diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py index 2600413..0b44d3a 100644 --- a/stem/util/test_tools.py +++ b/stem/util/test_tools.py @@ -71,6 +71,13 @@ class TimedTestRunner(unittest.TextTestRunner): TEST_RUNTIMES[self.id()] = time.time() - start_time return result
+ # TODO: remove and drop unnecessary 'returns' when dropping python 2.6 + # support + + def skipTest(self, message): + if not stem.prereq._is_python_26(): + return super(original_type, self).skipTest(message) + # TODO: remove when dropping python 2.6 support
def assertRaisesRegexp(self, exc_type, exc_msg, func, *args, **kwargs): diff --git a/test/integ/control/base_controller.py b/test/integ/control/base_controller.py index 78e6e3e..0a51e1f 100644 --- a/test/integ/control/base_controller.py +++ b/test/integ/control/base_controller.py @@ -14,10 +14,7 @@ import stem.util.system import test.mocking import test.runner
-from test.util import ( - skip, - require_controller, -) +from test.util import require_controller
class StateObserver(object): @@ -50,7 +47,7 @@ class TestBaseController(unittest.TestCase): """
if stem.util.system.is_mac(): - skip(self, '(ticket #6235)') + self.skipTest('(ticket #6235)') return
with test.runner.get_runner().get_tor_socket() as control_socket: @@ -100,7 +97,7 @@ class TestBaseController(unittest.TestCase): """
if stem.util.system.is_mac(): - skip(self, '(ticket #6235)') + self.skipTest('(ticket #6235)') return
with test.runner.get_runner().get_tor_socket() as control_socket: diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py index 877c40b..48a50fe 100644 --- a/test/integ/control/controller.py +++ b/test/integ/control/controller.py @@ -30,7 +30,6 @@ from stem.version import Requirement from test.util import ( register_new_capability, tor_version, - skip, only_run_once, require_controller, require_version, @@ -1126,7 +1125,7 @@ class TestController(unittest.TestCase): runner = test.runner.get_runner()
if not os.path.exists(runner.get_test_dir('cached-descriptors')): - skip(self, '(no cached microdescriptors)') + self.skipTest('(no cached microdescriptors)') return
with runner.get_tor_controller() as controller: @@ -1148,7 +1147,7 @@ class TestController(unittest.TestCase): runner = test.runner.get_runner()
if tor_version() >= Requirement.MICRODESCRIPTOR_IS_DEFAULT: - skip(self, '(requires server descriptors)') + self.skipTest('(requires server descriptors)') return
with runner.get_tor_controller() as controller: @@ -1178,7 +1177,7 @@ class TestController(unittest.TestCase): runner = test.runner.get_runner()
if tor_version() >= Requirement.MICRODESCRIPTOR_IS_DEFAULT: - skip(self, '(requires server descriptors)') + self.skipTest('(requires server descriptors)') return
with runner.get_tor_controller() as controller: @@ -1358,7 +1357,7 @@ class TestController(unittest.TestCase):
if TEST_ROUTER_STATUS_ENTRY is None: # this is only likely to occure if we can't get descriptors - skip(self, '(no named relays)') + self.skipTest('(no named relays)') return
return TEST_ROUTER_STATUS_ENTRY diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py index 2ac44fe..6ea2b16 100644 --- a/test/integ/descriptor/extrainfo_descriptor.py +++ b/test/integ/descriptor/extrainfo_descriptor.py @@ -10,7 +10,6 @@ import test.runner
from test.util import ( register_new_capability, - skip, only_run_once, )
@@ -27,7 +26,7 @@ class TestExtraInfoDescriptor(unittest.TestCase): descriptor_path = test.runner.get_runner().get_test_dir('cached-extrainfo')
if not os.path.exists(descriptor_path): - skip(self, '(no cached descriptors)') + self.skipTest('(no cached descriptors)') return
with open(descriptor_path, 'rb') as descriptor_file: diff --git a/test/integ/descriptor/microdescriptor.py b/test/integ/descriptor/microdescriptor.py index b1796c2..97127d6 100644 --- a/test/integ/descriptor/microdescriptor.py +++ b/test/integ/descriptor/microdescriptor.py @@ -10,7 +10,6 @@ import test.runner
from test.util import ( register_new_capability, - skip, only_run_once, )
@@ -27,7 +26,7 @@ class TestMicrodescriptor(unittest.TestCase): descriptor_path = test.runner.get_runner().get_test_dir('cached-microdescs')
if not os.path.exists(descriptor_path): - skip(self, '(no cached microdescriptors)') + self.skipTest('(no cached microdescriptors)') return
with open(descriptor_path, 'rb') as descriptor_file: diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py index e6bdce2..72d503a 100644 --- a/test/integ/descriptor/networkstatus.py +++ b/test/integ/descriptor/networkstatus.py @@ -13,7 +13,6 @@ import test.runner
from test.util import ( register_new_capability, - skip, only_run_once, )
@@ -28,13 +27,13 @@ class TestNetworkStatus(unittest.TestCase): consensus_path = test.runner.get_runner().get_test_dir('cached-consensus')
if not os.path.exists(consensus_path): - skip(self, '(no cached-consensus)') + self.skipTest('(no cached-consensus)') return elif stem.util.system.is_windows(): # Unable to check memory usage on windows, so can't prevent hanging the # system if things go bad.
- skip(self, '(unavailable on windows)') + self.skipTest('(unavailable on windows)') return
count, reported_flags = 0, [] @@ -65,10 +64,10 @@ class TestNetworkStatus(unittest.TestCase): consensus_path = test.runner.get_runner().get_test_dir('cached-microdesc-consensus')
if not os.path.exists(consensus_path): - skip(self, '(no cached-microdesc-consensus)') + self.skipTest('(no cached-microdesc-consensus)') return elif stem.util.system.is_windows(): - skip(self, '(unavailable on windows)') + self.skipTest('(unavailable on windows)') return
count, reported_flags = 0, [] diff --git a/test/integ/descriptor/remote.py b/test/integ/descriptor/remote.py index cd18187..b873b96 100644 --- a/test/integ/descriptor/remote.py +++ b/test/integ/descriptor/remote.py @@ -12,7 +12,6 @@ import stem.descriptor.router_status_entry import stem.descriptor.server_descriptor
from test.util import ( - skip, only_run_once, require_online, ) @@ -247,7 +246,7 @@ class TestDescriptorDownloader(unittest.TestCase): # Don't run this test by default. Once upon a time it was fine, but tor has # added so many fallbacks now that this takes a looong time. :(
- skip(self, '(skipped by default)') + self.skipTest('(skipped by default)') return
unsuccessful = {} diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py index 302cef1..bd61e70 100644 --- a/test/integ/descriptor/server_descriptor.py +++ b/test/integ/descriptor/server_descriptor.py @@ -11,7 +11,6 @@ import test.runner
from test.util import ( register_new_capability, - skip, only_run_once, )
@@ -28,7 +27,7 @@ class TestServerDescriptor(unittest.TestCase): descriptor_path = test.runner.get_runner().get_test_dir('cached-descriptors')
if not os.path.exists(descriptor_path): - skip(self, '(no cached descriptors)') + self.skipTest('(no cached descriptors)') return
with open(descriptor_path, 'rb') as descriptor_file: diff --git a/test/integ/installation.py b/test/integ/installation.py index 72f2df4..ad21fd0 100644 --- a/test/integ/installation.py +++ b/test/integ/installation.py @@ -11,10 +11,7 @@ import stem.util.system
import test.util
-from test.util import ( - skip, - only_run_once, -) +from test.util import only_run_once
INSTALL_MISMATCH_MSG = "Running 'python setup.py sdist' doesn't match our git contents in the following way. The manifest in our setup.py may need to be updated...\n\n"
@@ -134,7 +131,7 @@ class TestInstallation(unittest.TestCase): """
if not stem.util.system.is_available('git'): - skip(self, '(git unavailable)') + self.skipTest('(git unavailable)') return
setup().join() diff --git a/test/integ/manual.py b/test/integ/manual.py index 187cde9..f9d4dbd 100644 --- a/test/integ/manual.py +++ b/test/integ/manual.py @@ -13,7 +13,6 @@ import stem.util.system import test.runner
from stem.manual import Category -from test.util import skip
EXPECTED_CATEGORIES = set([ 'NAME', @@ -120,7 +119,7 @@ class TestManual(unittest.TestCase):
def requires_downloaded_manual(self): if self.skip_reason: - skip(self, self.skip_reason) + self.skipTest(self.skip_reason) return True elif self.download_error: self.fail(self.download_error) diff --git a/test/integ/process.py b/test/integ/process.py index 4cc79e3..e77fdfb 100644 --- a/test/integ/process.py +++ b/test/integ/process.py @@ -23,7 +23,6 @@ import stem.version import test.runner
from test.util import ( - skip, require_controller, require_version, ) @@ -441,7 +440,7 @@ class TestProcess(unittest.TestCase): """
if not stem.util.system.is_available('sleep'): - skip(self, "('sleep' command is unavailable)") + self.skipTest("('sleep' command is unavailable)") return
sleep_process = subprocess.Popen(['sleep', '60']) diff --git a/test/integ/util/connection.py b/test/integ/util/connection.py index 1145169..63f62ff 100644 --- a/test/integ/util/connection.py +++ b/test/integ/util/connection.py @@ -8,7 +8,6 @@ import unittest import test.runner
from stem.util.connection import Resolver, get_connections, system_resolvers -from test.util import skip
class TestConnection(unittest.TestCase): @@ -16,13 +15,13 @@ class TestConnection(unittest.TestCase): runner = test.runner.get_runner()
if test.runner.Torrc.PORT not in runner.get_options(): - skip(self, '(no control port)') + self.skipTest('(no control port)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment set)') + self.skipTest('(DisableDebuggerAttachment set)') return elif resolver not in system_resolvers(): - skip(self, '(resolver unavailable on this platform)') + self.skipTest('(resolver unavailable on this platform)') return
with runner.get_tor_socket(): diff --git a/test/integ/util/proc.py b/test/integ/util/proc.py index 4671b3d..a7e798d 100644 --- a/test/integ/util/proc.py +++ b/test/integ/util/proc.py @@ -9,7 +9,6 @@ import unittest import test.runner
from stem.util import proc -from test.util import skip
class TestProc(unittest.TestCase): @@ -19,10 +18,10 @@ class TestProc(unittest.TestCase): """
if not proc.is_available(): - skip(self, '(proc unavailable)') + self.skipTest('(proc unavailable)') return elif not test.runner.get_runner().is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return
runner = test.runner.get_runner() @@ -35,7 +34,7 @@ class TestProc(unittest.TestCase): """
if not proc.is_available(): - skip(self, '(proc unavailable)') + self.skipTest('(proc unavailable)') return
tor_pid = test.runner.get_runner().get_pid() @@ -47,7 +46,7 @@ class TestProc(unittest.TestCase): """
if not proc.is_available(): - skip(self, '(proc unavailable)') + self.skipTest('(proc unavailable)') return
tor_pid = test.runner.get_runner().get_pid() @@ -63,7 +62,7 @@ class TestProc(unittest.TestCase): """
if not proc.is_available(): - skip(self, '(proc unavailable)') + self.skipTest('(proc unavailable)') return
tor_cmd = test.runner.get_runner().get_tor_command(True) @@ -84,16 +83,16 @@ class TestProc(unittest.TestCase): runner = test.runner.get_runner()
if not proc.is_available(): - skip(self, '(proc unavailable)') + self.skipTest('(proc unavailable)') return elif test.runner.Torrc.PORT not in runner.get_options(): - skip(self, '(no control port)') + self.skiTestp('(no control port)') return elif not test.runner.get_runner().is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return elif not os.access('/proc/net/tcp', os.R_OK) or not os.access('/proc/net/udp', os.R_OK): - skip(self, '(proc lacks read permissions)') + self.skipTest('(proc lacks read permissions)') return
# making a controller connection so that we have something to query for diff --git a/test/integ/util/system.py b/test/integ/util/system.py index eee2ccb..973c3cb 100644 --- a/test/integ/util/system.py +++ b/test/integ/util/system.py @@ -12,8 +12,6 @@ import stem.util.proc import stem.util.system import test.runner
-from test.util import skip - try: # added in python 3.3 from unittest.mock import Mock, patch @@ -69,7 +67,7 @@ class TestSystem(unittest.TestCase): """
if not stem.util.system.is_available('ps'): - skip(self, '(ps unavailable)') + self.skipTest('(ps unavailable)') return
# Check to see if the command we started tor with is running. The process @@ -87,7 +85,7 @@ class TestSystem(unittest.TestCase): """
if self._is_extra_tor_running(): - skip(self, '(multiple tor instances)') + self.skipTest('(multiple tor instances)') return
tor_pid = test.runner.get_runner().get_pid() @@ -101,10 +99,10 @@ class TestSystem(unittest.TestCase): """
if self._is_extra_tor_running(): - skip(self, '(multiple tor instances)') + self.skipTest('(multiple tor instances)') return elif not stem.util.system.is_available('pgrep'): - skip(self, '(pgrep unavailable)') + self.skipTest('(pgrep unavailable)') return
pgrep_prefix = stem.util.system.GET_PID_BY_NAME_PGREP % '' @@ -124,10 +122,10 @@ class TestSystem(unittest.TestCase): """
if self._is_extra_tor_running(): - skip(self, '(multiple tor instances)') + self.skipTest('(multiple tor instances)') return elif not stem.util.system.is_available('pidof'): - skip(self, '(pidof unavailable)') + self.skipTest('(pidof unavailable)') return
pidof_prefix = stem.util.system.GET_PID_BY_NAME_PIDOF % '' @@ -147,13 +145,13 @@ class TestSystem(unittest.TestCase): """
if self._is_extra_tor_running(): - skip(self, '(multiple tor instances)') + self.skipTest('(multiple tor instances)') return elif not stem.util.system.is_available('ps'): - skip(self, '(ps unavailable)') + self.skipTest('(ps unavailable)') return elif stem.util.system.is_bsd(): - skip(self, '(linux only)') + self.skipTest('(linux only)') return
ps_prefix = stem.util.system.GET_PID_BY_NAME_PS_LINUX % '' @@ -173,13 +171,13 @@ class TestSystem(unittest.TestCase): """
if self._is_extra_tor_running(): - skip(self, '(multiple tor instances)') + self.skipTest('(multiple tor instances)') return elif not stem.util.system.is_available('ps'): - skip(self, '(ps unavailable)') + self.skipTest('(ps unavailable)') return elif not stem.util.system.is_bsd(): - skip(self, '(bsd only)') + self.skipTest('(bsd only)') return
ps_prefix = stem.util.system.GET_PID_BY_NAME_PS_BSD @@ -200,13 +198,13 @@ class TestSystem(unittest.TestCase):
runner = test.runner.get_runner() if self._is_extra_tor_running(): - skip(self, '(multiple tor instances)') + self.skipTest('(multiple tor instances)') return elif not stem.util.system.is_available('lsof'): - skip(self, '(lsof unavailable)') + self.skipTest('(lsof unavailable)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return
lsof_prefix = stem.util.system.GET_PID_BY_NAME_LSOF % '' @@ -229,10 +227,10 @@ class TestSystem(unittest.TestCase): """
if self._is_extra_tor_running(): - skip(self, '(multiple tor instances)') + self.skipTest('(multiple tor instances)') return elif not stem.util.system.is_available('tasklist'): - skip(self, '(tasklist unavailable)') + self.skipTest('(tasklist unavailable)') return
runner = test.runner.get_runner() @@ -245,21 +243,21 @@ class TestSystem(unittest.TestCase):
runner = test.runner.get_runner() if stem.util.system.is_windows(): - skip(self, '(unavailable on windows)') + self.skipTest('(unavailable on windows)') return elif not _has_port(): - skip(self, '(test instance has no port)') + self.skipTest('(test instance has no port)') return elif stem.util.system.is_mac() or stem.util.system.is_gentoo(): - skip(self, '(resolvers unavailable)') + self.skipTest('(resolvers unavailable)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return elif not (stem.util.system.is_available('netstat') or stem.util.system.is_available('sockstat') or stem.util.system.is_available('lsof')): - skip(self, '(connection resolvers unavailable)') + self.skipTest('(connection resolvers unavailable)') return
tor_pid, tor_port = runner.get_pid(), test.runner.CONTROL_PORT @@ -272,20 +270,21 @@ class TestSystem(unittest.TestCase): """
runner = test.runner.get_runner() + if not _has_port(): - skip(self, '(test instance has no port)') + self.skipTest('(test instance has no port)') return elif not stem.util.system.is_available('netstat'): - skip(self, '(netstat unavailable)') + self.skipTest('(netstat unavailable)') return elif stem.util.system.is_bsd() or stem.util.system.is_windows(): - skip(self, '(linux only)') + self.skipTest('(linux only)') return elif stem.util.system.is_gentoo(): - skip(self, '(unavailable on gentoo)') + self.skipTest('(unavailable on gentoo)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return
netstat_prefix = stem.util.system.GET_PID_BY_PORT_NETSTAT @@ -304,17 +303,18 @@ class TestSystem(unittest.TestCase): """
runner = test.runner.get_runner() + if not _has_port(): - skip(self, '(test instance has no port)') + self.skipTest('(test instance has no port)') return elif not stem.util.system.is_available('sockstat'): - skip(self, '(sockstat unavailable)') + self.skipTest('(sockstat unavailable)') return elif not stem.util.system.is_bsd(): - skip(self, '(bsd only)') + self.skipTest('(bsd only)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return
sockstat_prefix = stem.util.system.GET_PID_BY_PORT_SOCKSTAT % '' @@ -333,17 +333,18 @@ class TestSystem(unittest.TestCase): """
runner = test.runner.get_runner() + if not _has_port(): - skip(self, '(test instance has no port)') + self.skipTest('(test instance has no port)') return elif not stem.util.system.is_available('lsof'): - skip(self, '(lsof unavailable)') + self.skipTest('(lsof unavailable)') return elif stem.util.system.is_mac() or stem.util.system.is_gentoo(): - skip(self, '(resolvers unavailable)') + self.skipTest('(resolvers unavailable)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return
lsof_prefix = stem.util.system.GET_PID_BY_PORT_LSOF @@ -387,10 +388,10 @@ class TestSystem(unittest.TestCase): runner = test.runner.get_runner()
if stem.util.system.is_windows(): - skip(self, '(unavailable on windows)') + self.skipTest('(unavailable on windows)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return
runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd() @@ -405,10 +406,10 @@ class TestSystem(unittest.TestCase): runner = test.runner.get_runner()
if not stem.util.system.is_available('pwdx'): - skip(self, '(pwdx unavailable)') + self.skipTest('(pwdx unavailable)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return
# filter the call function to only allow this command @@ -431,10 +432,10 @@ class TestSystem(unittest.TestCase): runner = test.runner.get_runner()
if not stem.util.system.is_available('lsof'): - skip(self, '(lsof unavailable)') + self.skipTest('(lsof unavailable)') return elif not runner.is_ptraceable(): - skip(self, '(DisableDebuggerAttachment is set)') + self.skipTest('(DisableDebuggerAttachment is set)') return
# filter the call function to only allow this command @@ -464,7 +465,7 @@ class TestSystem(unittest.TestCase): """
if not stem.util.proc.is_available(): - skip(self, '(proc unavailable)') + self.skipTest('(proc unavailable)') return
call_replacement = filter_system_call(['ps ']) @@ -484,7 +485,7 @@ class TestSystem(unittest.TestCase): """
if not stem.util.system.is_available('ps'): - skip(self, '(ps unavailable)') + self.skipTest('(ps unavailable)') return
pid = test.runner.get_runner().get_pid() @@ -505,7 +506,7 @@ class TestSystem(unittest.TestCase): """
if not stem.util.proc.is_available(): - skip(self, '(proc unavailable)') + self.skipTest('(proc unavailable)') return
call_replacement = filter_system_call(['ps ']) @@ -523,7 +524,7 @@ class TestSystem(unittest.TestCase): """
if not stem.util.system.is_available('ps'): - skip(self, '(ps unavailable)') + self.skipTest('(ps unavailable)') return
pid = test.runner.get_runner().get_pid() @@ -553,7 +554,7 @@ class TestSystem(unittest.TestCase): # '/root'
if getpass.getuser() == 'root': - skip(self, '(running as root)') + self.skipTest('(running as root)') return
self.assertEqual(os.getcwd(), stem.util.system.expand_path('.')) diff --git a/test/integ/version.py b/test/integ/version.py index 06837c7..35e016a 100644 --- a/test/integ/version.py +++ b/test/integ/version.py @@ -9,10 +9,7 @@ import stem.prereq import stem.version import test.runner
-from test.util import ( - skip, - require_controller, -) +from test.util import require_controller
class TestVersion(unittest.TestCase): @@ -22,7 +19,7 @@ class TestVersion(unittest.TestCase): """
if not stem.util.system.is_available('tor'): - skip(self, "(tor isn't in our path)") + self.skipTest("(tor isn't in our path)") return
# Since tor is in our path we should expect to be able to get the version diff --git a/test/unit/descriptor/export.py b/test/unit/descriptor/export.py index ae7e4a0..a262343 100644 --- a/test/unit/descriptor/export.py +++ b/test/unit/descriptor/export.py @@ -12,7 +12,6 @@ except ImportError: import stem.prereq
from stem.descriptor.export import export_csv, export_csv_file -from test.util import skip
from test.mocking import ( get_relay_server_descriptor, @@ -27,7 +26,7 @@ class TestExport(unittest.TestCase): """
if stem.prereq._is_python_26(): - skip(self, '(header added in python 2.7)') + self.skipTest('(header added in python 2.7)') return
desc = get_relay_server_descriptor() @@ -76,7 +75,7 @@ class TestExport(unittest.TestCase): """
if stem.prereq._is_python_26(): - skip(self, '(header added in python 2.7)') + self.skipTest('(header added in python 2.7)') return
desc = get_relay_server_descriptor() diff --git a/test/unit/descriptor/reader.py b/test/unit/descriptor/reader.py index ac7fd83..ad6a425 100644 --- a/test/unit/descriptor/reader.py +++ b/test/unit/descriptor/reader.py @@ -17,7 +17,6 @@ import stem.descriptor.reader import test.unit.descriptor
from stem.util import str_type, system -from test.util import skip
try: # added in python 3.3 @@ -191,7 +190,7 @@ class TestDescriptorReader(unittest.TestCase): # test relies on being unable to read a file
if getpass.getuser() == 'root': - skip(self, '(running as root)') + self.skipTest('(running as root)') return
# Skip the test on windows, since you can only set the file's @@ -199,7 +198,7 @@ class TestDescriptorReader(unittest.TestCase): # http://docs.python.org/library/os.html#os.chmod
if system.is_windows(): - skip(self, '(chmod not functional)') + self.skipTest('(chmod not functional)')
test_listing_path = self._make_processed_files_listing(BASIC_LISTING) os.chmod(test_listing_path, 0o077) # remove read permissions @@ -413,7 +412,7 @@ class TestDescriptorReader(unittest.TestCase): # Skip on windows since SIGALRM is unavailable
if system.is_windows(): - skip(self, '(SIGALRM unavailable)') + self.skipTest('(SIGALRM unavailable)')
is_test_running = True reader = stem.descriptor.reader.DescriptorReader('/usr') @@ -550,10 +549,10 @@ class TestDescriptorReader(unittest.TestCase): # test relies on being unable to read a file
if getpass.getuser() == 'root': - skip(self, '(running as root)') + self.skipTest('(running as root)') return elif system.is_windows(): - skip(self, '(chmod not functional)') + self.skipTest('(chmod not functional)') return
test_path = os.path.join(self.temp_directory, 'secret_file') diff --git a/test/unit/installation.py b/test/unit/installation.py index 83d560a..73881de 100644 --- a/test/unit/installation.py +++ b/test/unit/installation.py @@ -5,8 +5,6 @@ import unittest
import test.util
-from test.util import skip -
class TestInstallation(unittest.TestCase): # TODO: remove when dropping support for python 2.6 @@ -26,7 +24,7 @@ class TestInstallation(unittest.TestCase):
def test_installs_all_modules(self): if self.skip_reason: - skip(self, self.skip_reason) + self.skipTest(self.skip_reason) return True
# Modules cited my our setup.py looks like... @@ -50,7 +48,7 @@ class TestInstallation(unittest.TestCase):
def test_installs_all_data_files(self): if self.skip_reason: - skip(self, self.skip_reason) + self.skipTest(self.skip_reason) return True
# Checking that we have all non-source files. Data looks like... diff --git a/test/unit/manual.py b/test/unit/manual.py index deded2d..6d0c174 100644 --- a/test/unit/manual.py +++ b/test/unit/manual.py @@ -12,8 +12,6 @@ import stem.prereq import stem.manual import stem.util.system
-from test.util import skip - try: # account for urllib's change between python 2.x and 3.x import urllib.request as urllib @@ -160,10 +158,10 @@ class TestManual(unittest.TestCase): """
if not stem.util.system.is_available('man'): - skip(self, '(require man command)') + self.skipTest('(require man command)') return elif stem.util.system.is_mac(): - skip(self, '(man lacks --encoding arg on OSX, #18660)') + self.skipTest('(man lacks --encoding arg on OSX, #18660)') return
manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH) @@ -183,10 +181,10 @@ class TestManual(unittest.TestCase): """
if not stem.util.system.is_available('man'): - skip(self, '(require man command)') + self.skipTest('(require man command)') return elif stem.util.system.is_mac(): - skip(self, '(man lacks --encoding arg on OSX, #18660)') + self.skipTest('(man lacks --encoding arg on OSX, #18660)') return
manual = stem.manual.Manual.from_man(UNKNOWN_OPTIONS_MAN_PATH) @@ -213,7 +211,7 @@ class TestManual(unittest.TestCase): """
if not stem.util.system.is_available('man'): - skip(self, '(require man command)') + self.skipTest('(require man command)') return
manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH) diff --git a/test/unit/tutorial_examples.py b/test/unit/tutorial_examples.py index bf313ce..de5079e 100644 --- a/test/unit/tutorial_examples.py +++ b/test/unit/tutorial_examples.py @@ -21,7 +21,6 @@ from stem.descriptor.remote import DIRECTORY_AUTHORITIES
from test import mocking from test.unit import exec_documentation_example -from test.util import skip
from test.mocking import ( get_relay_server_descriptor, @@ -247,7 +246,7 @@ class TestTutorialExamples(unittest.TestCase): # example imports OrderedDict from collections which doesn't work under # python 2.6
- skip(self, "(example doesn't support python 2.6)") + self.skipTest("(example doesn't support python 2.6)") return
get_authorities_mock().items.return_value = [('moria1', DIRECTORY_AUTHORITIES['moria1']), ('maatuska', DIRECTORY_AUTHORITIES['maatuska'])] diff --git a/test/util.py b/test/util.py index 75ea50e..2468b55 100644 --- a/test/util.py +++ b/test/util.py @@ -18,8 +18,7 @@ Tasks are...
::
- Test Skipping - |- skip - skips the current test if we can + Test Requirements |- only_run_once - skip test if it has been ran before |- require - skips the test unless a requirement is met | @@ -220,20 +219,6 @@ def get_new_capabilities(): return NEW_CAPABILITIES
-def skip(test_case, message): - """ - Skips the test if we can. The capability for skipping tests was added in - python 2.7 so callers should return after this, so they report 'success' if - this method is unavailable. - - :param unittest.TestCase test_case: test being ran - :param str message: message to skip the test with - """ - - if not stem.prereq._is_python_26(): - test_case.skipTest(message) - - def only_run_once(func): """ Skips the test if it has ran before. If it hasn't then flags it as being ran. @@ -246,7 +231,7 @@ def only_run_once(func): RAN_TESTS.append(self.id()) return func(self, *args, **kwargs) else: - skip(self, '(already ran)') + self.skipTest('(already ran)')
return wrapped
@@ -261,7 +246,7 @@ def require(condition, message): if condition(): return func(self, *args, **kwargs) else: - skip(self, '(%s)' % message) + self.skipTest('(%s)' % message)
return wrapped
@@ -281,7 +266,7 @@ def require_controller(func): if test.runner.get_runner().is_accessible(): return func(self, *args, **kwargs) else: - skip(self, '(no connection)') + self.skipTest('(no connection)')
return wrapped
@@ -306,7 +291,7 @@ def require_online(func): if Target.ONLINE in test.runner.get_runner().attribute_targets: return func(self, *args, **kwargs) else: - skip(self, '(requires online target)') + self.skipTest('(requires online target)')
return wrapped