Merge "hacking: Add check for deprecated exception types"
This commit is contained in:
commit
12de8a105e
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from hacking import core
|
from hacking import core
|
||||||
@ -26,7 +27,7 @@ Guidelines for writing new hacking checks
|
|||||||
- Keep the test method code in the source file ordered based
|
- Keep the test method code in the source file ordered based
|
||||||
on the O3xx value.
|
on the O3xx value.
|
||||||
- List the new rule in the top level HACKING.rst file
|
- List the new rule in the top level HACKING.rst file
|
||||||
- Add test cases for each new rule to nova/tests/unit/test_hacking.py
|
- Add test cases for each new rule to openstack/tests/unit/test_hacking.py
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -41,3 +42,23 @@ def assert_no_setupclass(logical_line):
|
|||||||
"""
|
"""
|
||||||
if SETUPCLASS_RE.match(logical_line):
|
if SETUPCLASS_RE.match(logical_line):
|
||||||
yield (0, "O300: setUpClass not allowed")
|
yield (0, "O300: setUpClass not allowed")
|
||||||
|
|
||||||
|
|
||||||
|
@core.flake8ext
|
||||||
|
def assert_no_deprecated_exceptions(logical_line, filename):
|
||||||
|
"""Check for use of deprecated cloud-layer exceptions
|
||||||
|
|
||||||
|
0310
|
||||||
|
"""
|
||||||
|
if filename.endswith(os.path.join('openstack', 'cloud', 'exc.py')):
|
||||||
|
return
|
||||||
|
|
||||||
|
for exception in (
|
||||||
|
'OpenStackCloudTimeout',
|
||||||
|
'OpenStackCloudHTTPError',
|
||||||
|
'OpenStackCloudBadRequest',
|
||||||
|
'OpenStackCloudURINotFound',
|
||||||
|
'OpenStackCloudResourceNotFound',
|
||||||
|
):
|
||||||
|
if re.search(fr'\b{exception}\b', logical_line):
|
||||||
|
yield (0, 'O310: Use of deprecated Exception class')
|
@ -37,7 +37,7 @@ class OpenStackCloudUnavailableFeature(OpenStackCloudException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Backwards compat
|
# Backwards compat. These are deprecated and should not be used in new code.
|
||||||
OpenStackCloudTimeout = exceptions.ResourceTimeout
|
OpenStackCloudTimeout = exceptions.ResourceTimeout
|
||||||
OpenStackCloudHTTPError = exceptions.HttpException
|
OpenStackCloudHTTPError = exceptions.HttpException
|
||||||
OpenStackCloudBadRequest = exceptions.BadRequestException
|
OpenStackCloudBadRequest = exceptions.BadRequestException
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from openstack import _hacking
|
from openstack._hacking import checks
|
||||||
from openstack.tests.unit import base
|
from openstack.tests.unit import base
|
||||||
|
|
||||||
|
|
||||||
@ -52,20 +52,45 @@ class HackingTestCase(base.TestCase):
|
|||||||
|
|
||||||
def test_assert_no_setupclass(self):
|
def test_assert_no_setupclass(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(list(_hacking.assert_no_setupclass("def setUpClass(cls)"))), 1
|
len(list(checks.assert_no_setupclass("def setUpClass(cls)"))), 1
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(list(_hacking.assert_no_setupclass("# setUpClass is evil"))), 0
|
len(list(checks.assert_no_setupclass("# setUpClass is evil"))), 0
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(
|
len(
|
||||||
list(
|
list(
|
||||||
_hacking.assert_no_setupclass(
|
checks.assert_no_setupclass(
|
||||||
"def setUpClassyDrinkingLocation(cls)"
|
"def setUpClassyDrinkingLocation(cls)"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_assert_no_deprecated_exceptions(self):
|
||||||
|
self.assertEqual(
|
||||||
|
len(
|
||||||
|
list(
|
||||||
|
checks.assert_no_deprecated_exceptions(
|
||||||
|
"raise exc.OpenStackCloudTimeout",
|
||||||
|
"openstack/cloud/compute.py",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
len(
|
||||||
|
list(
|
||||||
|
checks.assert_no_deprecated_exceptions(
|
||||||
|
"raise exc.OpenStackCloudTimeout",
|
||||||
|
"openstack/cloud/exc.py",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
5
tox.ini
5
tox.ini
@ -160,8 +160,9 @@ exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,openstack/_services_m
|
|||||||
|
|
||||||
[flake8:local-plugins]
|
[flake8:local-plugins]
|
||||||
extension =
|
extension =
|
||||||
O300 = _hacking:assert_no_setupclass
|
O300 = checks:assert_no_setupclass
|
||||||
paths = ./openstack
|
O310 = checks:assert_no_deprecated_exceptions
|
||||||
|
paths = ./openstack/_hacking
|
||||||
|
|
||||||
[doc8]
|
[doc8]
|
||||||
extensions = .rst, .yaml
|
extensions = .rst, .yaml
|
||||||
|
Loading…
x
Reference in New Issue
Block a user