diff --git a/src/twisted/names/test/test_hosts.py b/src/twisted/names/test/test_hosts.py index 96f4d33ea85..39331e124dc 100644 --- a/src/twisted/names/test/test_hosts.py +++ b/src/twisted/names/test/test_hosts.py @@ -7,7 +7,7 @@ from __future__ import division, absolute_import -from twisted.trial.unittest import TestCase +from twisted.trial.unittest import SynchronousTestCase from twisted.python.filepath import FilePath from twisted.internet.defer import gatherResults @@ -22,7 +22,7 @@ def path(self): -class SearchHostsFileTests(TestCase, GoodTempPathMixin): +class SearchHostsFileTests(SynchronousTestCase, GoodTempPathMixin): """ Tests for L{searchFileFor}, a helper which finds the first address for a particular hostname in a I{hosts(5)}-style file. @@ -81,7 +81,7 @@ def test_searchFileForAliases(self): -class SearchHostsFileForAllTests(TestCase, GoodTempPathMixin): +class SearchHostsFileForAllTests(SynchronousTestCase, GoodTempPathMixin): """ Tests for L{searchFileForAll}, a helper which finds all addresses for a particular hostname in a I{hosts(5)}-style file. @@ -121,7 +121,7 @@ def test_readError(self): -class HostsTests(TestCase, GoodTempPathMixin): +class HostsTests(SynchronousTestCase, GoodTempPathMixin): """ Tests for the I{hosts(5)}-based L{twisted.names.hosts.Resolver}. """ @@ -162,7 +162,7 @@ def test_getHostByName(self): ] ds = [self.resolver.getHostByName(n).addCallback(self.assertEqual, ip) for n, ip in data] - return gatherResults(ds) + self.successResultOf(gatherResults(ds)) def test_lookupAddress(self): @@ -171,16 +171,13 @@ def test_lookupAddress(self): records from the hosts file. """ d = self.resolver.lookupAddress(b'multiple') - def resolved(results): - answers, authority, additional = results - self.assertEqual( - (RRHeader(b"multiple", A, IN, self.ttl, - Record_A("1.1.1.3", self.ttl)), - RRHeader(b"multiple", A, IN, self.ttl, - Record_A("1.1.1.4", self.ttl))), - answers) - d.addCallback(resolved) - return d + answers, authority, additional = self.successResultOf(d) + self.assertEqual( + (RRHeader(b"multiple", A, IN, self.ttl, + Record_A("1.1.1.3", self.ttl)), + RRHeader(b"multiple", A, IN, self.ttl, + Record_A("1.1.1.4", self.ttl))), + answers) def test_lookupIPV6Address(self): @@ -189,16 +186,13 @@ def test_lookupIPV6Address(self): with AAAA records from the hosts file. """ d = self.resolver.lookupIPV6Address(b'ip6-multiple') - def resolved(results): - answers, authority, additional = results - self.assertEqual( - (RRHeader(b"ip6-multiple", AAAA, IN, self.ttl, - Record_AAAA("::3", self.ttl)), - RRHeader(b"ip6-multiple", AAAA, IN, self.ttl, - Record_AAAA("::4", self.ttl))), - answers) - d.addCallback(resolved) - return d + answers, authority, additional = self.successResultOf(d) + self.assertEqual( + (RRHeader(b"ip6-multiple", AAAA, IN, self.ttl, + Record_AAAA("::3", self.ttl)), + RRHeader(b"ip6-multiple", AAAA, IN, self.ttl, + Record_AAAA("::4", self.ttl))), + answers) def test_lookupAllRecords(self): @@ -207,26 +201,26 @@ def test_lookupAllRecords(self): with A records from the hosts file. """ d = self.resolver.lookupAllRecords(b'mixed') - def resolved(results): - answers, authority, additional = results - self.assertEqual( - (RRHeader(b"mixed", A, IN, self.ttl, - Record_A("1.1.1.2", self.ttl)),), - answers) - d.addCallback(resolved) - return d + answers, authority, additional = self.successResultOf(d) + self.assertEqual( + (RRHeader(b"mixed", A, IN, self.ttl, + Record_A("1.1.1.2", self.ttl)),), + answers) def test_notImplemented(self): - return self.assertFailure(self.resolver.lookupMailExchange(b'EXAMPLE'), - NotImplementedError) + """ + L{hosts.Resolver} fails with L{NotImplementedError} for L{IResolver} + methods it doesn't implement. + """ + self.failureResultOf(self.resolver.lookupMailExchange(b'EXAMPLE'), + NotImplementedError) def test_query(self): d = self.resolver.query(Query(b'EXAMPLE')) - d.addCallback(lambda x: self.assertEqual(x[0][0].payload.dottedQuad(), - '1.1.1.1')) - return d + [answer], authority, additional = self.successResultOf(d) + self.assertEqual(answer.payload.dottedQuad(), '1.1.1.1') def test_lookupAddressNotFound(self): @@ -235,8 +229,8 @@ def test_lookupAddressNotFound(self): L{dns.DomainError} if the name passed in has no addresses in the hosts file. """ - return self.assertFailure(self.resolver.lookupAddress(b'foueoa'), - DomainError) + self.failureResultOf(self.resolver.lookupAddress(b'foueoa'), + DomainError) def test_lookupIPV6AddressNotFound(self): @@ -244,8 +238,8 @@ def test_lookupIPV6AddressNotFound(self): Like L{test_lookupAddressNotFound}, but for L{hosts.Resolver.lookupIPV6Address}. """ - return self.assertFailure(self.resolver.lookupIPV6Address(b'foueoa'), - DomainError) + self.failureResultOf(self.resolver.lookupIPV6Address(b'foueoa'), + DomainError) def test_lookupAllRecordsNotFound(self): @@ -253,5 +247,5 @@ def test_lookupAllRecordsNotFound(self): Like L{test_lookupAddressNotFound}, but for L{hosts.Resolver.lookupAllRecords}. """ - return self.assertFailure(self.resolver.lookupAllRecords(b'foueoa'), - DomainError) + self.failureResultOf(self.resolver.lookupAllRecords(b'foueoa'), + DomainError)