Add autopep8 to tox.ini

autopep8 is an automated code formatting tool for python,
it does not know everything, also not super fast,
but it is faster than I can manually reformat the code.

tools/format.sh will call the formatting,
the tox will check did you called it.

Also adding a tox -eautopep8 way to use it.

autopep8 formats the lines in one way,
where tempest used a another way it was changed.

Change-Id: I6d51b14a5a5b87761071d0927fca23ba1651aa41
This commit is contained in:
afazekas 2019-03-08 11:25:11 +01:00
parent c975f08e9b
commit 40fcb9ba28
27 changed files with 54 additions and 34 deletions

View File

@ -310,8 +310,8 @@ class TempestCleanup(command.Command):
svc.run() svc.run()
with open(SAVED_STATE_JSON, 'w+') as f: with open(SAVED_STATE_JSON, 'w+') as f:
f.write(json.dumps(data, f.write(json.dumps(data, sort_keys=True,
sort_keys=True, indent=2, separators=(',', ': '))) indent=2, separators=(',', ': ')))
def _load_json(self, saved_state_json=SAVED_STATE_JSON): def _load_json(self, saved_state_json=SAVED_STATE_JSON):
try: try:

View File

@ -202,8 +202,8 @@ class TempestRun(command.Command):
svc.run() svc.run()
with open(SAVED_STATE_JSON, 'w+') as f: with open(SAVED_STATE_JSON, 'w+') as f:
f.write(json.dumps(data, f.write(json.dumps(data, sort_keys=True,
sort_keys=True, indent=2, separators=(',', ': '))) indent=2, separators=(',', ': ')))
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super(TempestRun, self).get_parser(prog_name) parser = super(TempestRun, self).get_parser(prog_name)

View File

@ -19,7 +19,6 @@ from tempest.lib import exceptions as lib_exc
def get_unused_ip_addresses(ports_client, subnets_client, def get_unused_ip_addresses(ports_client, subnets_client,
network_id, subnet_id, count): network_id, subnet_id, count):
"""Return a list with the specified number of unused IP addresses """Return a list with the specified number of unused IP addresses
This method uses the given ports_client to find the specified number of This method uses the given ports_client to find the specified number of

View File

@ -48,6 +48,7 @@ class TestMinimumBasicScenario(manager.ScenarioTest):
10. Check SSH connection to instance after reboot 10. Check SSH connection to instance after reboot
""" """
def nova_show(self, server): def nova_show(self, server):
got_server = (self.servers_client.show_server(server['id']) got_server = (self.servers_client.show_server(server['id'])
['server']) ['server'])

View File

@ -86,7 +86,6 @@ class TestVolumeBootPattern(manager.EncryptionScenarioTest):
'Cinder volume snapshots are disabled') 'Cinder volume snapshots are disabled')
@utils.services('compute', 'volume', 'image') @utils.services('compute', 'volume', 'image')
def test_volume_boot_pattern(self): def test_volume_boot_pattern(self):
"""This test case attempts to reproduce the following steps: """This test case attempts to reproduce the following steps:
* Create in Cinder some bootable volume importing a Glance image * Create in Cinder some bootable volume importing a Glance image

View File

@ -179,6 +179,7 @@ class TempestTestPluginManager(object):
This class is used to manage the lifecycle of external tempest test This class is used to manage the lifecycle of external tempest test
plugins. It provides functions for getting set plugins. It provides functions for getting set
""" """
def __init__(self): def __init__(self):
self.ext_plugins = stevedore.ExtensionManager( self.ext_plugins = stevedore.ExtensionManager(
'tempest.test_plugins', invoke_on_load=True, 'tempest.test_plugins', invoke_on_load=True,

View File

@ -186,13 +186,17 @@ class TestImagesClient(base.BaseServiceTest):
def _test_resource_deleted(self, bytes_body=False): def _test_resource_deleted(self, bytes_body=False):
params = {"id": self.FAKE_IMAGE_ID} params = {"id": self.FAKE_IMAGE_ID}
expected_op = self.FAKE_IMAGE_DATA['show'] expected_op = self.FAKE_IMAGE_DATA['show']
self.useFixture(fixtures.MockPatch('tempest.lib.services.compute' self.useFixture(
fixtures.MockPatch(
'tempest.lib.services.compute'
'.images_client.ImagesClient.show_image', '.images_client.ImagesClient.show_image',
side_effect=lib_exc.NotFound)) side_effect=lib_exc.NotFound))
self.assertEqual(True, self.client.is_resource_deleted(**params)) self.assertEqual(True, self.client.is_resource_deleted(**params))
tempdata = copy.deepcopy(self.FAKE_IMAGE_DATA['show']) tempdata = copy.deepcopy(self.FAKE_IMAGE_DATA['show'])
tempdata['image']['id'] = None tempdata['image']['id'] = None
self.useFixture(fixtures.MockPatch('tempest.lib.services.compute' self.useFixture(
fixtures.MockPatch(
'tempest.lib.services.compute'
'.images_client.ImagesClient.show_image', '.images_client.ImagesClient.show_image',
return_value=expected_op)) return_value=expected_op))
self.assertEqual(False, self.client.is_resource_deleted(**params)) self.assertEqual(False, self.client.is_resource_deleted(**params))

View File

@ -48,6 +48,7 @@ class HackingTestCase(base.TestCase):
just assertTrue if the check is expected to fail and assertFalse if it just assertTrue if the check is expected to fail and assertFalse if it
should pass. should pass.
""" """
def test_no_setup_teardown_class_for_tests(self): def test_no_setup_teardown_class_for_tests(self):
self.assertTrue(checks.no_setup_teardown_class_for_tests( self.assertTrue(checks.no_setup_teardown_class_for_tests(
" def setUpClass(cls):", './tempest/tests/fake_test.py')) " def setUpClass(cls):", './tempest/tests/fake_test.py'))

5
tools/format.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
cd $(dirname "$(readlink -f "$0")")
autopep8 --exit-code --max-line-length=79 --experimental --in-place -r ../tempest ../setup.py && echo Formatting was not needed. >&2

10
tox.ini
View File

@ -197,11 +197,21 @@ commands =
whitelist_externals = rm whitelist_externals = rm
[testenv:pep8] [testenv:pep8]
deps =
-r test-requirements.txt
autopep8
basepython = python3 basepython = python3
commands = commands =
autopep8 --exit-code --max-line-length=79 --experimental --diff -r tempest setup.py
flake8 {posargs} flake8 {posargs}
check-uuid check-uuid
[testenv:autopep8]
deps = autopep8
basepython = python3
commands =
autopep8 --max-line-length=79 --experimental --in-place -r tempest setup.py
[testenv:uuidgen] [testenv:uuidgen]
commands = commands =
check-uuid --fix check-uuid --fix