Merge "Migrate flake8 to pre-commit"

This commit is contained in:
Zuul 2018-11-22 21:48:07 +00:00 committed by Gerrit Code Review
commit c5156af3e6
10 changed files with 176 additions and 111 deletions

View File

@ -9,6 +9,9 @@ repos:
- id: check-executables-have-shebangs - id: check-executables-have-shebangs
- id: check-merge-conflict - id: check-merge-conflict
- id: debug-statements - id: debug-statements
- id: flake8
additional_dependencies:
- hacking<1.2.0,>=1.1.0
- id: check-yaml - id: check-yaml
files: .*\.(yaml|yml)$ files: .*\.(yaml|yml)$
- repo: https://github.com/adrienverge/yamllint.git - repo: https://github.com/adrienverge/yamllint.git

View File

@ -1,4 +1,22 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# #
# instack-undercloud documentation build configuration file, created by # instack-undercloud documentation build configuration file, created by
# sphinx-quickstart on Wed Feb 25 10:56:57 2015. # sphinx-quickstart on Wed Feb 25 10:56:57 2015.
@ -11,18 +29,17 @@
# All configuration values have a default; values that are commented out # All configuration values have a default; values that are commented out
# serve to show the default. # serve to show the default.
import sys, os
import sphinx_rtd_theme import sphinx_rtd_theme
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here. # documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.')) # sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ----------------------------------------------------- # -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here. # If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0' # needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be # Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
@ -39,7 +56,7 @@ templates_path = ['_templates']
source_suffix = '.rst' source_suffix = '.rst'
# The encoding of source files. # The encoding of source files.
#source_encoding = 'utf-8-sig' # source_encoding = 'utf-8-sig'
# The master toctree document. # The master toctree document.
master_doc = 'index' master_doc = 'index'
@ -61,37 +78,37 @@ release = '3.0.0'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
#language = None # language = None
# There are two options for replacing |today|: either, you set today to some # There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used: # non-false value, then it is used:
#today = '' # today = ''
# Else, today_fmt is used as the format for a strftime call. # Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y' # today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
exclude_patterns = [] exclude_patterns = []
# The reST default role (used for this markup: `text`) to use for all documents. # The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None # default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text. # If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True # add_function_parentheses = True
# If true, the current module name will be prepended to all description # If true, the current module name will be prepended to all description
# unit titles (such as .. function::). # unit titles (such as .. function::).
#add_module_names = True # add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the # If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default. # output. They are ignored by default.
#show_authors = False # show_authors = False
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting. # A list of ignored prefixes for module index sorting.
#modindex_common_prefix = [] # modindex_common_prefix = []
# -- Options for HTML output --------------------------------------------------- # -- Options for HTML output ---------------------------------------------------
@ -110,15 +127,15 @@ html_show_copyright = True
# -- Options for LaTeX output -------------------------------------------------- # -- Options for LaTeX output --------------------------------------------------
latex_elements = { latex_elements = {
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper', # 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt'). # The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt', # 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble. # Additional stuff for the LaTeX preamble.
#'preamble': '', # 'preamble': '',
} }
rst_prolog = """ rst_prolog = """
.. |project| replace:: %s .. |project| replace:: %s

View File

@ -49,6 +49,7 @@ def process_events(all_events, events):
elapsed = times[name]['elapsed'] elapsed = times[name]['elapsed']
print('%s %s') % (name, elapsed) print('%s %s') % (name, elapsed)
if __name__ == '__main__': if __name__ == '__main__':
stdin = sys.stdin.read() stdin = sys.stdin.read()
all_events = json.loads(stdin) all_events = json.loads(stdin)

View File

@ -213,7 +213,8 @@ class InfluxStandardFields(object):
return os.environ.get('STATS_OOOQ', 0) return os.environ.get('STATS_OOOQ', 0)
def zuul_host_prepare(self): def zuul_host_prepare(self):
if (os.environ.get('DEVSTACK_GATE_TIMEOUT') and
if (os.environ.get('DEVSTACK_GATE_TIMEOUT') and # noqa: W504
os.environ.get('REMAINING_TIME')): os.environ.get('REMAINING_TIME')):
return (int( return (int(
os.environ['DEVSTACK_GATE_TIMEOUT']) - int( os.environ['DEVSTACK_GATE_TIMEOUT']) - int(

View File

@ -1,3 +1,21 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
import argparse import argparse
import bugzilla import bugzilla
import logging import logging
@ -157,13 +175,13 @@ class BugVerifyCmd(object):
return output return output
def print_output(self, known_failures, output_format): def print_output(self, known_failures, output_format):
print self.get_output(known_failures, output_format) print(self.get_output(known_failures, output_format))
def show_report(self): def show_report(self):
print 'Here\'s the original list:' print('Here\'s the original list:')
self.print_output(self.original_failures, self.args.output_format) self.print_output(self.original_failures, self.args.output_format)
print '\n\n' print('\n\n')
print 'Here\'s the skipped list:' print('Here\'s the skipped list:')
self.print_output(self.skipped_failures, self.args.output_format) self.print_output(self.skipped_failures, self.args.output_format)
def save_output(self, known_failures, output_format): def save_output(self, known_failures, output_format):
@ -202,5 +220,6 @@ def main():
bvc.setup_logging() bvc.setup_logging()
bvc.run() bvc.run()
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())

View File

@ -1,3 +1,21 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
import mock import mock
import os import os
import tempfile import tempfile
@ -6,11 +24,11 @@ import xmlrpclib
from bugcheck import BugVerifyCmd from bugcheck import BugVerifyCmd
from bugcheck import BugzillaConnector from bugcheck import BugzillaConnector
from bugcheck import LaunchpadConnector
from bugcheck import VerifyBug
from bugcheck import OPEN
from bugcheck import CLOSED from bugcheck import CLOSED
from bugcheck import INVALID from bugcheck import INVALID
from bugcheck import LaunchpadConnector
from bugcheck import OPEN
from bugcheck import VerifyBug
class TestLaunchpadConnector(unittest.TestCase): class TestLaunchpadConnector(unittest.TestCase):
@ -25,13 +43,13 @@ class TestLaunchpadConnector(unittest.TestCase):
for status in ['Fix Released', 'Fix Committed', 'Invalid']: for status in ['Fix Released', 'Fix Committed', 'Invalid']:
item.status = status item.status = status
self.assertEquals(lp_connector.get_bug_status(1693838), CLOSED) self.assertEqual(lp_connector.get_bug_status(1693838), CLOSED)
item.status = 'No idea' item.status = 'No idea'
self.assertEquals(lp_connector.get_bug_status(1693838), OPEN) self.assertEqual(lp_connector.get_bug_status(1693838), OPEN)
bugs.__getitem__.side_effect = KeyError() bugs.__getitem__.side_effect = KeyError()
self.assertEquals(lp_connector.get_bug_status(1693838), INVALID) self.assertEqual(lp_connector.get_bug_status(1693838), INVALID)
class TestBugzillaConnector(unittest.TestCase): class TestBugzillaConnector(unittest.TestCase):
@ -40,19 +58,19 @@ class TestBugzillaConnector(unittest.TestCase):
bz_connector = BugzillaConnector() bz_connector = BugzillaConnector()
bug = bugzilla_mock.return_value.getbug bug = bugzilla_mock.return_value.getbug
bug.return_value.status = 'CLOSED' bug.return_value.status = 'CLOSED'
self.assertEquals(bz_connector.get_bug_status(123), CLOSED) self.assertEqual(bz_connector.get_bug_status(123), CLOSED)
bz_status = ['ASSIGNED', 'NEEDINFO', 'NEW', 'REOPENED', 'RESOLVED', bz_status = ['ASSIGNED', 'NEEDINFO', 'NEW', 'REOPENED', 'RESOLVED',
'UNCONFIRMED', 'VERIFIRED'] 'UNCONFIRMED', 'VERIFIRED']
for status in bz_status: for status in bz_status:
bug.return_value.status = status bug.return_value.status = status
self.assertEquals(bz_connector.get_bug_status(123), OPEN) self.assertEqual(bz_connector.get_bug_status(123), OPEN)
bug.side_effect = xmlrpclib.Fault(faultCode=102, bug.side_effect = xmlrpclib.Fault(faultCode=102,
faultString='Permission') faultString='Permission')
self.assertEquals(bz_connector.get_bug_status(123), OPEN) self.assertEqual(bz_connector.get_bug_status(123), OPEN)
bug.side_effect = xmlrpclib.Fault(faultCode=42, bug.side_effect = xmlrpclib.Fault(faultCode=42,
faultString='Other fault') faultString='Other fault')
self.assertEquals(bz_connector.get_bug_status(123), INVALID) self.assertEqual(bz_connector.get_bug_status(123), INVALID)
class TestVerifyBug(unittest.TestCase): class TestVerifyBug(unittest.TestCase):
@ -62,9 +80,9 @@ class TestVerifyBug(unittest.TestCase):
self.v_bug = VerifyBug() self.v_bug = VerifyBug()
def test__get_id_from_url(self): def test__get_id_from_url(self):
self.assertEquals(self.v_bug._get_id_from_url( self.assertEqual(self.v_bug._get_id_from_url(
'https://bugs.launchpad.net/tripleo/+bug/1577769'), 1577769) 'https://bugs.launchpad.net/tripleo/+bug/1577769'), 1577769)
self.assertEquals(self.v_bug._get_id_from_url( self.assertEqual(self.v_bug._get_id_from_url(
'https://bugzilla.redhat.com/show_bug.cgi?id=1380187'), 1380187) 'https://bugzilla.redhat.com/show_bug.cgi?id=1380187'), 1380187)
def test__get_connector(self): def test__get_connector(self):
@ -81,11 +99,11 @@ class TestVerifyBug(unittest.TestCase):
def test_is_bug_open(self, bug_status_mock): def test_is_bug_open(self, bug_status_mock):
for status in [CLOSED, INVALID]: for status in [CLOSED, INVALID]:
bug_status_mock.return_value = status bug_status_mock.return_value = status
self.assertEquals(self.v_bug.is_bug_open( self.assertEqual(self.v_bug.is_bug_open(
'https://bugzilla.redhat.com/show_bug.cgi?id=1380187'), False) 'https://bugzilla.redhat.com/show_bug.cgi?id=1380187'), False)
bug_status_mock.return_value = OPEN bug_status_mock.return_value = OPEN
self.assertEquals(self.v_bug.is_bug_open( self.assertEqual(self.v_bug.is_bug_open(
'https://bugzilla.redhat.com/show_bug.cgi?id=1380187'), True) 'https://bugzilla.redhat.com/show_bug.cgi?id=1380187'), True)
@ -150,15 +168,15 @@ class TestBugVerifyCmd(unittest.TestCase):
def test_load_skip_file(self): def test_load_skip_file(self):
known_failures = self.cmd.load_skip_file() known_failures = self.cmd.load_skip_file()
self.assertEquals(known_failures, self.known_failures) self.assertEqual(known_failures, self.known_failures)
def test__print_txt(self): def test__print_txt(self):
output = self.cmd._print_txt(self.known_failures) output = self.cmd._print_txt(self.known_failures)
self.assertEquals(output, self.txt_output) self.assertEqual(output, self.txt_output)
def test__print_yaml(self): def test__print_yaml(self):
output = self.cmd._print_yaml(self.known_failures) output = self.cmd._print_yaml(self.known_failures)
self.assertEquals(output, self.yaml_output) self.assertEqual(output, self.yaml_output)
@mock.patch('bugcheck.BugVerifyCmd._print_txt') @mock.patch('bugcheck.BugVerifyCmd._print_txt')
@mock.patch('bugcheck.BugVerifyCmd._print_yaml') @mock.patch('bugcheck.BugVerifyCmd._print_yaml')
@ -182,7 +200,7 @@ class TestBugVerifyCmd(unittest.TestCase):
'tempest.api.data_processing\n', 'tempest.api.data_processing\n',
'# New test, need investigation\n', '# New test, need investigation\n',
'neutron.tests.tempest.api.test_revisions.TestRevisions\n'] 'neutron.tests.tempest.api.test_revisions.TestRevisions\n']
self.assertEquals(output, expected) self.assertEqual(output, expected)
cmd.save_output(self.known_failures, 'yaml') cmd.save_output(self.known_failures, 'yaml')
output = open(tmp_f, 'r').readlines() output = open(tmp_f, 'r').readlines()
@ -200,5 +218,4 @@ class TestBugVerifyCmd(unittest.TestCase):
'- reason: New test, need investigation\n', '- reason: New test, need investigation\n',
' test: neutron.tests.tempest.api.test_revisions.Tes' ' test: neutron.tests.tempest.api.test_revisions.Tes'
'tRevisions\n'] 'tRevisions\n']
self.assertEquals(output, expected) self.assertEqual(output, expected)

View File

@ -31,8 +31,8 @@ from six.moves.urllib.parse import urljoin
HREF = re.compile('href="([^"]+)"') HREF = re.compile('href="([^"]+)"')
JOBRE = re.compile('[a-z0-9]{7}/') JOBRE = re.compile('[a-z0-9]{7}/')
TESTRE = re.compile('(tempest[^ \(\)]+|\w+\.tests\.[^ \(\)]+)') TESTRE = re.compile(r'(tempest[^ \(\)]+|\w+\.tests\.[^ \(\)]+)')
TIMEST = re.compile('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}):\d{2}\.\d+ \|') TIMEST = re.compile(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}):\d{2}\.\d+ \|')
TITLE = re.compile('<title>(.*?)</title>') TITLE = re.compile('<title>(.*?)</title>')
FAILED = "... FAILED" FAILED = "... FAILED"
@ -386,8 +386,8 @@ class TempestMailCmd(object):
'reason': t.get('reason')}) 'reason': t.get('reason')})
if self.args.skip_file: if self.args.skip_file:
known_failures = (known_failures + known_failures = \
self.load_skip_file(self.args.skip_file)) (known_failures + self.load_skip_file(self.args.skip_file))
newconfig.known_failures = known_failures newconfig.known_failures = known_failures
newconfig.api_server = config.get('api_server') newconfig.api_server = config.get('api_server')

View File

@ -1,8 +1,26 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
import datetime import datetime
import mock import mock
import re
import tempfile import tempfile
import unittest import unittest
import re
from tempestmail import Config from tempestmail import Config
from tempestmail import Mail from tempestmail import Mail
@ -81,32 +99,32 @@ class MailTest(unittest.TestCase):
def test_render_template(self): def test_render_template(self):
mail = Mail(self.config) mail = Mail(self.config)
content = mail.render_template(self.data) content = mail.render_template(self.data)
self.assertEquals(self.render_output, content) self.assertEqual(self.render_output, content)
def test_filter_emails(self): def test_filter_emails(self):
mail = Mail(self.config) mail = Mail(self.config)
self.assertEquals(self.data.get('has_errors'), None) self.assertEqual(self.data.get('has_errors'), None)
addresses = mail.filter_emails( addresses = mail.filter_emails(
'periodic-tripleo-ci-centos-7-ovb-ha-tempest', self.data) 'periodic-tripleo-ci-centos-7-ovb-ha-tempest', self.data)
self.assertEquals({'' : ['email1@example.com', 'email2@example.com']}, self.assertEqual({'': ['email1@example.com', 'email2@example.com']},
addresses) addresses)
mail.config.emails[0]['jobs'].append('another-job') mail.config.emails[0]['jobs'].append('another-job')
addresses = mail.filter_emails( addresses = mail.filter_emails(
'periodic-tripleo-ci-centos-7-ovb-ha-tempest', self.data) 'periodic-tripleo-ci-centos-7-ovb-ha-tempest', self.data)
self.assertEquals({'' : ['email2@example.com']}, addresses) self.assertEqual({'': ['email2@example.com']}, addresses)
self.assertEquals(self.data['has_errors'], True) self.assertEqual(self.data['has_errors'], True)
mail.config.emails[0]['jobs'] = [] mail.config.emails[0]['jobs'] = []
mail.config.emails[0]['regex'].append(re.compile( mail.config.emails[0]['regex'].append(re.compile(
'tempest.some.regex')) 'tempest.some.regex'))
self.assertEquals({'' : ['email2@example.com']}, addresses) self.assertEqual({'': ['email2@example.com']}, addresses)
def test_filter_emails_topics(self): def test_filter_emails_topics(self):
mail = Mail(self.config) mail = Mail(self.config)
addresses = mail.filter_emails( addresses = mail.filter_emails(
'periodic-tripleo-ci-centos-7-ovb-ha-tempest', self.data) 'periodic-tripleo-ci-centos-7-ovb-ha-tempest', self.data)
self.assertEquals({'' : ['email1@example.com', self.assertEqual({'': ['email1@example.com',
'email2@example.com']}, 'email2@example.com']},
addresses) addresses)
mail.config.emails[0]['jobs'].append( mail.config.emails[0]['jobs'].append(
'periodic-tripleo-ci-centos-7-ovb-ha-tempest') 'periodic-tripleo-ci-centos-7-ovb-ha-tempest')
mail.config.emails[0]['regex'].append(re.compile( mail.config.emails[0]['regex'].append(re.compile(
@ -122,11 +140,10 @@ class MailTest(unittest.TestCase):
mail.config.emails.append(new) mail.config.emails.append(new)
addresses = mail.filter_emails( addresses = mail.filter_emails(
'periodic-tripleo-ci-centos-7-ovb-ha-tempest', self.data) 'periodic-tripleo-ci-centos-7-ovb-ha-tempest', self.data)
bookaddr = {'[many_objects]' : ['email1@example.com'], bookaddr = {'[many_objects]': ['email1@example.com'],
'[valid_object]' : ['email2@example.com'], '[valid_object]': ['email2@example.com'],
'[valid_object][object_storage]' : ['email2@example.com'] '[valid_object][object_storage]': ['email2@example.com']}
} self.assertEqual(bookaddr, addresses)
self.assertEquals(bookaddr, addresses)
@mock.patch('tempestmail.Mail._send_mail_api') @mock.patch('tempestmail.Mail._send_mail_api')
@mock.patch('tempestmail.Mail._send_mail_local') @mock.patch('tempestmail.Mail._send_mail_local')
@ -196,26 +213,27 @@ class TestTempestMailCmd(unittest.TestCase):
html_mock.return_value.content.decode.return_value = self.content_job.decode() html_mock.return_value.content.decode.return_value = self.content_job.decode()
index = tmc.get_index() index = tmc.get_index()
self.assertEquals(index, [(u'http://logs.openstack.org/periodic/perio' self.assertEqual(
'dic-tripleo-ci-centos-7-ovb-nonha-tempest-' index,
'oooq-master/613de4e/')]) [(u'http://logs.openstack.org/periodic/periodic-tripleo-ci'
'-centos-7-ovb-nonha-tempest-oooq-master/613de4e/')])
html_mock.return_value.content.decode.return_value = 'No links' html_mock.return_value.content.decode.return_value = 'No links'
index = tmc.get_index() index = tmc.get_index()
self.assertEquals(index, []) self.assertEqual(index, [])
html_mock.return_value = None html_mock.return_value = None
index = tmc.get_index() index = tmc.get_index()
self.assertEquals(index, []) self.assertEqual(index, [])
html_mock.ok.return_value = None html_mock.ok.return_value = None
index = tmc.get_index() index = tmc.get_index()
self.assertEquals(index, []) self.assertEqual(index, [])
html_mock.ok.return_value = True html_mock.ok.return_value = True
html_mock.content.return_value = None html_mock.content.return_value = None
index = tmc.get_index() index = tmc.get_index()
self.assertEquals(index, []) self.assertEqual(index, [])
@mock.patch('tempestmail.get_html') @mock.patch('tempestmail.get_html')
def test_get_console(self, html_mock): def test_get_console(self, html_mock):
@ -228,30 +246,30 @@ class TestTempestMailCmd(unittest.TestCase):
tmc.setupConfig() tmc.setupConfig()
console, date, log_path = tmc.get_console() console, date, log_path = tmc.get_console()
self.assertEquals(console, self.console_ok) self.assertEqual(console, self.console_ok)
self.assertEquals(log_path, None) self.assertEqual(log_path, None)
tmc.parse_arguments(['-c', 'tests/fixtures/config.yaml', '--job', tmc.parse_arguments(['-c', 'tests/fixtures/config.yaml', '--job',
'periodic-tripleo-ci-centos-7-ovb-nonha-tempest-' 'periodic-tripleo-ci-centos-7-ovb-nonha-tempest-'
'oooq-master', '--file', 'oooq-master', '--file',
'tests/fixtures/not_found.log']) 'tests/fixtures/not_found.log'])
self.assertEquals(tmc.get_console(), (None, None, None)) self.assertEqual(tmc.get_console(), (None, None, None))
html_mock.return_value.status_code = '300' html_mock.return_value.status_code = '300'
result = tmc.get_console(job_url='http://logs.openstack.org') result = tmc.get_console(job_url='http://logs.openstack.org')
self.assertEquals(result, (None, None, None)) self.assertEqual(result, (None, None, None))
html_mock.return_value.status_code = '200' html_mock.return_value.status_code = '200'
html_mock.return_value.content = self.console_ok html_mock.return_value.content = self.console_ok
console, date, url = tmc.get_console( console, date, url = tmc.get_console(
job_url='http://logs.openstack.org') job_url='http://logs.openstack.org')
self.assertEquals(console, self.console_ok.decode('utf-8')) self.assertEqual(console, self.console_ok.decode('utf-8'))
self.assertEquals(url, 'http://logs.openstack.org/console.html.gz') self.assertEqual(url, 'http://logs.openstack.org/console.html.gz')
html_mock.return_value = None html_mock.return_value = None
result = tmc.get_console(job_url='http://logs.openstack.org') result = tmc.get_console(job_url='http://logs.openstack.org')
self.assertEquals(result, (None, None, None)) self.assertEqual(result, (None, None, None))
def test_get_data(self): def test_get_data(self):
tmc = TempestMailCmd() tmc = TempestMailCmd()
@ -264,24 +282,24 @@ class TestTempestMailCmd(unittest.TestCase):
data = tmc.get_data(self.console_ok, None, 'http://logs.openstack.org') data = tmc.get_data(self.console_ok, None, 'http://logs.openstack.org')
self.assertEquals( self.assertEqual(
data['job'], data['job'],
'periodic-tripleo-ci-centos-7-ovb-nonha-tempest-oooq-master') 'periodic-tripleo-ci-centos-7-ovb-nonha-tempest-oooq-master')
self.assertEquals(data['date'], None) self.assertEqual(data['date'], None)
self.assertEquals(data['run'], True) self.assertEqual(data['run'], True)
self.assertEquals(data['link'], 'http://logs.openstack.org') self.assertEqual(data['link'], 'http://logs.openstack.org')
self.assertEquals(len(data['ok']), 2) self.assertEqual(len(data['ok']), 2)
self.assertEquals(data.get('failed'), None) self.assertEqual(data.get('failed'), None)
self.assertEquals(data.get('covered'), None) self.assertEqual(data.get('covered'), None)
self.assertEquals(data.get('new'), None) self.assertEqual(data.get('new'), None)
self.assertEquals(data.get('errors'), None) self.assertEqual(data.get('errors'), None)
data = tmc.get_data('some content', None, 'http://logs.openstack.org') data = tmc.get_data('some content', None, 'http://logs.openstack.org')
self.assertEquals(data['run'], False) self.assertEqual(data['run'], False)
data = tmc.get_data(self.console_fail, None, data = tmc.get_data(self.console_fail, None,
'http://logs.openstack.org') 'http://logs.openstack.org')
self.assertNotEquals(data['failed'], None) self.assertNotEqual(data['failed'], None)
def test_load_skip_file(self): def test_load_skip_file(self):
tmc = TempestMailCmd() tmc = TempestMailCmd()
@ -303,14 +321,14 @@ class TestTempestMailCmd(unittest.TestCase):
{'test': 'neutron.tests.tempest.api.test_revisions.TestRevisions', {'test': 'neutron.tests.tempest.api.test_revisions.TestRevisions',
'reason': 'New test, need investigation'} 'reason': 'New test, need investigation'}
] ]
self.assertEquals(result, expected) self.assertEqual(result, expected)
tmc.parse_arguments(['-c', 'tests/fixtures/config.yaml', '--job', tmc.parse_arguments(['-c', 'tests/fixtures/config.yaml', '--job',
'periodic-tripleo-ci-centos-7-ovb-nonha-tempest-' 'periodic-tripleo-ci-centos-7-ovb-nonha-tempest-'
'oooq-master', '--file', 'oooq-master', '--file',
'tests/fixtures/not_found.log', '--skip-file', 'tests/fixtures/not_found.log', '--skip-file',
'non_exist_file.txt']) 'non_exist_file.txt'])
result = tmc.load_skip_file(self.tmp_file) result = tmc.load_skip_file(self.tmp_file)
self.assertEquals(result, []) self.assertEqual(result, [])
def test_setup_config(self): def test_setup_config(self):
tmc = TempestMailCmd() tmc = TempestMailCmd()
@ -323,14 +341,14 @@ class TestTempestMailCmd(unittest.TestCase):
tmc.setupConfig() tmc.setupConfig()
config = tmc.config config = tmc.config
self.assertEquals(config.require_auth, True) self.assertEqual(config.require_auth, True)
self.assertEquals(config.mail_from, 'tripleoresults@gmail.com') self.assertEqual(config.mail_from, 'tripleoresults@gmail.com')
self.assertEquals(config.templates_path, 'template/') self.assertEqual(config.templates_path, 'template/')
self.assertEquals( self.assertEqual(
config.log_url, config.log_url,
'http://logs.openstack.org/periodic/') 'http://logs.openstack.org/periodic/')
self.assertEquals( self.assertEqual(
config.api_server, config.api_server,
'http://tempest-tripleoci.rhcloud.com/api/v1.0/sendmail') 'http://tempest-tripleoci.rhcloud.com/api/v1.0/sendmail')
self.assertEquals(config.use_api_server, True) self.assertEqual(config.use_api_server, True)
self.assertEquals(config.default_log_url, 'http://logs.openstack.org') self.assertEqual(config.default_log_url, 'http://logs.openstack.org')

View File

@ -1,5 +1,4 @@
openstackdocstheme>=1.11.0 # Apache-2.0 openstackdocstheme>=1.11.0 # Apache-2.0
hacking<0.11,>=0.10
pre-commit>=1.10 # MIT License pre-commit>=1.10 # MIT License
ansible-lint>=3.5.0 ansible-lint>=3.5.0

14
tox.ini
View File

@ -26,18 +26,9 @@ commands =
python -m pre_commit run bashate --all-files python -m pre_commit run bashate --all-files
[testenv:pep8] [testenv:pep8]
envdir = {toxworkdir}/linters
commands = commands =
# Run hacking/flake8 check for all python files python -m pre_commit run flake8 --all-files
bash -c "grep --recursive --binary-files=without-match \
--files-with-match '^.!.*python$' \
--exclude-dir .tox \
--exclude-dir .git \
--exclude-dir .eggs \
--exclude-dir *.egg-info \
--exclude-dir dist \
--exclude-dir *lib/python* \
--exclude-dir doc \
{toxinidir} | xargs flake8 --verbose"
[testenv:ansible-lint] [testenv:ansible-lint]
basepython=python2 basepython=python2
@ -54,7 +45,6 @@ commands =
python -m pre_commit run --source HEAD^ --origin HEAD python -m pre_commit run --source HEAD^ --origin HEAD
# in the future we may want to check entire repository: # in the future we may want to check entire repository:
# python -m pre_commit run yamllint --all-files # python -m pre_commit run yamllint --all-files
{[testenv:pep8]commands}
{[testenv:ansible-lint]commands} {[testenv:ansible-lint]commands}
{[testenv:validate-jinja]commands} {[testenv:validate-jinja]commands}