[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] Add test_Tests.monkeypatchTests() to setup regression tests.
commit 9a4c98a72cda5bbd440282123a2a4a073cadd5c8
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Fri Dec 20 02:45:47 2013 +0000
Add test_Tests.monkeypatchTests() to setup regression tests.
This function creates a `twisted.python.monkey.MonkeyPatcher` which will add
deprecated code from `bridgedb.test.deprecated` back in, so that a TestCase
class can run its tests on pre-refactored code to test for regressions.
---
lib/bridgedb/test/test_Tests.py | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/lib/bridgedb/test/test_Tests.py b/lib/bridgedb/test/test_Tests.py
index b898cc4..2532be1 100644
--- a/lib/bridgedb/test/test_Tests.py
+++ b/lib/bridgedb/test/test_Tests.py
@@ -22,9 +22,12 @@ import logging
import os
import warnings
+from twisted.python import monkey
from twisted.trial import unittest
from bridgedb import Tests
+from bridgedb.test import deprecated
+
logging.warnings.filterwarnings('ignore', module="Tests")
pyunit = __import__('unittest')
@@ -57,6 +60,36 @@ def generateTrialAdaptedDoctestsSuite():
globs=fakedGlobals))
return testSuites
+def monkeypatchTests():
+ """Monkeypatch the old unittests, replacing new, refactored code with their
+ original equivalents from :mod:`bridgedb.test.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
+ 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
+ was previously located at ``bridgedb.Bridges.PortList``).
+
+ The third, forth, and fifth monkeypatches add some module-level attributes
+ back into :mod:`bridgedb.Bridges`.
+
+ :rtype: :class:`~twisted.python.monkey.MonkeyPatcher`
+ :returns: A :class:`~twisted.python.monkey.MonkeyPatcher`, preloaded with
+ patches from :mod:`bridgedb.test.deprecated`.
+ """
+ patcher = monkey.MonkeyPatcher()
+ patcher.addPatch(Tests.networkstatus, 'parseALine',
+ deprecated.parseORAddressLine)
+ patcher.addPatch(Tests.addr, 'PortList', deprecated.PortList)
+ patcher.addPatch(Tests.bridgedb.Bridges, 'PORTSPEC_LEN', 16)
+ patcher.addPatch(Tests.bridgedb.Bridges, 're_ipv4', deprecated.re_ipv4)
+ patcher.addPatch(Tests.bridgedb.Bridges, 're_ipv6', deprecated.re_ipv6)
+ return patcher
+
class OldUnittests(unittest.TestCase):
"""A wrapper around :mod:`bridgedb.Tests` to produce :mod:`~twisted.trial`
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits