From b0caa4113873725c37744348f0a6413386cde147 Mon Sep 17 00:00:00 2001 From: Levi Blackstone Date: Tue, 5 May 2015 09:10:26 -0500 Subject: [PATCH] Add PEP8 check and fix related issues - Add PEP8 section to tox.ini - Add requirements.txt - Add hacking to requirements to enforce OpenStack style requirements - Fix formatting issues flagged by flake8 check - Add copyright notices to all remaining files - Update .gitignore file Change-Id: I82cd4377d5eaded1a39fe0349105582fd42779d1 --- .gitignore | 5 +++++ requirements.txt | 1 + simport/__init__.py | 8 +++---- tests/external/externalmodule.py | 16 ++++++++++++++ tests/localmodule.py | 16 ++++++++++++++ tests/test_simport.py | 37 +++++++++++++++++++++++--------- tox.ini | 4 +--- 7 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index ded6067..28ae24b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,8 @@ nosetests.xml .mr.developer.cfg .project .pydevproject + +# IDE Project Files +*.project +*.pydev* +*.idea diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..281cc79 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +hacking>=0.10.0,<0.11 diff --git a/simport/__init__.py b/simport/__init__.py index 6ba2c98..a829f1a 100644 --- a/simport/__init__.py +++ b/simport/__init__.py @@ -75,8 +75,8 @@ def _get_module(target): sys.path.append(filepath) if not class_or_function: - raise MissingMethodOrFunction("No Method or Function specified in " - "'%s'" % target) + raise MissingMethodOrFunction( + "No Method or Function specified in '%s'" % target) if module: try: @@ -95,8 +95,8 @@ def load(target, source_module=None): if not module and source_module: module = source_module if not module: - raise MissingModule("No module name supplied or " - "source_module provided.") + raise MissingModule( + "No module name supplied or source_module provided.") actual_module = sys.modules[module] if not klass: return getattr(actual_module, function) diff --git a/tests/external/externalmodule.py b/tests/external/externalmodule.py index 10c745c..27d071c 100644 --- a/tests/external/externalmodule.py +++ b/tests/external/externalmodule.py @@ -1,3 +1,19 @@ +# Copyright (c) 2014 Dark Secret Software Inc. +# +# 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. + + class Foo(object): def method_a(self, a, b, c, d): pass diff --git a/tests/localmodule.py b/tests/localmodule.py index 33f179a..2b6993c 100644 --- a/tests/localmodule.py +++ b/tests/localmodule.py @@ -1,3 +1,19 @@ +# Copyright (c) 2014 Dark Secret Software Inc. +# +# 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. + + class Foo(object): def method_a(self, a, b, c, d): pass diff --git a/tests/test_simport.py b/tests/test_simport.py index 1c745dd..35d4e42 100644 --- a/tests/test_simport.py +++ b/tests/test_simport.py @@ -1,3 +1,18 @@ +# Copyright (c) 2014 Dark Secret Software Inc. +# +# 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. + import sys import unittest @@ -40,9 +55,9 @@ class TestSimport(unittest.TestCase): self.assertFalse("AnyModuleName" in sys.modules) def test_good_external_targets(self): - self.assertEquals(("localmodule", "Foo", "method_a"), - simport._get_module("tests|" - "localmodule:Foo.method_a")) + self.assertEqual(("localmodule", "Foo", "method_a"), + simport._get_module("tests|" + "localmodule:Foo.method_a")) self.assertRaises(simport.ImportFailed, simport._get_module, "tests|that_module:function_a") @@ -52,18 +67,19 @@ class TestSimport(unittest.TestCase): "test_simport:missing") def test_good_load_internal(self): - self.assertEquals(dummy_function, - simport.load("test_simport:dummy_function")) - self.assertEquals(DummyClass.method_a, - simport.load("test_simport:DummyClass.method_a")) + self.assertEqual(dummy_function, + simport.load("test_simport:dummy_function")) + self.assertEqual(DummyClass.method_a, + simport.load("test_simport:DummyClass.method_a")) def test_good_load_local(self): method = simport.load("tests|" "localmodule:Foo.method_a") import localmodule - self.assertEquals(method, localmodule.Foo.method_a) - self.assertEquals(localmodule.function_a, - simport.load("localmodule:function_a")) + + self.assertEqual(method, localmodule.Foo.method_a) + self.assertEqual(localmodule.function_a, + simport.load("localmodule:function_a")) def test_good_load_external(self): method = simport.load("tests/external|" @@ -82,6 +98,7 @@ class TestSimport(unittest.TestCase): klass = simport.load("tests/external|" "external.externalmodule:Blah") import external.externalmodule + self.assertEqual(klass, external.externalmodule.Blah) def test_local_class(self): diff --git a/tox.ini b/tox.ini index bf285bd..c443f47 100644 --- a/tox.ini +++ b/tox.ini @@ -3,12 +3,10 @@ envlist = py26,py27,pep8 [testenv] deps = + -r{toxinidir}/requirements.txt coverage nose mock - flake8 - -setenv = VIRTUAL_ENV={envdir} commands = nosetests -d -v --with-coverage --cover-inclusive --cover-package simport []