From 59fe450ae9fc3e6f012a6931a9d0f6785a70a944 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 27 Jul 2016 01:03:57 -0400 Subject: [PATCH] Fix all things tox This commit fixes all the issues with the tox jobs. I initially wrote this project outside of the openstack infrastructure and played kinda hard and fast with anything from tox. To correct this I need to add sphinx docs, a pro forma test to (and the preresiquite testr boilerplate), and a bunch of random pep8 fixes. Change-Id: I9946fc7db5c030b5860f03b45471f70c1fc4efb1 --- .testr.conf | 8 ++++ doc/source/conf.py | 74 +++++++++++++++++++++++++++++++++++ doc/source/index.rst | 9 +++++ doc/source/readme.rst | 1 + germqtt/germqtt.py | 6 ++- germqtt/tests/base.py | 37 ++++++++++++++++++ germqtt/tests/test_germqtt.py | 29 ++++++++++++++ requirements.txt | 1 + test-requirements.txt | 5 --- tox.ini | 2 +- 10 files changed, 164 insertions(+), 8 deletions(-) create mode 100644 .testr.conf create mode 100755 doc/source/conf.py create mode 100644 doc/source/index.rst create mode 100644 doc/source/readme.rst create mode 100644 germqtt/tests/base.py create mode 100644 germqtt/tests/test_germqtt.py diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 0000000..6ddafdd --- /dev/null +++ b/.testr.conf @@ -0,0 +1,8 @@ +[DEFAULT] +test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ + OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ + OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-500} \ + OS_TEST_LOCK_PATH=${OS_TEST_LOCK_PATH:-${TMPDIR:-'/tmp'}} \ + ${PYTHON:-python} -m subunit.run discover -t ./ ./germqtt/tests $LISTOPT $IDOPTION +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/doc/source/conf.py b/doc/source/conf.py new file mode 100755 index 0000000..b4628b2 --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +# 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 os +import sys + +sys.path.insert(0, os.path.abspath('../..')) +# -- General configuration ---------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [ + 'sphinx.ext.autodoc', + 'oslosphinx', +] + +# autodoc generation is a bit aggressive and a nuisance when doing heavy +# text edit cycles. +# execute "export SPHINX_DEBUG=1" in your terminal to disable + +# The suffix of source filenames. +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'germqtt' +copyright = u'2016, Matthew Treinish' + +# If true, '()' will be appended to :func: etc. cross-reference text. +add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +add_module_names = True + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# -- Options for HTML output -------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. Major themes that come with +# Sphinx are currently 'default' and 'sphinxdoc'. +# html_theme_path = ["."] +# html_theme = '_theme' +# html_static_path = ['static'] + +# Output file base name for HTML help builder. +htmlhelp_basename = '%sdoc' % project + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass +# [howto/manual]). +latex_documents = [ + ('index', + '%s.tex' % project, + u'%s Documentation' % project, + u'Matthew Treinish', 'manual'), +] + +# Example configuration for intersphinx: refer to the Python standard library. +# intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000..b0ec624 --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1,9 @@ +germqtt +======= + +Contents: + +.. toctree:: + :maxdepth: 2 + + readme diff --git a/doc/source/readme.rst b/doc/source/readme.rst new file mode 100644 index 0000000..a6210d3 --- /dev/null +++ b/doc/source/readme.rst @@ -0,0 +1 @@ +.. include:: ../../README.rst diff --git a/germqtt/germqtt.py b/germqtt/germqtt.py index 3e315d8..97a2016 100644 --- a/germqtt/germqtt.py +++ b/germqtt/germqtt.py @@ -15,14 +15,14 @@ # under the License. import argparse -import ConfigParser -import logging import json +import logging import os import daemon import gerritlib.gerrit import paho.mqtt.publish as publish +from six.moves import configparser as ConfigParser try: import daemon.pidlockfile @@ -36,6 +36,7 @@ except Exception: log = logging.getLogger('germqtt') + class GerritStream(object): def __init__(self, user, host, key, thread=True, port=29418): @@ -81,6 +82,7 @@ def get_options(): parser.add_argument('conffile', nargs=1, help="Configuration file") return parser.parse_args() + def get_topic(base_topic, event): project = event.get('project', '') event_type = event.get('type', '') diff --git a/germqtt/tests/base.py b/germqtt/tests/base.py new file mode 100644 index 0000000..a218d3c --- /dev/null +++ b/germqtt/tests/base.py @@ -0,0 +1,37 @@ +# Copyright (c) 2016 Hewlett-Packard Development Company, L.P. +# +# 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 os + +import fixtures +import testtools + + +class TestCase(testtools.TestCase): + + true = ('True', 'true', '1', 'yes') + + def setUp(self): + super(TestCase, self).setUp() + if os.environ.get('OS_STDOUT_CAPTURE') in self.true: + stdout = self.useFixture(fixtures.StringStream('stdout')).stream + self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) + if os.environ.get('OS_STDERR_CAPTURE') in self.true: + stderr = self.useFixture(fixtures.StringStream('stderr')).stream + self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) + if (os.environ.get('OS_LOG_CAPTURE') != 'False' and + os.environ.get('OS_LOG_CAPTURE') != '0'): + self.useFixture(fixtures.LoggerFixture(nuke_handlers=False, + level=None)) diff --git a/germqtt/tests/test_germqtt.py b/germqtt/tests/test_germqtt.py new file mode 100644 index 0000000..37eab5c --- /dev/null +++ b/germqtt/tests/test_germqtt.py @@ -0,0 +1,29 @@ +# Copyright (c) 2014 Hewlett-Packard Development Company, L.P. +# +# 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 germqtt import germqtt +from germqtt.tests import base + + +class TestGermqtt(base.TestCase): + + def test_get_topic_with_project(self): + base_topic = 'gerrit' + event = { + 'project': 'fake_project', + 'type': 'fake-type', + } + full_topic = germqtt.get_topic(base_topic, event) + self.assertEqual('gerrit/fake_project/fake-type', full_topic) diff --git a/requirements.txt b/requirements.txt index b205070..b0a9939 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. pbr>=1.6 # Apache-2.0 +six>=1.9.0 # MIT paho-mqtt>=1.1 gerritlib>=0.6.0 python-daemon diff --git a/test-requirements.txt b/test-requirements.txt index b8e5fb3..5456d48 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,11 +5,6 @@ hacking<0.11,>=0.10.2 # Apache-2.0 coverage>=3.6 # Apache-2.0 -discover # BSD sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0 -oslotest>=1.10.0 # Apache-2.0 -testscenarios>=0.4 # Apache-2.0/BSD -ddt>=1.0.1 # MIT -six>=1.9.0 # MIT os-testr>=0.6.0 diff --git a/tox.ini b/tox.ini index de5096f..20a0e9a 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,6 @@ commands = python setup.py build_sphinx # E123, E125 skipped as they are invalid PEP-8. show-source = True -ignore = E123,E125 +ignore = E123,E125,E129 builtins = _ exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build