[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] Replace assertItemsEqual with assertCountEqual
commit 66c0f8bd9356a8e6387557cbee284aa011bb606c
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Jan 10 13:47:19 2020 -0800
Replace assertItemsEqual with assertCountEqual
I really dislike the new method name, but cest la vi. According to the
following they're the same...
https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertItemsEqual
This changes the test results as follows...
before: FAILED (skips=1, failures=8, errors=53, successes=250)
after: FAILED (skips=1, failures=8, errors=49, successes=254)
---
bridgedb/test/test_bridges.py | 64 ++++++++++++-------------
bridgedb/test/test_distributors_moat_request.py | 2 +-
bridgedb/test/test_distributors_moat_server.py | 4 +-
bridgedb/test/test_https_distributor.py | 2 +-
bridgedb/test/test_https_request.py | 2 +-
bridgedb/test/test_main.py | 2 +-
bridgedb/test/test_persistentSaveAndLoad.py | 3 +-
bridgedb/test/test_proxy.py | 12 ++---
8 files changed, 45 insertions(+), 46 deletions(-)
diff --git a/bridgedb/test/test_bridges.py b/bridgedb/test/test_bridges.py
index cc1680e..f2c2876 100644
--- a/bridgedb/test/test_bridges.py
+++ b/bridgedb/test/test_bridges.py
@@ -506,7 +506,7 @@ class PluggableTransportTests(unittest.TestCase):
args = pt._parseArgumentsIntoDict(["sharedsecret=foobar",
"publickey=1234"])
self.assertIsInstance(args, dict)
- self.assertItemsEqual(args, {"sharedsecret": "foobar",
+ self.assertCountEqual(args, {"sharedsecret": "foobar",
"publickey": "1234"})
def test_PluggableTransport_parseArgumentsIntoDict_valid_list_multi(self):
@@ -517,7 +517,7 @@ class PluggableTransportTests(unittest.TestCase):
args = pt._parseArgumentsIntoDict(["sharedsecret=foobar,password=baz",
"publickey=1234"])
self.assertIsInstance(args, dict)
- self.assertItemsEqual(args, {"sharedsecret": "foobar",
+ self.assertCountEqual(args, {"sharedsecret": "foobar",
"password": "baz",
"publickey": "1234"})
@@ -528,7 +528,7 @@ class PluggableTransportTests(unittest.TestCase):
pt = bridges.PluggableTransport()
args = pt._parseArgumentsIntoDict(
["sharedsecret=foobar,password,publickey=1234"])
- self.assertItemsEqual(args, {"sharedsecret": "foobar",
+ self.assertCountEqual(args, {"sharedsecret": "foobar",
"publickey": "1234"})
def test_PluggableTransport_checkArguments_scramblesuit_missing_password(self):
@@ -1013,11 +1013,11 @@ class BridgeTests(unittest.TestCase):
"""
self.bridge.address = '1.1.1.1'
self.bridge.orPort = 443
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
def test_Bridge_allVanillaAddresses_idempotency_others(self):
@@ -1027,17 +1027,17 @@ class BridgeTests(unittest.TestCase):
"""
self.bridge.address = '1.1.1.1'
self.bridge.orPort = 443
- self.assertItemsEqual(self.bridge.orAddresses, [])
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
- self.assertItemsEqual(self.bridge.orAddresses, [])
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
- self.assertItemsEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.orAddresses, [])
def test_Bridge_allVanillaAddresses_reentrancy_all(self):
"""Bridge.allVanillaAddresses should be reentrant, i.e. updating the
@@ -1045,34 +1045,34 @@ class BridgeTests(unittest.TestCase):
returned by allVanillaAddresses.
"""
self.bridge.address = '1.1.1.1'
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), None, 4)])
self.assertEqual(self.bridge.address, ipaddr.IPv4Address('1.1.1.1'))
self.assertEqual(self.bridge.orPort, None)
- self.assertItemsEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.orAddresses, [])
self.bridge.orPort = 443
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
self.assertEqual(self.bridge.address, ipaddr.IPv4Address('1.1.1.1'))
self.assertEqual(self.bridge.orPort, 443)
- self.assertItemsEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.orAddresses, [])
self.bridge.address = '2.2.2.2'
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('2.2.2.2'), 443, 4)])
self.assertEqual(self.bridge.address, ipaddr.IPv4Address('2.2.2.2'))
self.assertEqual(self.bridge.orPort, 443)
- self.assertItemsEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.orAddresses, [])
self.bridge.orAddresses.append(
(ipaddr.IPv6Address('200::6ffb:11bb:a129'), 4443, 6))
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('2.2.2.2'), 443, 4),
(ipaddr.IPv6Address('200::6ffb:11bb:a129'), 4443, 6)])
self.assertEqual(self.bridge.address, ipaddr.IPv4Address('2.2.2.2'))
self.assertEqual(self.bridge.orPort, 443)
- self.assertItemsEqual(self.bridge.orAddresses,
+ self.assertCountEqual(self.bridge.orAddresses,
[(ipaddr.IPv6Address('200::6ffb:11bb:a129'), 4443, 6)])
def test_Bridge_allVanillaAddresses_reentrancy_orPort(self):
@@ -1081,15 +1081,15 @@ class BridgeTests(unittest.TestCase):
set, it should return the orPort.
"""
self.bridge.address = '1.1.1.1'
- self.assertItemsEqual(self.bridge.orAddresses, [])
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), None, 4)])
- self.assertItemsEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.orAddresses, [])
self.bridge.orPort = 443
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
- self.assertItemsEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.orAddresses, [])
def test_Bridge_allVanillaAddresses_reentrancy_address(self):
"""Calling Bridge.allVanillaAddresses before Bridge.address is set
@@ -1097,10 +1097,10 @@ class BridgeTests(unittest.TestCase):
is set, it should return the address.
"""
self.bridge.orPort = 443
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(None, 443, 4)])
self.bridge.address = '1.1.1.1'
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
def test_Bridge_allVanillaAddresses_reentrancy_orAddresses(self):
@@ -1109,14 +1109,14 @@ class BridgeTests(unittest.TestCase):
"""
self.bridge.address = '1.1.1.1'
self.bridge.orPort = 443
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
- self.assertItemsEqual(self.bridge.orAddresses, [])
+ self.assertCountEqual(self.bridge.orAddresses, [])
self.bridge.orAddresses.append(
(ipaddr.IPv4Address('2.2.2.2'), 4443, 4))
- self.assertItemsEqual(self.bridge.orAddresses,
+ self.assertCountEqual(self.bridge.orAddresses,
[(ipaddr.IPv4Address('2.2.2.2'), 4443, 4)])
- self.assertItemsEqual(self.bridge.allVanillaAddresses,
+ self.assertCountEqual(self.bridge.allVanillaAddresses,
[(ipaddr.IPv4Address('2.2.2.2'), 4443, 4),
(ipaddr.IPv4Address('1.1.1.1'), 443, 4)])
diff --git a/bridgedb/test/test_distributors_moat_request.py b/bridgedb/test/test_distributors_moat_request.py
index 555b3eb..a5c22e0 100644
--- a/bridgedb/test/test_distributors_moat_request.py
+++ b/bridgedb/test/test_distributors_moat_request.py
@@ -30,7 +30,7 @@ class MoatBridgeRequest(unittest.TestCase):
self.bridgeRequest.withoutBlockInCountry(data)
self.bridgeRequest.generateFilters()
- self.assertItemsEqual(['byTransportNotBlockedIn(vanilla,us,4)',
+ self.assertCountEqual(['byTransportNotBlockedIn(vanilla,us,4)',
'byTransportNotBlockedIn(vanilla,ir,4)',
'byTransportNotBlockedIn(vanilla,sy,4)',
'byProbingResistance(vanilla,4)'],
diff --git a/bridgedb/test/test_distributors_moat_server.py b/bridgedb/test/test_distributors_moat_server.py
index 33069ef..222518d 100644
--- a/bridgedb/test/test_distributors_moat_server.py
+++ b/bridgedb/test/test_distributors_moat_server.py
@@ -140,7 +140,7 @@ class MiscellaneousTests(unittest.TestCase):
"""
server.setSupportedTransports(self.config.SUPPORTED_TRANSPORTS)
- self.assertItemsEqual(server.getSupportedTransports(),
+ self.assertCountEqual(server.getSupportedTransports(),
["obfs4", "obfs3", "scramblesuit", "fte", "vanilla"])
@@ -553,7 +553,7 @@ class CaptchaFetchResourceTests(unittest.TestCase):
def test_getPreferredTransports_unknown_transport(self):
preferred = self.resource.getPreferredTransports(['dinosaur'])
- self.assertItemsEqual(preferred,
+ self.assertCountEqual(preferred,
['obfs4', 'obfs3', 'fte', 'scramblesuit', 'vanilla'])
def assert_data_is_ok(self, decoded):
diff --git a/bridgedb/test/test_https_distributor.py b/bridgedb/test/test_https_distributor.py
index dd56785..a96238d 100644
--- a/bridgedb/test/test_https_distributor.py
+++ b/bridgedb/test/test_https_distributor.py
@@ -322,7 +322,7 @@ class HTTPSDistributorTests(unittest.TestCase):
for i in range(5):
responses[i] = dist.getBridges(bridgeRequest, 1)
for i in range(4):
- self.assertItemsEqual(responses[i], responses[i+1])
+ self.assertCountEqual(responses[i], responses[i+1])
def test_HTTPSDistributor_getBridges_with_BridgeRingParameters(self):
param = BridgeRingParameters(needPorts=[(443, 1)])
diff --git a/bridgedb/test/test_https_request.py b/bridgedb/test/test_https_request.py
index 2ea3fe6..81f8e0b 100644
--- a/bridgedb/test/test_https_request.py
+++ b/bridgedb/test/test_https_request.py
@@ -64,7 +64,7 @@ class HTTPSBridgeRequestTests(unittest.TestCase):
self.request = request.HTTPSBridgeRequest(addClientCountryCode=False)
self.request.client = '5.5.5.5'
self.request.withoutBlockInCountry(httprequest)
- self.assertItemsEqual(['nl'], self.request.notBlockedIn)
+ self.assertCountEqual(['nl'], self.request.notBlockedIn)
def test_HTTPSBridgeRequest_withoutBlockInCountry_bad_params(self):
"""HTTPSBridgeRequest.withoutBlockInCountry() should stop processing if
diff --git a/bridgedb/test/test_main.py b/bridgedb/test/test_main.py
index 52d98a2..87b4a81 100644
--- a/bridgedb/test/test_main.py
+++ b/bridgedb/test/test_main.py
@@ -323,7 +323,7 @@ class BridgedbTests(unittest.TestCase):
# a MoatDistributor ring, and an UnallocatedHolder ring:
self.assertEqual(len(hashring.ringsByName.keys()), 4)
self.assertGreater(len(httpsDist.proxies), 0)
- self.assertItemsEqual(exitRelays, httpsDist.proxies)
+ self.assertCountEqual(exitRelays, httpsDist.proxies)
def test_main_createBridgeRings_no_https_dist(self):
"""When HTTPS_DIST=False, main.createBridgeRings() should add only
diff --git a/bridgedb/test/test_persistentSaveAndLoad.py b/bridgedb/test/test_persistentSaveAndLoad.py
index 7678948..0ebb1e2 100644
--- a/bridgedb/test/test_persistentSaveAndLoad.py
+++ b/bridgedb/test/test_persistentSaveAndLoad.py
@@ -57,8 +57,7 @@ class StateSaveAndLoadTests(unittest.TestCase):
self.assertIsInstance(loadedState, persistent.State)
self.assertNotIdentical(self.state, loadedState)
self.assertNotEqual(self.state, loadedState)
- # For some reason, twisted.trial.unittest.TestCase in Python2.6
- # doesn't have an 'assertItemsEqual' attribute...
+
self.assertEqual(self.state.__dict__.keys().sort(),
loadedState.__dict__.keys().sort())
diff --git a/bridgedb/test/test_proxy.py b/bridgedb/test/test_proxy.py
index c55e03c..74290bc 100644
--- a/bridgedb/test/test_proxy.py
+++ b/bridgedb/test/test_proxy.py
@@ -254,7 +254,7 @@ class ProxySetUnittests(unittest.TestCase):
def test_ProxySet_proxies_getter(self):
"""ProxySet.proxies should list all proxies."""
- self.assertItemsEqual(self.proxyList.proxies, set(self.proxies))
+ self.assertCountEqual(self.proxyList.proxies, set(self.proxies))
def test_ProxySet_proxies_setter(self):
"""``ProxySet.proxies = ['foo']`` should raise an ``AttributeError``."""
@@ -273,7 +273,7 @@ class ProxySetUnittests(unittest.TestCase):
def test_ProxySet_exitRelays_getter(self):
"""ProxySet.exitRelays should list all exit relays."""
self.proxyList.addExitRelays(self.moarProxies)
- self.assertItemsEqual(self.proxyList.exitRelays, set(self.moarProxies))
+ self.assertCountEqual(self.proxyList.exitRelays, set(self.moarProxies))
def test_ProxySet_exitRelays_setter(self):
"""``ProxySet.exitRelays = ['foo']`` should raise an ``AttributeError``."""
@@ -447,9 +447,9 @@ class ProxySetUnittests(unittest.TestCase):
"""
proxySetA = self.proxyList
proxySetB = proxy.ProxySet(self.moarProxies)
- self.assertItemsEqual(proxySetA.difference(proxySetB),
+ self.assertCountEqual(proxySetA.difference(proxySetB),
set(self.proxies))
- self.assertItemsEqual(proxySetB.difference(proxySetA),
+ self.assertCountEqual(proxySetB.difference(proxySetA),
set(self.moarProxies))
def test_ProxySet_firstSeen_returns_timestamp(self):
@@ -493,7 +493,7 @@ class ProxySetUnittests(unittest.TestCase):
a.extend(self.moarProxies)
a = set(a)
b = self.proxyList.intersection(set(self.moarProxies))
- self.assertItemsEqual(a, b)
+ self.assertCountEqual(a, b)
def test_ProxySet_remove(self):
"""ProxySet.remove() should subtract proxies which were already added
@@ -534,7 +534,7 @@ class ProxySetUnittests(unittest.TestCase):
proxyListA = proxy.ProxySet(self.proxies)
proxyListB = proxy.ProxySet(self.proxies)
self.assertEqual(proxyListA, proxyListB)
- self.assertItemsEqual(proxyListA, proxyListB)
+ self.assertCountEqual(proxyListA, proxyListB)
self.assertEqual(hash(proxyListA), hash(proxyListB))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits