Miscellaneous cleanup in discover.py

Remove some unused variables.

Remove a couple of unused parameters from private method
EndpointData._run_discovery.

Fix some formatting issues to reclaim a line or two, or because my IDE
flags them.

Change-Id: Idcc1f1e4dc6068125ea30ce0ab482a99a9e0b1cc
This commit is contained in:
Eric Fried 2017-07-10 15:12:17 -05:00
parent d6449772ba
commit 7293a7b39f
2 changed files with 15 additions and 20 deletions

View File

@ -116,10 +116,9 @@ def normalize_version_number(version):
def _normalize_version_args(version, min_version, max_version):
if version and (min_version or max_version):
raise ValueError(
"version is mutually exclusive with min_version and"
" max_version")
if min_version == 'latest' and max_version not in (
None, 'latest'):
"version is mutually exclusive with min_version and max_version")
if min_version == 'latest' and max_version not in (None, 'latest'):
raise ValueError(
"min_version is 'latest' and max_version is {max_version}"
" but is only allowed to be 'latest' or None".format(
@ -636,9 +635,8 @@ class EndpointData(object):
self._run_discovery(
session=session, cache=cache,
version=version, min_version=min_version,
max_version=max_version,
match_url=match_url, project_id=project_id,
allow_version_hack=allow_version_hack, allow=allow,
max_version=max_version, project_id=project_id,
allow_version_hack=allow_version_hack,
discover_versions=discover_versions)
if not self._disc:
return
@ -690,9 +688,8 @@ class EndpointData(object):
@positional(1)
def _run_discovery(self, session, cache, version, min_version,
max_version, match_url, project_id,
allow_version_hack, allow, discover_versions):
vers_url = None
max_version, project_id,
allow_version_hack, discover_versions):
tried = set()
for vers_url in self._get_discovery_url_choices(
@ -771,13 +768,12 @@ class EndpointData(object):
# Peek to see if -2 is a version. If so, -1 is a project_id,
# even if we don't know that at this point in the call stack
try:
url_version = normalize_version_number(url_parts[-2])
normalize_version_number(url_parts[-2])
self._saved_project_id = url_parts.pop()
except TypeError:
pass
catalog_discovery = versioned_discovery = None
high_match = exact_match = None
# Next, check to see if the url indicates a version and if that
# version either matches our version request or is withing the
@ -797,11 +793,11 @@ class EndpointData(object):
else:
is_between = version_between(
min_version, max_version, url_version)
exact_match = (version and version != 'latest'
and version_match(version, url_version))
high_match = (is_between and max_version
and max_version != 'latest' and version_match(
max_version, url_version))
exact_match = (version and version != 'latest' and
version_match(version, url_version))
high_match = (is_between and max_version and
max_version != 'latest' and
version_match(max_version, url_version))
if exact_match or is_between:
self._catalog_matches_version = True

View File

@ -690,9 +690,8 @@ class EndpointDataTests(utils.TestCase):
epd = discover.EndpointData()
epd._run_discovery(
session='sess', cache='cache', version='vers', min_version='min',
max_version='max', match_url='match', project_id='projid',
allow_version_hack='allow_hack', allow='allow',
discover_versions='disc_vers')
max_version='max', project_id='projid',
allow_version_hack='allow_hack', discover_versions='disc_vers')
# Only one call with 'url1'
self.assertEqual(3, mock_get_disc.call_count)
mock_get_disc.assert_has_calls(