Skip to content

Commit

Permalink
Remove dead code used only in tests (#2620)
Browse files Browse the repository at this point in the history
  • Loading branch information
socketpair committed Dec 27, 2017
1 parent 11024e1 commit 93cf93d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
10 changes: 0 additions & 10 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from http.cookies import SimpleCookie
from itertools import cycle, islice
from time import monotonic
from types import MappingProxyType

from . import hdrs, helpers
from .client_exceptions import (ClientConnectionError,
Expand Down Expand Up @@ -554,10 +553,6 @@ def __init__(self, ttl=None):
def __contains__(self, host):
return host in self._addrs

@property
def addrs(self):
return self._addrs

def add(self, host, addrs):
self._addrs[host] = addrs
self._addrs_rr[host] = cycle(addrs)
Expand Down Expand Up @@ -705,11 +700,6 @@ def use_dns_cache(self):
"""True if local DNS caching is enabled."""
return self._use_dns_cache

@property
def cached_hosts(self):
"""Read-only dict of cached DNS record."""
return MappingProxyType(self._cached_hosts.addrs)

def clear_dns_cache(self, host=None, port=None):
"""Remove specified host/port or clear all dns local cache."""
if host is not None and port is not None:
Expand Down
34 changes: 23 additions & 11 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ def test_tcp_connector_ctor(loop):

assert conn.use_dns_cache
assert conn.family == 0
assert conn.cached_hosts == {}


def test_tcp_connector_ctor_fingerprint_valid(loop):
Expand Down Expand Up @@ -1112,11 +1111,19 @@ def test_tcp_connector_clear_dns_cache(loop):
conn._cached_hosts.add(('localhost', 123), hosts)
conn._cached_hosts.add(('localhost', 124), hosts)
conn.clear_dns_cache('localhost', 123)
assert ('localhost', 123) not in conn.cached_hosts
with pytest.raises(KeyError):
conn._cached_hosts.next_addrs(('localhost', 123))

assert conn._cached_hosts.next_addrs(('localhost', 124)) == hosts

# Remove removed element is OK
conn.clear_dns_cache('localhost', 123)
assert ('localhost', 123) not in conn.cached_hosts
with pytest.raises(KeyError):
conn._cached_hosts.next_addrs(('localhost', 123))

conn.clear_dns_cache()
assert conn.cached_hosts == {}
with pytest.raises(KeyError):
conn._cached_hosts.next_addrs(('localhost', 124))


def test_tcp_connector_clear_dns_cache_bad_args(loop):
Expand Down Expand Up @@ -1925,23 +1932,28 @@ class TestDNSCacheTable:
def dns_cache_table(self):
return _DNSCacheTable()

def test_addrs(self, dns_cache_table):
def test_next_addrs_basic(self, dns_cache_table):
dns_cache_table.add('localhost', ['127.0.0.1'])
dns_cache_table.add('foo', ['127.0.0.2'])
assert dns_cache_table.addrs == {
'localhost': ['127.0.0.1'],
'foo': ['127.0.0.2']
}

addrs = dns_cache_table.next_addrs('localhost')
assert addrs == ['127.0.0.1']
addrs = dns_cache_table.next_addrs('foo')
assert addrs == ['127.0.0.2']
with pytest.raises(KeyError):
dns_cache_table.next_addrs('no-such-host')

def test_remove(self, dns_cache_table):
dns_cache_table.add('localhost', ['127.0.0.1'])
dns_cache_table.remove('localhost')
assert dns_cache_table.addrs == {}
with pytest.raises(KeyError):
dns_cache_table.next_addrs('localhost')

def test_clear(self, dns_cache_table):
dns_cache_table.add('localhost', ['127.0.0.1'])
dns_cache_table.clear()
assert dns_cache_table.addrs == {}
with pytest.raises(KeyError):
dns_cache_table.next_addrs('localhost')

def test_not_expired_ttl_None(self, dns_cache_table):
dns_cache_table.add('localhost', ['127.0.0.1'])
Expand Down

0 comments on commit 93cf93d

Please sign in to comment.