Merge "Port test_hacking to Python 3"

This commit is contained in:
Jenkins
2016-07-22 02:36:20 +00:00
committed by Gerrit Code Review
2 changed files with 21 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ import os
import re import re
import pep8 import pep8
import six
""" """
Guidelines for writing new hacking checks Guidelines for writing new hacking checks
@@ -431,14 +432,26 @@ class CheckForStrUnicodeExc(BaseASTChecker):
self.name = [] self.name = []
self.already_checked = [] self.already_checked = []
def visit_TryExcept(self, node): # Python 2 produces ast.TryExcept and ast.TryFinally nodes, but Python 3
for handler in node.handlers: # only produces ast.Try nodes.
if handler.name: if six.PY2:
self.name.append(handler.name.id) def visit_TryExcept(self, node):
super(CheckForStrUnicodeExc, self).generic_visit(node) for handler in node.handlers:
self.name = self.name[:-1] if handler.name:
else: self.name.append(handler.name.id)
super(CheckForStrUnicodeExc, self).generic_visit(node) super(CheckForStrUnicodeExc, self).generic_visit(node)
self.name = self.name[:-1]
else:
super(CheckForStrUnicodeExc, self).generic_visit(node)
else:
def visit_Try(self, node):
for handler in node.handlers:
if handler.name:
self.name.append(handler.name)
super(CheckForStrUnicodeExc, self).generic_visit(node)
self.name = self.name[:-1]
else:
super(CheckForStrUnicodeExc, self).generic_visit(node)
def visit_Call(self, node): def visit_Call(self, node):
if self._check_call_names(node, ['str', 'unicode']): if self._check_call_names(node, ['str', 'unicode']):

View File

@@ -57,7 +57,6 @@ nova.tests.unit.pci.test_stats.PciDeviceStatsTestCase
nova.tests.unit.pci.test_stats.PciDeviceStatsWithTagsTestCase nova.tests.unit.pci.test_stats.PciDeviceStatsWithTagsTestCase
nova.tests.unit.test_bdm.BlockDeviceMappingEc2CloudTestCase nova.tests.unit.test_bdm.BlockDeviceMappingEc2CloudTestCase
nova.tests.unit.test_configdrive2.ConfigDriveTestCase nova.tests.unit.test_configdrive2.ConfigDriveTestCase
nova.tests.unit.test_hacking.HackingTestCase
nova.tests.unit.test_matchers.TestDictMatches nova.tests.unit.test_matchers.TestDictMatches
nova.tests.unit.test_metadata.MetadataHandlerTestCase nova.tests.unit.test_metadata.MetadataHandlerTestCase
nova.tests.unit.test_metadata.MetadataPasswordTestCase nova.tests.unit.test_metadata.MetadataPasswordTestCase