diff options
author | 2015-06-30 18:47:29 +0200 | |
---|---|---|
committer | 2015-06-30 18:47:29 +0200 | |
commit | b8c756ecdd7cced1db4300935484e8c83701c82e (patch) | |
tree | 87e51107d82b217ede145de9d9d59e2100725bd7 /keystone-moon/keystone/tests/unit/utils.py | |
parent | c304c773bae68fb854ed9eab8fb35c4ef17cf136 (diff) |
migrate moon code from github to opnfv
Change-Id: Ice53e368fd1114d56a75271aa9f2e598e3eba604
Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'keystone-moon/keystone/tests/unit/utils.py')
-rw-r--r-- | keystone-moon/keystone/tests/unit/utils.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/keystone-moon/keystone/tests/unit/utils.py b/keystone-moon/keystone/tests/unit/utils.py new file mode 100644 index 00000000..17d1de81 --- /dev/null +++ b/keystone-moon/keystone/tests/unit/utils.py @@ -0,0 +1,89 @@ +# 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. + +"""Useful utilities for tests.""" + +import functools +import os +import time +import uuid + +from oslo_log import log +import six +from testtools import testcase + + +LOG = log.getLogger(__name__) + +TZ = None + + +def timezone(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + tz_original = os.environ.get('TZ') + try: + if TZ: + os.environ['TZ'] = TZ + time.tzset() + return func(*args, **kwargs) + finally: + if TZ: + if tz_original: + os.environ['TZ'] = tz_original + else: + if 'TZ' in os.environ: + del os.environ['TZ'] + time.tzset() + return wrapper + + +def new_uuid(): + """Return a string UUID.""" + return uuid.uuid4().hex + + +def wip(message): + """Mark a test as work in progress. + + Based on code by Nat Pryce: + https://gist.github.com/npryce/997195#file-wip-py + + The test will always be run. If the test fails then a TestSkipped + exception is raised. If the test passes an AssertionError exception + is raised so that the developer knows they made the test pass. This + is a reminder to remove the decorator. + + :param message: a string message to help clarify why the test is + marked as a work in progress + + usage: + >>> @wip('waiting on bug #000000') + >>> def test(): + >>> pass + + """ + + def _wip(f): + @six.wraps(f) + def run_test(*args, **kwargs): + try: + f(*args, **kwargs) + except Exception: + raise testcase.TestSkipped('work in progress test failed: ' + + message) + + raise AssertionError('work in progress test passed: ' + message) + + return run_test + + return _wip |