Merge pull request #72 from gnuoy/enable-docstring-lint

Enable doc string lint checks
This commit is contained in:
Alex Kavanagh
2018-06-21 09:55:20 +01:00
committed by GitHub
3 changed files with 20 additions and 2 deletions
+2
View File
@@ -4,6 +4,8 @@ juju
juju_wait
PyYAML
flake8>=2.2.4,<=3.5.0
flake8-docstrings
flake8-per-file-ignores
mock>=1.2
nose>=1.3.7
pbr>=1.8.0,<1.9.0
+2
View File
@@ -23,6 +23,8 @@ commands = {posargs}
[flake8]
ignore = E402,E226
per-file-ignores =
unit_tests/**: D
[testenv:docs]
basepython = python3
+16 -2
View File
@@ -15,6 +15,8 @@
# sys.modules['charmhelpers.contrib.openstack.utils'] = mock.MagicMock()
# sys.modules['charmhelpers.contrib.network.ip'] = mock.MagicMock()
"""Module to provide helper for writing unit tests."""
import contextlib
import io
import mock
@@ -23,10 +25,13 @@ import unittest
@contextlib.contextmanager
def patch_open():
'''Patch open() to allow mocking both open() itself and the file that is
"""Patch open().
Patch open() to allow mocking both open() itself and the file that is
yielded.
Yields the mock for "open" and "file", respectively.'''
Yields the mock for "open" and "file", respectively.
"""
mock_open = mock.MagicMock(spec=open)
mock_file = mock.MagicMock(spec=io.FileIO)
@@ -40,12 +45,19 @@ def patch_open():
class BaseTestCase(unittest.TestCase):
"""Base class for creating classes of unit tests."""
def shortDescription(self):
"""Disable reporting unit test doc strings rather than names."""
return None
def setUp(self):
"""Run setup of patches."""
self._patches = {}
self._patches_start = {}
def tearDown(self):
"""Run teardown of patches."""
for k, v in self._patches.items():
v.stop()
setattr(self, k, None)
@@ -54,6 +66,7 @@ class BaseTestCase(unittest.TestCase):
def patch_object(self, obj, attr, return_value=None, name=None, new=None,
**kwargs):
"""Patch the given object."""
if name is None:
name = attr
if new is not None:
@@ -68,6 +81,7 @@ class BaseTestCase(unittest.TestCase):
setattr(self, name, started)
def patch(self, item, return_value=None, name=None, new=None, **kwargs):
"""Patch the given item."""
if name is None:
raise RuntimeError("Must pass 'name' to .patch()")
if new is not None: