
This patch addresses inconsistent code style and enforces it with a gate for future submissions. Separate work will be done in the future to address several of the PEP8 ignores for docstrings, and attempt to bring the tests directory to PEP8 compliance. This patch: 1. Updates .style.yapf to set the knobs desired for YAPF. 2. Updates tox.ini to allow one of the knobs to work. 3. Removes unused code from several __init__.py files. 4. Updates the YAPF version in test-requirements.txt to latest (this is needed for several knobs to work). 5. Stylistic changes to the python codebase in Pegleg. 6. Updates to tox.ini to run YAPF during PEP8 check. Change-Id: Ieaa0fdef2b601d01c875d64b840986e54df73abf
70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
# Copyright 2018 AT&T Intellectual Property. All other rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from pegleg.engine.util import definition
|
|
from tests.unit.fixtures import create_tmp_deployment_files
|
|
|
|
|
|
class TestSiteDefinitionHelpers(object):
|
|
def _test_documents_for_site(self, sitename):
|
|
documents = definition.documents_for_site(sitename)
|
|
global_documents = []
|
|
site_documents = []
|
|
|
|
for document in documents:
|
|
name = document["metadata"]["name"]
|
|
# Assert that the document is either global level or a relevant
|
|
# site document.
|
|
assert name.startswith("global") or name.startswith(sitename)
|
|
|
|
if name.startswith("global"):
|
|
global_documents.append(document)
|
|
elif name.startswith(sitename):
|
|
site_documents.append(document)
|
|
else:
|
|
raise AssertionError(
|
|
"Unexpected document retrieved by "
|
|
"`documents_for_site`: %s" % document)
|
|
|
|
# Assert that documents from both levels appear.
|
|
assert global_documents
|
|
assert site_documents
|
|
|
|
return global_documents + site_documents
|
|
|
|
def test_documents_for_site(self, create_tmp_deployment_files):
|
|
self._test_documents_for_site("cicd")
|
|
self._test_documents_for_site("lab")
|
|
|
|
def test_documents_for_each_site(self, create_tmp_deployment_files):
|
|
documents_by_site = definition.documents_for_each_site()
|
|
sort_func = lambda x: x['metadata']['name']
|
|
|
|
# Validate that both expected site documents are found.
|
|
assert 2 == len(documents_by_site)
|
|
assert "cicd" in documents_by_site
|
|
assert "lab" in documents_by_site
|
|
|
|
cicd_documents = self._test_documents_for_site("cicd")
|
|
lab_documents = self._test_documents_for_site("lab")
|
|
|
|
# Validate that each set of site documents matches the same set of
|
|
# documents returned by ``documents_for_site`` for that site.
|
|
assert (
|
|
sorted(cicd_documents, key=sort_func) == sorted(
|
|
documents_by_site["cicd"], key=sort_func))
|
|
assert (
|
|
sorted(lab_documents, key=sort_func) == sorted(
|
|
documents_by_site["lab"], key=sort_func))
|