@@ -37,80 +37,59 @@ def fake(*args, **kwargs):
37
37
38
38
39
39
@pytest .mark .skipif (aiodns is None , reason = "aiodns required" )
40
+ @pytest .mark .run_loop
40
41
def test_async_resolver_positive_lookup (loop ):
41
- @asyncio .coroutine
42
- def go ():
43
- with patch ('aiodns.DNSResolver.query' ) as mock_query :
44
- mock_query .return_value = fake_result (['127.0.0.1' ])
45
- resolver = AsyncResolver (loop = loop )
46
- real = yield from resolver .resolve ('www.python.org' )
47
- ipaddress .ip_address (real [0 ]['host' ])
48
- loop .run_until_complete (go ())
42
+ with patch ('aiodns.DNSResolver.query' ) as mock_query :
43
+ mock_query .return_value = fake_result (['127.0.0.1' ])
44
+ resolver = AsyncResolver (loop = loop )
45
+ real = yield from resolver .resolve ('www.python.org' )
46
+ ipaddress .ip_address (real [0 ]['host' ])
49
47
50
48
51
49
@pytest .mark .skipif (aiodns is None , reason = "aiodns required" )
50
+ @pytest .mark .run_loop
52
51
def test_async_resolver_multiple_replies (loop ):
53
- @asyncio .coroutine
54
- def go ():
55
- with patch ('aiodns.DNSResolver.query' ) as mock_query :
56
- ips = ['127.0.0.1' , '127.0.0.2' , '127.0.0.3' , '127.0.0.4' ]
57
- mock_query .return_value = fake_result (ips )
58
- resolver = AsyncResolver (loop = loop )
59
- real = yield from resolver .resolve ('www.google.com' )
60
- ips = [ipaddress .ip_address (x ['host' ]) for x in real ]
61
- assert len (ips ) > 3 , "Expecting multiple addresses"
62
- loop .run_until_complete (go ())
52
+ with patch ('aiodns.DNSResolver.query' ) as mock_query :
53
+ ips = ['127.0.0.1' , '127.0.0.2' , '127.0.0.3' , '127.0.0.4' ]
54
+ mock_query .return_value = fake_result (ips )
55
+ resolver = AsyncResolver (loop = loop )
56
+ real = yield from resolver .resolve ('www.google.com' )
57
+ ips = [ipaddress .ip_address (x ['host' ]) for x in real ]
58
+ assert len (ips ) > 3 , "Expecting multiple addresses"
63
59
64
60
65
61
@pytest .mark .skipif (aiodns is None , reason = "aiodns required" )
62
+ @pytest .mark .run_loop
66
63
def test_async_negative_lookup (loop ):
67
- @asyncio .coroutine
68
- def go ():
69
- with patch ('aiodns.DNSResolver.query' ) as mock_query :
70
- mock_query .side_effect = aiodns .error .DNSError ()
71
- resolver = AsyncResolver (loop = loop )
72
- try :
73
- yield from resolver .resolve ('doesnotexist.bla' )
74
- assert False , "Expecting aiodns.error.DNSError"
75
- except aiodns .error .DNSError :
76
- pass
77
-
78
- loop .run_until_complete (go ())
64
+ with patch ('aiodns.DNSResolver.query' ) as mock_query :
65
+ mock_query .side_effect = aiodns .error .DNSError ()
66
+ resolver = AsyncResolver (loop = loop )
67
+ with pytest .raises (aiodns .error .DNSError ):
68
+ yield from resolver .resolve ('doesnotexist.bla' )
79
69
80
70
71
+ @pytest .mark .run_loop
81
72
def test_default_resolver_positive_lookup (loop ):
82
- @asyncio .coroutine
83
- def go ():
84
- loop .getaddrinfo = fake_addrinfo (["127.0.0.1" ])
85
- resolver = DefaultResolver (loop = loop )
86
- real = yield from resolver .resolve ('www.python.org' )
87
- ipaddress .ip_address (real [0 ]['host' ])
88
-
89
- loop .run_until_complete (go ())
73
+ loop .getaddrinfo = fake_addrinfo (["127.0.0.1" ])
74
+ resolver = DefaultResolver (loop = loop )
75
+ real = yield from resolver .resolve ('www.python.org' )
76
+ ipaddress .ip_address (real [0 ]['host' ])
90
77
91
78
79
+ @pytest .mark .run_loop
92
80
def test_default_resolver_multiple_replies (loop ):
93
- @asyncio .coroutine
94
- def go ():
95
- ips = ['127.0.0.1' , '127.0.0.2' , '127.0.0.3' , '127.0.0.4' ]
96
- loop .getaddrinfo = fake_addrinfo (ips )
97
- resolver = DefaultResolver (loop = loop )
98
- real = yield from resolver .resolve ('www.google.com' )
99
- ips = [ipaddress .ip_address (x ['host' ]) for x in real ]
100
- assert len (ips ) > 3 , "Expecting multiple addresses"
101
- loop .run_until_complete (go ())
81
+ ips = ['127.0.0.1' , '127.0.0.2' , '127.0.0.3' , '127.0.0.4' ]
82
+ loop .getaddrinfo = fake_addrinfo (ips )
83
+ resolver = DefaultResolver (loop = loop )
84
+ real = yield from resolver .resolve ('www.google.com' )
85
+ ips = [ipaddress .ip_address (x ['host' ]) for x in real ]
86
+ assert len (ips ) > 3 , "Expecting multiple addresses"
102
87
103
88
89
+ @pytest .mark .run_loop
104
90
def test_default_negative_lookup (loop ):
105
- @asyncio .coroutine
106
- def go ():
107
- ips = []
108
- loop .getaddrinfo = fake_addrinfo (ips )
109
- resolver = DefaultResolver (loop = loop )
110
- try :
111
- yield from resolver .resolve ('doesnotexist.bla' )
112
- assert False , "Expecting socket.gaierror"
113
- except socket .gaierror :
114
- pass
115
-
116
- loop .run_until_complete (go ())
91
+ ips = []
92
+ loop .getaddrinfo = fake_addrinfo (ips )
93
+ resolver = DefaultResolver (loop = loop )
94
+ with pytest .raises (socket .gaierror ):
95
+ yield from resolver .resolve ('doesnotexist.bla' )
0 commit comments