From 05022e1ff8a93fe7b1e666bad58ab153ca8b9034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Tr=C4=99bski?= Date: Fri, 13 Jan 2017 14:22:46 +0100 Subject: [PATCH] Extend tox for monasca-statsd Following commits accomplishes several things: * unit tests run with ostestr * coverage calculation * documentation generated using OS approach & theme * bandit linting Change-Id: I6c3b48805c237f0ad95220b90ff66b045c7478fb --- .coveragerc | 7 ++ .gitignore | 4 + .testr.conf | 9 +++ {docs => doc}/source/conf.py | 40 ++++++--- doc/source/index.rst | 22 +++++ docs/Makefile | 153 ----------------------------------- docs/source/index.rst | 35 -------- setup.cfg | 6 ++ test-requirements.txt | 13 ++- tests/__init__.py | 0 tox.ini | 65 +++++++++++++-- 11 files changed, 144 insertions(+), 210 deletions(-) create mode 100644 .coveragerc create mode 100644 .testr.conf rename {docs => doc}/source/conf.py (91%) create mode 100644 doc/source/index.rst delete mode 100644 docs/Makefile delete mode 100644 docs/source/index.rst create mode 100644 tests/__init__.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..1ce546b --- /dev/null +++ b/.coveragerc @@ -0,0 +1,7 @@ +[run] +branch = True +source = monascastatsd +omit = tests/* + +[report] +ignore_errors = True \ No newline at end of file diff --git a/.gitignore b/.gitignore index bbb5722..faa9c1d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ dist .tox AUTHORS ChangeLog +.coverage +cover/ +.testrepository/ +doc/build/ \ No newline at end of file diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 0000000..72195ed --- /dev/null +++ b/.testr.conf @@ -0,0 +1,9 @@ +[DEFAULT] +test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ + OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ + OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \ + ${PYTHON:-python} -m subunit.run discover -t ./ $OS_TEST_PATH $LISTOPT $IDOPTION + +test_id_option=--load-list $IDFILE +test_list_option=--list +group_regex=tests(?:\.|_)([^_]+) \ No newline at end of file diff --git a/docs/source/conf.py b/doc/source/conf.py similarity index 91% rename from docs/source/conf.py rename to doc/source/conf.py index 9f572db..20d22e9 100644 --- a/docs/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,5 @@ # (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP +# Copyright 2017 FUJITSU LIMITED # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -54,6 +55,9 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. # sys.path.insert(0, os.path.abspath('.')) +import subprocess +import warnings + # -- General configuration ---------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. @@ -61,7 +65,14 @@ # 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', 'sphinx.ext.viewcode'] +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.viewcode', + 'sphinx.ext.graphviz', + 'oslosphinx' +] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -77,7 +88,8 @@ master_doc = 'index' # General information about the project. project = u'monasca-statsd' -copyright = u'2014, HP' +author = u'OpenStack' +copyright = u'2014-present, OpenStack Foundatio' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -110,24 +122,24 @@ exclude_patterns = [] # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -# add_module_names = True +add_module_names = False # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -# show_authors = False +show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] +modindex_common_prefix = ['monasca.'] # -- Options for HTML output -------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +# html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -160,7 +172,15 @@ html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' +#html_last_updated_fmt = '%b %d, %Y' +git_cmd = ["git", "log", "--pretty=format:'%ad, commit %h'", "--date=local", + "-n1"] +try: + html_last_updated_fmt = subprocess.Popen( + git_cmd, stdout=subprocess.PIPE).communicate()[0].decode() +except Exception: + warnings.warn('Cannot get last updated time from git repository. ' + 'Not setting "html_last_updated_fmt".') # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. @@ -223,7 +243,7 @@ latex_documents = [ ('index', 'monasca-statsd-python.tex', u'monasca-statsd-python Documentation', - u'HP', + u'OpenStack Foundation', 'manual'), ] @@ -254,7 +274,7 @@ latex_documents = [ # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'monasca-statsd-python', u'monasca-statsd-python Documentation', - [u'HP'], 1) + [u'OpenStack Foundation'], 1) ] # If true, show URL addresses after external links. @@ -269,7 +289,7 @@ man_pages = [ texinfo_documents = [ ('index', 'monasca-statsd-python', u'monasca-statsd-python Documentation', - u'HP', + u'Openstack Foundation', 'monasca-statsd-python', 'One line description of project.', 'Miscellaneous'), diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000..282e71b --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1,22 @@ +Introduction +============ + +A global :class:`~statsd.MonascaStatsd` instance that is easily shared +across an application's modules. Initialize this once in your application's +set-up code and then other modules can import and use it without further +configuration. + + >>> from monascastatsd import monascastatsd + >>> monascastatsd.connect(host='localhost', port=8125) + +Source +====== + +The Monasca-Statsd source is freely available on Github. Check it out `here +`_. + +Get in Touch +============ + +If you'd like to suggest a feature or report a bug, +please add an issue `here `_. diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index 8f5c25b..0000000 --- a/docs/Makefile +++ /dev/null @@ -1,153 +0,0 @@ -# Makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -PAPER = -BUILDDIR = build - -# Internal variables. -PAPEROPT_a4 = -D latex_paper_size=a4 -PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source -# the i18n builder cannot share the environment and doctrees with the others -I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source - -.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext - -help: - @echo "Please use \`make ' where is one of" - @echo " html to make standalone HTML files" - @echo " dirhtml to make HTML files named index.html in directories" - @echo " singlehtml to make a single large HTML file" - @echo " pickle to make pickle files" - @echo " json to make JSON files" - @echo " htmlhelp to make HTML files and a HTML help project" - @echo " qthelp to make HTML files and a qthelp project" - @echo " devhelp to make HTML files and a Devhelp project" - @echo " epub to make an epub" - @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" - @echo " latexpdf to make LaTeX files and run them through pdflatex" - @echo " text to make text files" - @echo " man to make manual pages" - @echo " texinfo to make Texinfo files" - @echo " info to make Texinfo files and run them through makeinfo" - @echo " gettext to make PO message catalogs" - @echo " changes to make an overview of all changed/added/deprecated items" - @echo " linkcheck to check all external links for integrity" - @echo " doctest to run all doctests embedded in the documentation (if enabled)" - -clean: - -rm -rf $(BUILDDIR)/* - -html: - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." - -dirhtml: - $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." - -singlehtml: - $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml - @echo - @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." - -pickle: - $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle - @echo - @echo "Build finished; now you can process the pickle files." - -json: - $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json - @echo - @echo "Build finished; now you can process the JSON files." - -htmlhelp: - $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp - @echo - @echo "Build finished; now you can run HTML Help Workshop with the" \ - ".hhp project file in $(BUILDDIR)/htmlhelp." - -qthelp: - $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp - @echo - @echo "Build finished; now you can run "qcollectiongenerator" with the" \ - ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/monasca-statsd.qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/monasca-statsd.qhc" - -devhelp: - $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp - @echo - @echo "Build finished." - @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/monasca-statsd" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/monasca-statsd" - @echo "# devhelp" - -epub: - $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub - @echo - @echo "Build finished. The epub file is in $(BUILDDIR)/epub." - -latex: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo - @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." - @echo "Run \`make' in that directory to run these through (pdf)latex" \ - "(use \`make latexpdf' here to do that automatically)." - -latexpdf: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through pdflatex..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -text: - $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text - @echo - @echo "Build finished. The text files are in $(BUILDDIR)/text." - -man: - $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man - @echo - @echo "Build finished. The manual pages are in $(BUILDDIR)/man." - -texinfo: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo - @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." - @echo "Run \`make' in that directory to run these through makeinfo" \ - "(use \`make info' here to do that automatically)." - -info: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo "Running Texinfo files through makeinfo..." - make -C $(BUILDDIR)/texinfo info - @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." - -gettext: - $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale - @echo - @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." - -changes: - $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes - @echo - @echo "The overview file is in $(BUILDDIR)/changes." - -linkcheck: - $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck - @echo - @echo "Link check complete; look for any errors in the above output " \ - "or in $(BUILDDIR)/linkcheck/output.txt." - -doctest: - $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest - @echo "Testing of doctests in the sources finished, look at the " \ - "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/source/index.rst b/docs/source/index.rst deleted file mode 100644 index b358ffc..0000000 --- a/docs/source/index.rst +++ /dev/null @@ -1,35 +0,0 @@ -.. monasca-statsd documentation master file, created by - sphinx-quickstart on Thu Jun 14 19:22:15 2012. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -monasca-statsd -============== - - -.. automodule:: statsd - - .. autoclass:: Monasca-Statsd - :members: - -.. module:: statsd -.. data:: statsd - - A global :class:`~statsd.MonascaStatsd` instance that is easily shared - across an application's modules. Initialize this once in your application's - set-up code and then other modules can import and use it without further - configuration. - - >>> from monascastatsd import monascastatsd - >>> monascastatsd.connect(host='localhost', port=8125) - -Source -====== - -The Monasca-Statsd source is freely available on Github. Check it out `here -`_. - -Get in Touch -============ - -If you'd like to suggest a feature or report a bug, please add an issue `here `_. diff --git a/setup.cfg b/setup.cfg index f777827..9adc837 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,6 +18,7 @@ classifier = Topic :: System :: Monitoring Programming Language :: Python Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3.5 [files] packages = @@ -37,3 +38,8 @@ universal = 1 tag_build = tag_date = 0 tag_svn_revision = 0 + +[build_sphinx] +all_files = 1 +build-dir = doc/build +source-dir = doc/source diff --git a/test-requirements.txt b/test-requirements.txt index 3b989fe..41e162f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,8 +1,13 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 - -nose # LGPL -nosexcover # BSD +hacking>=0.12.0,!=0.13.0,<0.14 # Apache-2.0 +bandit>=1.1.0 # Apache-2.0 +coverage>=4.0 # Apache-2.0 mock>=2.0 # BSD +sphinx!=1.3b1,<1.4,>=1.2.1 # BSD +oslosphinx>=4.7.0 # Apache-2.0 +oslotest>=1.10.0 # Apache-2.0 +os-testr>=0.8.0 # Apache-2.0 +testrepository>=0.0.18 # Apache-2.0/BSD +openstackdocstheme>=1.5.0 # Apache-2.0 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini index e51b967..d9988d2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,30 +1,79 @@ [tox] -envlist = py27,py35,pep8 -minversion = 1.6 +envlist = py{27,35},pep8,cover +minversion = 2.5 skipsdist = True [testenv] +setenv = + VIRTUAL_ENV={envdir} + OS_TEST_PATH=tests + CLIENT_NAME=monasca-statsd +passenv = http_proxy + HTTP_PROXY + https_proxy + HTTPS_PROXY + no_proxy + NO_PROXY usedevelop = True install_command = {toxinidir}/tools/tox_install.sh {env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} -setenv = - VIRTUAL_ENV={envdir} - DISCOVER_DIRECTORY=tests deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt whitelist_externals = bash find + rm commands = find . -type f -name "*.py[c|o]" -delete - nosetests + +[testenv:py27] +basepython = python2.7 +deps = {[testenv]deps} +commands = + {[testenv]commands} + ostestr {posargs} + +[testenv:py35] +basepython = python3.5 +deps = {[testenv]deps} +commands = + {[testenv]commands} + ostestr {posargs} + +[testenv:cover] +basepython = python2.7 +deps = {[testenv]deps} +commands = + {[testenv]commands} + coverage erase + python setup.py test --coverage --testr-args='{posargs}' --coverage-package-name=monascastatsd + coverage report + +[testenv:debug] +deps = {[testenv]deps} +commands = + {[testenv]commands} + oslo_debug_helper -t {toxinidir}/tests {posargs} + +[testenv:docs] +commands = + rm -rf doc/build + python setup.py build_sphinx + +[testenv:bandit] +commands = bandit -r monascastatsd -s B311 -n5 -x monascastatsd/tests + +[testenv:flake8] +commands = flake8 monascastatsd [testenv:pep8] -commands = flake8 +commands = + {[testenv:flake8]commands} + {[testenv:bandit]commands} [testenv:venv] commands = {posargs} [flake8] show-source = True -exclude=.venv,.git,.tox,dist,*egg,build +exclude=.venv,.git,.tox,dist,*egg,build,docs,cover max-line-length = 120