Browse Source

Create test framework for python with stestr.

Add add the first unit test for fm-rest-api/fm/fm/common/timeutils.
Add tox task for py27/35 as zuul checking and gating jobs.

Story: 2007082
Task: 38077

Change-Id: I2f259dcf2178f42546966063c0d724bc17e2a804
Signed-off-by: chenyan <yan.chen@intel.com>
changes/75/702175/12
chenyan 1 year ago
committed by SidneyAn
parent
commit
385f274a8f
11 changed files with 166 additions and 4 deletions
  1. +2
    -0
      .gitignore
  2. +24
    -0
      .zuul.yaml
  3. +5
    -0
      fm-rest-api/fm/.stestr.conf
  4. +2
    -2
      fm-rest-api/fm/fm/common/timeutils.py
  5. +14
    -0
      fm-rest-api/fm/fm/tests/__init__.py
  6. +33
    -0
      fm-rest-api/fm/fm/tests/base.py
  7. +34
    -0
      fm-rest-api/fm/fm/tests/test_common.py
  8. +10
    -1
      fm-rest-api/fm/test-requirements.txt
  9. +33
    -0
      fm-rest-api/fm/tox.ini
  10. +7
    -1
      test-requirements.txt
  11. +2
    -0
      tox.ini

+ 2
- 0
.gitignore View File

@ -22,6 +22,8 @@ develop-eggs
dist
eggs
sdist
.stestr
.ipynb_checkpoints
# Sphinx documentation
doc/build


+ 24
- 0
.zuul.yaml View File

@ -11,10 +11,14 @@
- openstack-tox-linters
- openstack-tox-pep8
- stx-fault-build
- fault-rest-api-py27
- fault-rest-api-py35
gate:
jobs:
- openstack-tox-linters
- openstack-tox-pep8
- fault-rest-api-py27
- fault-rest-api-py35
# Perform just a build
- job:
@ -48,3 +52,23 @@
fault: https://opendev.org/starlingx/fault
integ: https://opendev.org/starlingx/integ
update: https://opendev.org/starlingx/update
- job:
name: fault-rest-api-py27
parent: tox
description: |
Run py27 test for fm-rest-api
nodeset: ubuntu-xenial
vars:
tox_envlist: py27
tox_extra_args: -c fm-rest-api/fm/tox.ini
- job:
name: fault-rest-api-py35
parent: tox
description: |
Run py35 test for fm-rest-api
nodeset: ubuntu-xenial
vars:
tox_envlist: py35
tox_extra_args: -c fm-rest-api/fm/tox.ini

+ 5
- 0
fm-rest-api/fm/.stestr.conf View File

@ -0,0 +1,5 @@
[DEFAULT]
test_path=./fm/tests
top_dir=./
#parallel_class=True

+ 2
- 2
fm-rest-api/fm/fm/common/timeutils.py View File

@ -46,9 +46,9 @@ def parse_isotime(timestr):
try:
return iso8601.parse_date(timestr)
except iso8601.ParseError as e:
raise ValueError(e.message)
raise ValueError(str(e))
except TypeError as e:
raise ValueError(e.message)
raise ValueError(str(e))
def strtime(at=None, fmt=PERFECT_TIME_FORMAT):


+ 14
- 0
fm-rest-api/fm/fm/tests/__init__.py View File

@ -0,0 +1,14 @@
# Copyright 2020 Intel Corporation.
# All 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.

+ 33
- 0
fm-rest-api/fm/fm/tests/base.py View File

@ -0,0 +1,33 @@
# Copyright 2020 Intel Corporation.
# All 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.
"""Base classes for our unit tests.
Allows overriding of config for use of fakes, and some black magic for
inline callbacks.
"""
import testtools
class TestCase(testtools.TestCase):
"""Test case base class for all unit tests."""
def setUp(self):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
def tearDown(self):
super(TestCase, self).tearDown()

+ 34
- 0
fm-rest-api/fm/fm/tests/test_common.py View File

@ -0,0 +1,34 @@
# Copyright 2020 Intel Corporation.
# All 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.
import datetime
from fm.common import timeutils
from fm.tests import base
class FaultTimeUtilsTestCase(base.TestCase):
def test_isotime(self):
isotimestr = timeutils.isotime()
isotime = timeutils.parse_isotime(isotimestr)
self.assertTrue(isinstance(isotime, datetime.datetime))
isotimestr = timeutils.isotime(subsecond=True)
isotime = timeutils.parse_isotime(isotimestr)
self.assertTrue(isinstance(isotime, datetime.datetime))
self.assertRaises(ValueError, timeutils.parse_isotime, "bad input")
self.assertRaises(ValueError, timeutils.parse_isotime, isotime)

+ 10
- 1
fm-rest-api/fm/test-requirements.txt View File

@ -1 +1,10 @@
-r requirements.txt
hacking!=0.13.0,<0.14,>=0.12.0
bashate >= 0.2
PyYAML >= 3.1.0
yamllint >= 0.5.2
stestr
testtools!=1.2.0,>=0.9.36
iso8601
stestr
mock
cython

+ 33
- 0
fm-rest-api/fm/tox.ini View File

@ -0,0 +1,33 @@
[tox]
envlist = py27,py35
minversion = 2.3
skipsdist = True
stxdir = {toxinidir}/../../../
[testenv]
install_command = pip install -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
OS_STDOUT_CAPTURE=1
OS_STDERR_CAPTURE=1
OS_TEST_TIMEOUT=60
deps = -r{toxinidir}/test-requirements.txt
[testenv:venv]
basepython = python3
commands = {posargs}
[testenv:py27]
basepython = python2.7
commands =
stestr run {posargs}
stestr slowest
[testenv:py35]
basepython = python3.5
commands =
stestr run {posargs}
stestr slowest

+ 7
- 1
test-requirements.txt View File

@ -2,4 +2,10 @@ hacking!=0.13.0,<0.14,>=0.12.0
bashate >= 0.2
PyYAML >= 3.1.0
yamllint >= 0.5.2
spec_cleaner>=1.0.9
#spec_cleaner>=1.0.9
stestr
testtools!=1.2.0,>=0.9.36
iso8601
stestr
mock
cython

+ 2
- 0
tox.ini View File

@ -2,6 +2,7 @@
envlist = linters,pep8,rpm-packaging-lint
minversion = 2.3
skipsdist = True
stxdir = {toxinidir}/../
[testenv]
install_command = pip install -U {opts} {packages}
@ -128,3 +129,4 @@ commands = {toxinidir}/devstack/build.sh
basepython = python3
whitelist_externals = cat
commands = cat /etc/fm/fm.conf

Loading…
Cancel
Save