193e2657ff
Also make flake8 happy in setup.py by adding docstrings.
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
# Copyright 2018 Canonical Ltd.
|
|
#
|
|
# 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.
|
|
|
|
"""Utilities to support running lifecycle phases."""
|
|
import importlib
|
|
import yaml
|
|
|
|
BUNDLE_DIR = "./tests/bundles/"
|
|
DEFAULT_TEST_CONFIG = "./tests/tests.yaml"
|
|
|
|
|
|
def get_charm_config(yaml_file=None):
|
|
"""Read the yaml test config file and return the resulting config.
|
|
|
|
:param yaml_file: File to be read
|
|
:type yaml_file: str
|
|
:returns: Config dictionary
|
|
:rtype: dict
|
|
"""
|
|
if not yaml_file:
|
|
yaml_file = DEFAULT_TEST_CONFIG
|
|
with open(yaml_file, 'r') as stream:
|
|
return yaml.load(stream)
|
|
|
|
|
|
def get_class(class_str):
|
|
"""Get the class represented by the given string.
|
|
|
|
For example, get_class('zaza.charms_tests.svc.TestSVCClass1')
|
|
returns zaza.charms_tests.svc.TestSVCClass1
|
|
|
|
:param class_str: Class to be returned
|
|
:type class_str: str
|
|
:returns: Test class
|
|
:rtype: class
|
|
"""
|
|
module_name = '.'.join(class_str.split('.')[:-1])
|
|
class_name = class_str.split('.')[-1]
|
|
module = importlib.import_module(module_name)
|
|
return getattr(module, class_name)
|