Currently, check will not work if nested is imported like below:
from contextlib import nested
with nested(......
This commit adds the case and add unit test for it.
Change-Id: I60aa280054d9950b1d2edc9e23505c3395f96fb0
# imports, we will need to add them to the regex below.
oslo_namespace_imports = re.compile(r"from[\s]*oslo[.](concurrency|db"
"|config|utils|serialization|log)")
+no_contextlib_nested = re.compile(r"\s*with (contextlib\.)?nested\(")
def no_vi_headers(physical_line, line_number, lines):
"the with-statement supports multiple nested objects. See https://"
"docs.python.org/2/library/contextlib.html#contextlib.nested "
"for more information.")
- if "with contextlib.nested" in logical_line:
+ if no_contextlib_nested.match(logical_line):
yield(0, msg)
def test_no_contextlib_nested(self):
self.assertEqual(1, len(list(checks.check_no_contextlib_nested(
"with contextlib.nested("))))
+ self.assertEqual(1, len(list(checks.check_no_contextlib_nested(
+ " with nested("))))
+ self.assertEqual(0, len(list(checks.check_no_contextlib_nested(
+ "with my.nested("))))
self.assertEqual(0, len(list(checks.check_no_contextlib_nested(
"with foo as bar"))))