Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-battery: pycodestyle #2128

Merged
merged 4 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ install:
- sudo apt-get install python-pip python-dev graphviz libgraphviz-dev python-jinja2 python-sqlalchemy
- pip install cherrypy Jinja2 requests simplejson sqlalchemy pyopenssl
- pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/"
- pip install pep8
- pip install pycodestyle
- sudo sh -c 'echo "deb http://opensource.wandisco.com/ubuntu `lsb_release -cs` svn19" >> /etc/apt/sources.list.d/subversion19.list'
- sudo wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | sudo apt-key add -
- sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion lib/python/rose/apps/rose_ana_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def execute_sql_retry(self, conn, sql_args, retries=10, timeout=5.0):
try:
conn.execute(*sql_args)
return
except:
except sqlite3.Error:
time.sleep(timeout)
# In the event that the retries are exceeded, re-raise the final
# exception for the calling application to handle
Expand Down
2 changes: 1 addition & 1 deletion lib/python/rose/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def main():
if opts.keys_mode:
try:
keys = root_node.get(args, opts.no_ignore).value.keys()
except:
except AttributeError:
sys.exit(1)
keys.sort()
for key in keys:
Expand Down
2 changes: 1 addition & 1 deletion lib/python/rose/gtk/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def run_dialog(dialog_type, text, title=None, modal=True,
except glib.GError:
try:
dialog.label.set_markup(rose.gtk.util.safe_str(text))
except:
except Exception:
dialog.label.set_text(text)
else:
dialog.label.set_markup(text)
Expand Down
1 change: 1 addition & 0 deletions lib/python/rose/gtk/splash.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def _update_splash_screen(self, update_input):
*update_input["args"], **update_input["kwargs"])
return False


if __name__ == "__main__":
sys.path.append(os.getenv('ROSE_HOME'))
splash_screen = SplashScreen(*sys.argv[1:])
Expand Down
2 changes: 1 addition & 1 deletion lib/python/rose/meta_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,5 @@ def meta_type_transform(value, meta_type):
c = c()
try:
return c.transform(value)
except:
except Exception:
return False
1 change: 1 addition & 0 deletions lib/python/rose/metadata_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,5 +385,6 @@ def main():
sys.exit(1)
reporter(rose.macro.MacroFinishNothingEvent(), level=reporter.V)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions lib/python/rose/metadata_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,6 @@ def main():
dest_file = os.path.join(dest, rose.META_CONFIG_NAME)
rose.config.dump(metadata_config, dest_file)


if __name__ == "__main__":
main()
6 changes: 4 additions & 2 deletions lib/python/rose/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class ReporterContext(object):
"""

TTY_COLOUR_ERR = "\033[1;31m"
TTY_COLOUR_NORM = "\033[0m"

def __init__(self,
kind=None,
Expand Down Expand Up @@ -262,8 +263,9 @@ def write(self, message):
def _tty_colour_err(self, s):
try:
if self.handle.isatty():
return self.TTY_COLOUR_ERR + s + "\033[0m"
except:
return "%s%s%s" % (self.TTY_COLOUR_ERR, s,
self.TTY_COLOUR_NORM)
except AttributeError:
pass
return s

Expand Down
8 changes: 4 additions & 4 deletions lib/python/rose/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def run(self, opts, args):
finally:
# Close handle on specific log file
try:
self.event_handler.contexts.get(uuid).handle.close()
except:
self.event_handler.contexts[uuid].handle.close()
except (KeyError, IOError, AttributeError):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly TypeError as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see how.

pass
# Remove work files
for work_file in work_files:
Expand All @@ -212,12 +212,12 @@ def run(self, opts, args):
os.unlink(work_file)
elif os.path.isdir(work_file):
shutil.rmtree(work_file)
except:
except OSError:
pass
# Change back to original working directory
try:
os.chdir(cwd)
except:
except OSError:
pass
# Reset os.environ
os.environ = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/python/rosie/browser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def set_show_controls(self):
try:
if self.adv_control_menuitem.get_active() != self.adv_controls_on:
self.adv_control_menuitem.set_active(self.adv_controls_on)
except:
except Exception:
pass
for child in self.filter_table.get_children():
if isinstance(child, rosie.browser.util.BracketWidget):
Expand Down
1 change: 1 addition & 0 deletions lib/python/rosie/db_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,6 @@ def main():
repos_path = conf.get_value(["rosie-db", "repos." + prefix])
init(db_url, repos_path)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion lib/python/rosie/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def index(self, *_):
"""Provide the index page."""
try:
return self._render()
except:
except (KeyError, AttributeError, jinja2.exceptions.TemplateError):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jinja2.exceptions.TemplateError might be sufficient here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely. The client will get a 500 in the worst case.

import traceback
traceback.print_exc()

Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions t/syntax/02-pycodestyle.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
#-------------------------------------------------------------------------------
# (C) British Crown Copyright 2012-7 Met Office.
#
# This file is part of Rose, a framework for meteorological suites.
#
# Rose is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rose is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rose. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
. "$(dirname "$0")/test_header"

if ! pycodestyle --version 1>'/dev/null' 2>&1; then
skip_all '"pycodestyle" command not available'
fi

tests 3

run_pass "${TEST_KEY_BASE}" \
pycodestyle --ignore=E402,E731 \
"${ROSE_HOME}/lib/python/isodatetime" \
"${ROSE_HOME}/lib/python/rose" \
"${ROSE_HOME}/lib/python/rosie"
file_cmp "${TEST_KEY_BASE}.out" "${TEST_KEY_BASE}.out" <'/dev/null'
file_cmp "${TEST_KEY_BASE}.err" "${TEST_KEY_BASE}.err" <'/dev/null'

exit