[tor-commits] [bridgedb/develop] Switch to using relative imports for test helpers in test/tests_*.py.
isis at torproject.org
isis at torproject.org
Thu Jun 25 07:10:55 UTC 2015
commit 6d309cae1e709e615b592690f1a34369f60fa709
Author: Isis Lovecruft <isis at torproject.org>
Date: Thu Jun 25 05:47:04 2015 +0000
Switch to using relative imports for test helpers in test/tests_*.py.
---
bridgedb/util.py | 48 +++++++++++++++++++++-----------------
test/email_helpers.py | 3 ++-
test/https_helpers.py | 3 ++-
test/legacy_Tests.py | 20 +++++++++-------
test/test_Tests.py | 37 +++++++++++++++--------------
test/test_bridgedb.py | 4 ++--
test/test_bridges.py | 6 ++---
test/test_crypto.py | 5 ++--
test/test_email_autoresponder.py | 7 +++---
test/test_email_distributor.py | 3 ++-
test/test_email_server.py | 7 +++---
test/test_https.py | 4 ++--
test/test_https_distributor.py | 7 +++---
test/test_https_server.py | 11 +++++----
test/test_parse_descriptors.py | 2 +-
test/test_smtp.py | 4 ++--
test/test_translations.py | 2 +-
test/util.py | 8 +++----
18 files changed, 98 insertions(+), 83 deletions(-)
diff --git a/bridgedb/util.py b/bridgedb/util.py
index f15e08b..4c558c4 100644
--- a/bridgedb/util.py
+++ b/bridgedb/util.py
@@ -153,6 +153,7 @@ def levenshteinDistance(s1, s2, len1=None, len2=None,
the number of characters which must be changed in **s1** to make it
identical to **s2**.
+ >>> from bridgedb.util import levenshteinDistance
>>> levenshteinDistance('cat', 'cat')
0
>>> levenshteinDistance('cat', 'hat')
@@ -188,6 +189,7 @@ def isascii(s):
Note that this function differs from the str.is* methods in that
it returns True for the empty string, rather than False.
+ >>> from bridgedb.util import isascii
>>> isascii('\x80')
False
>>> isascii('foo\tbar\rbaz\n')
@@ -206,6 +208,7 @@ def isascii_noncontrol(s):
Note that this function differs from the str.is* methods in that
it returns True for the empty string, rather than False.
+ >>> from bridgedb.util import isascii_noncontrol
>>> isascii_noncontrol('\x80')
False
>>> isascii_noncontrol('foo\tbar\rbaz\n')
@@ -220,6 +223,7 @@ def isascii_noncontrol(s):
def replaceControlChars(text, replacement=None, encoding="utf-8"):
"""Remove ASCII control characters [0-31, 92, 127].
+ >>> from bridgedb.util import replaceControlChars
>>> replaceControlChars('foo\n bar\\ baz\r \t\0quux\n')
'foo bar baz quux'
>>> replaceControlChars("\bI wonder if I'm outside the quotes now")
@@ -344,36 +348,36 @@ class mixin:
>>> from bridgedb.util import mixin
>>>
>>> class ClassA(object):
- >>> def sayWhich(self):
- >>> print("ClassA.sayWhich() called.")
- >>> def doSuperThing(self):
- >>> super(ClassA, self).__repr__()
- >>> def doThing(self):
- >>> print("ClassA is doing a thing.")
- >>>
+ ... def sayWhich(self):
+ ... print("ClassA.sayWhich() called.")
+ ... def doSuperThing(self):
+ ... print("%s" % super(ClassA, self))
+ ... def doThing(self):
+ ... print("ClassA is doing a thing.")
+ ...
>>> class ClassB(ClassA):
- >>> def sayWhich(self):
- >>> print("ClassB.sayWhich() called.")
- >>> def doSuperThing(self):
- >>> super(ClassB, self).__repr__()
- >>> def doOtherThing(self):
- >>> print("ClassB is doing something else.")
- >>>
+ ... def sayWhich(self):
+ ... print("ClassB.sayWhich() called.")
+ ... def doSuperThing(self):
+ ... print("%s" % super(ClassB, self))
+ ... def doOtherThing(self):
+ ... print("ClassB is doing something else.")
+ ...
>>> class ClassM(mixin):
- >>> def sayWhich(self):
- >>> print("ClassM.sayWhich() called.")
- >>>
+ ... def sayWhich(self):
+ ... print("ClassM.sayWhich() called.")
+ ...
>>> ClassM.register(ClassA)
>>>
>>> class ClassC(ClassM, ClassB):
- >>> def sayWhich(self):
- >>> super(ClassC, self).sayWhich()
- >>>
+ ... def sayWhich(self):
+ ... super(ClassC, self).sayWhich()
+ ...
>>> c = ClassC()
>>> c.sayWhich()
- ClassM.saywhich() called.
+ ClassM.sayWhich() called.
>>> c.doSuperThing()
- <super: <class 'ClassA'>, NULL>
+ <super: <class 'ClassB'>, <ClassC object>>
>>> c.doThing()
ClassA is doing a thing.
>>> c.doOtherThing()
diff --git a/test/email_helpers.py b/test/email_helpers.py
index 14c86f4..8d7dd49 100644
--- a/test/email_helpers.py
+++ b/test/email_helpers.py
@@ -18,7 +18,8 @@ from bridgedb.email.distributor import IgnoreEmail
from bridgedb.email.distributor import TooSoonEmail
from bridgedb.email.server import MailServerContext
from bridgedb.schedule import Unscheduled
-from bridgedb.test import util
+
+from . import util
EMAIL_DIST = True
diff --git a/test/https_helpers.py b/test/https_helpers.py
index e2c94ba..3fb4887 100644
--- a/test/https_helpers.py
+++ b/test/https_helpers.py
@@ -15,9 +15,10 @@ import io
from twisted.web.test import requesthelper
-from bridgedb.test import util
from bridgedb.persistent import Conf
+from . import util
+
SERVER_PUBLIC_FQDN = 'bridges.torproject.org'
SERVER_PUBLIC_EXTERNAL_IP = '38.229.72.19'
diff --git a/test/legacy_Tests.py b/test/legacy_Tests.py
index 40f7ae4..22b2e13 100644
--- a/test/legacy_Tests.py
+++ b/test/legacy_Tests.py
@@ -30,19 +30,21 @@ from bridgedb.email.distributor import EmailDistributor
from bridgedb.email.distributor import IgnoreEmail
from bridgedb.email.distributor import TooSoonEmail
from bridgedb.parse import addr
-from bridgedb.test.util import bracketIPv6
-from bridgedb.test.util import randomIP
-from bridgedb.test.util import randomIPv4
-from bridgedb.test.util import randomIPv6
-from bridgedb.test.util import randomIPString
-from bridgedb.test.util import randomIPv4String
-from bridgedb.test.util import randomIPv6String
-from bridgedb.test.util import randomPort
-from bridgedb.test.util import randomValidIPv6
+
+from .util import bracketIPv6
+from .util import randomIP
+from .util import randomIPv4
+from .util import randomIPv6
+from .util import randomIPString
+from .util import randomIPv4String
+from .util import randomIPv6String
+from .util import randomPort
+from .util import randomValidIPv6
from math import log
warnings.filterwarnings('ignore', '.*tmpnam.*')
+warnings.filterwarnings('ignore', '.*Config.*')
def randomPortSpec():
diff --git a/test/test_Tests.py b/test/test_Tests.py
index 84c3f8b..9209245 100644
--- a/test/test_Tests.py
+++ b/test/test_Tests.py
@@ -4,13 +4,13 @@
#
# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis at torproject.org>
# please also see AUTHORS file
-# :copyright: (c) 2013, Isis Lovecruft
-# (c) 2007-2013, The Tor Project, Inc.
-# (c) 2007-2013, all entities within the AUTHORS file
+# :copyright: (c) 2013-2015, Isis Lovecruft
+# (c) 2007-2015, The Tor Project, Inc.
+# (c) 2007-2015, all entities within the AUTHORS file
# :license: 3-Clause BSD, see LICENSE for licensing information
-"""Class wrappers to adapt BridgeDB old unittests in :mod:`bridgedb.Tests`
-(now kept in :mod:`bridgedb.test.legacy_Tests`) to be compatible with the
+"""Class wrappers to adapt BridgeDB old unittests in ``bridgedb.Tests``
+(now kept in ``test/legacy_Tests``) to be compatible with the
newer :api:`twisted.trial` unittests in this directory.
"""
@@ -22,16 +22,17 @@ import doctest
import glob
import logging
import os
-import warnings
from twisted.python import monkey
from twisted.trial import unittest
-from bridgedb.test import legacy_Tests as Tests
-from bridgedb.test import deprecated
+from . import legacy_Tests as Tests
+from . import deprecated
+
+
+logging.disable(50)
-warnings.filterwarnings('ignore', module="bridgedb\.test\.legacy_Tests")
pyunit = __import__('unittest')
@@ -64,16 +65,16 @@ def generateTrialAdaptedDoctestsSuite():
def monkeypatchTests():
"""Monkeypatch the old unittests, replacing new, refactored code with their
- original equivalents from :mod:`bridgedb.test.deprecated`.
+ original equivalents from :mod:`deprecated`.
The first patch replaces the newer parsing function,
:func:`~bridgedb.parse.networkstatus.parseALine`, with the older,
- :func:`deprecated one <bridgedb.test.deprecated.parseORAddressLine>` (the
+ :func:`deprecated one <deprecated.parseORAddressLine>` (the
old function was previously located at
``bridgedb.Bridges.parseORAddressLine``).
The second patch replaces the new :class:`~bridgedb.parse.addr.PortList`,
- with the :class:`older one <bridgedb.test.deprecated.PortList>` (which
+ with the :class:`older one <deprecated.PortList>` (which
was previously located at ``bridgedb.Bridges.PortList``).
The third, forth, and fifth monkeypatches add some module-level attributes
@@ -81,7 +82,7 @@ def monkeypatchTests():
:rtype: :api:`~twisted.python.monkey.MonkeyPatcher`
:returns: A :api:`~twisted.python.monkey.MonkeyPatcher`, preloaded with
- patches from :mod:`bridgedb.test.deprecated`.
+ patches from :mod:`deprecated`.
"""
patcher = monkey.MonkeyPatcher()
patcher.addPatch(Tests.bridgedb.Bridges, 'PluggableTransport',
@@ -189,14 +190,14 @@ class DynamicTestCaseMeta(type):
class OldUnittests(unittest.TestCase):
- """A wrapper around :mod:`bridgedb.Tests` to produce :api:`~twisted.trial`
+ """A wrapper around :mod:`legacy_Tests` to produce :api:`~twisted.trial`
compatible output.
Generates a :api:`twisted.trial.unittest.TestCase` containing a
- test for each of the individual tests in :mod:`bridgedb.Tests`.
+ test for each of the individual tests in :mod:`legacy_Tests`.
Each test in this :api:`~twisted.trial.unittest.TestCase`` is dynamically
- generated from one of the old unittests in :mod:`bridgedb.Tests`. Then,
+ generated from one of the old unittests in :mod:`legacy_Tests`. Then,
the class is wrapped to cause the results reporting mechanisms to be
:api:`~twisted.trial` compatible.
@@ -209,13 +210,13 @@ class OldUnittests(unittest.TestCase):
class MonkeypatchedOldUnittests(unittest.TestCase):
- """A wrapper around :mod:`bridgedb.Tests` to produce :api:`~twisted.trial`
+ """A wrapper around :mod:`legacy_Tests` to produce :api:`~twisted.trial`
compatible output.
For each test in this ``TestCase``, one of the old unittests in
bridgedb/Tests.py is run. For all of the tests, some functions and classes
are :api:`twisted.python.monkey.MonkeyPatcher.patch`ed with old,
- deprecated code from :mod:`bridgedb.test.deprecated` to ensure that any
+ deprecated code from :mod:`deprecated` to ensure that any
new code has not caused any regressions.
"""
__metaclass__ = DynamicTestCaseMeta
diff --git a/test/test_bridgedb.py b/test/test_bridgedb.py
index 70c71f0..00c231b 100644
--- a/test/test_bridgedb.py
+++ b/test/test_bridgedb.py
@@ -21,8 +21,8 @@ from twisted.trial import unittest
from twisted.trial.unittest import FailTest
from twisted.trial.unittest import SkipTest
-from bridgedb.test.util import processExists
-from bridgedb.test.util import getBridgeDBPID
+from .util import processExists
+from .util import getBridgeDBPID
class BridgeDBCliTest(unittest.TestCase):
diff --git a/test/test_bridges.py b/test/test_bridges.py
index db662ae..9448e3f 100644
--- a/test/test_bridges.py
+++ b/test/test_bridges.py
@@ -148,10 +148,10 @@ class BridgeIntegrationTests(unittest.TestCase):
.. data: OldTest (enum)
These tests were refactored from the old tests for
- :class:`~bridgedb.test.deprecated.Bridge`, which lived in
+ ``deprecated.Bridge`, which lived in
``lib/bridgedb/test/test_Bridges.py``. For the translations from the old
- tests in ``bridgedb.test.test_Bridges.BridgeClassTest`` to their new
- equivalents here in ``bridgedb.test.test_bridges.BridgeIntegrationTests``,
+ tests in ``test_Bridges.BridgeClassTest`` to their new
+ equivalents here in ``test_bridges.BridgeIntegrationTests``,
which should test for the same things as their old equivalents, see the
following table:
diff --git a/test/test_crypto.py b/test/test_crypto.py
index 3264ace..5220a58 100644
--- a/test/test_crypto.py
+++ b/test/test_crypto.py
@@ -33,8 +33,9 @@ from twisted.web.test import test_agent as txtagent
from bridgedb import crypto
from bridgedb import txrecaptcha
from bridgedb.persistent import Conf
-from bridgedb.test.util import fileCheckDecorator
-from bridgedb.test.email_helpers import _createConfig
+
+from .util import fileCheckDecorator
+from .email_helpers import _createConfig
logging.disable(50)
diff --git a/test/test_email_autoresponder.py b/test/test_email_autoresponder.py
index 98302ca..77fb77a 100644
--- a/test/test_email_autoresponder.py
+++ b/test/test_email_autoresponder.py
@@ -26,9 +26,10 @@ from twisted.test import proto_helpers
from bridgedb.email import autoresponder
from bridgedb.email.server import SMTPMessage
from bridgedb.email.distributor import TooSoonEmail
-from bridgedb.test.email_helpers import _createConfig
-from bridgedb.test.email_helpers import _createMailServerContext
-from bridgedb.test.email_helpers import DummyEmailDistributorWithState
+
+from .email_helpers import _createConfig
+from .email_helpers import _createMailServerContext
+from .email_helpers import DummyEmailDistributorWithState
class CreateResponseBodyTests(unittest.TestCase):
diff --git a/test/test_email_distributor.py b/test/test_email_distributor.py
index b4d88b2..f204d57 100644
--- a/test/test_email_distributor.py
+++ b/test/test_email_distributor.py
@@ -28,7 +28,8 @@ from bridgedb.email.request import EmailBridgeRequest
from bridgedb.parse.addr import BadEmail
from bridgedb.parse.addr import UnsupportedDomain
from bridgedb.parse.addr import normalizeEmail
-from bridgedb.test.util import generateFakeBridges
+
+from .util import generateFakeBridges
logging.disable(50)
diff --git a/test/test_email_server.py b/test/test_email_server.py
index 9c4fabb..3a3d62d 100644
--- a/test/test_email_server.py
+++ b/test/test_email_server.py
@@ -36,9 +36,10 @@ from bridgedb.email.distributor import EmailDistributor
from bridgedb.email.distributor import TooSoonEmail
from bridgedb.parse.addr import BadEmail
from bridgedb.schedule import Unscheduled
-from bridgedb.test import util
-from bridgedb.test.email_helpers import _createConfig
-from bridgedb.test.email_helpers import _createMailServerContext
+
+from . import util
+from .email_helpers import _createConfig
+from .email_helpers import _createMailServerContext
class SMTPMessageTests(unittest.TestCase):
diff --git a/test/test_https.py b/test/test_https.py
index 1e0c778..8a5754f 100644
--- a/test/test_https.py
+++ b/test/test_https.py
@@ -35,8 +35,8 @@ from twisted.trial import unittest
from twisted.trial.unittest import FailTest
from twisted.trial.unittest import SkipTest
-from bridgedb.test.util import processExists
-from bridgedb.test.util import getBridgeDBPID
+from .util import processExists
+from .util import getBridgeDBPID
HTTP_ROOT = 'http://127.0.0.1:6788'
CAPTCHA_RESPONSE = 'Tvx74Pmy'
diff --git a/test/test_https_distributor.py b/test/test_https_distributor.py
index 83f2503..3c1416d 100644
--- a/test/test_https_distributor.py
+++ b/test/test_https_distributor.py
@@ -26,9 +26,10 @@ from bridgedb.filters import byIPv6
from bridgedb.https import distributor
from bridgedb.https.request import HTTPSBridgeRequest
from bridgedb.proxy import ProxySet
-from bridgedb.test.util import randomValidIPv4String
-from bridgedb.test.util import generateFakeBridges
-from bridgedb.test.https_helpers import DummyRequest
+
+from .util import randomValidIPv4String
+from .util import generateFakeBridges
+from .https_helpers import DummyRequest
logging.disable(50)
diff --git a/test/test_https_server.py b/test/test_https_server.py
index e782135..708f7e3 100644
--- a/test/test_https_server.py
+++ b/test/test_https_server.py
@@ -29,11 +29,12 @@ from twisted.web.test import requesthelper
from bridgedb.https import server
from bridgedb.schedule import ScheduledInterval
-from bridgedb.test.https_helpers import _createConfig
-from bridgedb.test.https_helpers import DummyRequest
-from bridgedb.test.https_helpers import DummyHTTPSDistributor
-from bridgedb.test.util import DummyBridge
-from bridgedb.test.util import DummyMaliciousBridge
+
+from .https_helpers import _createConfig
+from .https_helpers import DummyRequest
+from .https_helpers import DummyHTTPSDistributor
+from .util import DummyBridge
+from .util import DummyMaliciousBridge
# For additional logger output for debugging, comment out the following:
diff --git a/test/test_parse_descriptors.py b/test/test_parse_descriptors.py
index dd6d146..5104ccd 100644
--- a/test/test_parse_descriptors.py
+++ b/test/test_parse_descriptors.py
@@ -33,7 +33,7 @@ except (ImportError, NameError), error:
else:
HAS_STEM = True
-from bridgedb.test.util import Benchmarker
+from .util import Benchmarker
BRIDGE_NETWORKSTATUS_0 = '''\
diff --git a/test/test_smtp.py b/test/test_smtp.py
index de443b3..0ac4ada 100644
--- a/test/test_smtp.py
+++ b/test/test_smtp.py
@@ -15,8 +15,8 @@ from twisted.trial import unittest
from twisted.trial.unittest import FailTest
from twisted.trial.unittest import SkipTest
-from bridgedb.test.util import processExists
-from bridgedb.test.util import getBridgeDBPID
+from .util import processExists
+from .util import getBridgeDBPID
# ------------- SMTP Client Config
SMTP_DEBUG_LEVEL = 0 # set to 1 to see SMTP message exchange
diff --git a/test/test_translations.py b/test/test_translations.py
index 48229c6..c1f0c8c 100644
--- a/test/test_translations.py
+++ b/test/test_translations.py
@@ -11,7 +11,7 @@
from twisted.trial import unittest
from bridgedb import translations
-from bridgedb.test.test_https_server import DummyRequest
+from .https_helpers import DummyRequest
REALISH_HEADERS = {
diff --git a/test/util.py b/test/util.py
index 0f1e0f9..bd8227d 100644
--- a/test/util.py
+++ b/test/util.py
@@ -4,12 +4,12 @@
#
# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis at torproject.org>
# please also see AUTHORS file
-# :copyright: (c) 2013, Isis Lovecruft
-# (c) 2007-2013, The Tor Project, Inc.
-# (c) 2007-2013, all entities within the AUTHORS file
+# :copyright: (c) 2013-2015, Isis Lovecruft
+# (c) 2007-2015, The Tor Project, Inc.
+# (c) 2007-2015, all entities within the AUTHORS file
# :license: 3-Clause BSD, see LICENSE for licensing information
-"""Unittests utilitys the `bridgedb.test` package."""
+"""Unittest utilities."""
from __future__ import print_function
from __future__ import unicode_literals
More information about the tor-commits
mailing list