Bump dev status

Shouldn't be considered pre-release anymore

Also fixed pep8 test.

Change-Id: I9ad41ce6e60736a944af4195542c409f59e110b2
This commit is contained in:
Monsyne Dragon 2015-08-17 22:41:49 +00:00
parent 8ff276f548
commit f5bc8c2a13
4 changed files with 30 additions and 16 deletions

View File

@ -1,13 +1,13 @@
[metadata] [metadata]
name = simport name = simport
version = 0.2 version = 0.3
author = Dark Secret Software Inc. author = Dark Secret Software Inc.
author-email = admin@darksecretsoftware.com author-email = admin@darksecretsoftware.com
summary = simple import with python path management summary = simple import with python path management
description-file = README.md description-file = README.md
license = Apache-2 license = Apache-2
classifier = classifier =
Development Status :: 3 - Alpha Development Status :: 5 - Production/Stable
Environment :: Console Environment :: Console
Intended Audience :: Developers Intended Audience :: Developers
Intended Audience :: Information Technology Intended Audience :: Information Technology

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import imp
import logging import logging
import os import os
import os.path import os.path
@ -76,13 +75,15 @@ def _get_module(target):
sys.path.append(filepath) sys.path.append(filepath)
if not class_or_function: 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: if module:
try: try:
__import__(module) __import__(module)
except ImportError as e: except ImportError as e:
raise ImportFailed("Failed to import '%s'. Error: %s" % (module, e)) raise ImportFailed("Failed to import '%s'. "
"Error: %s" % (module, e))
klass, sep, function = class_or_function.rpartition('.') klass, sep, function = class_or_function.rpartition('.')
return module, klass, function return module, klass, function
@ -94,7 +95,8 @@ def load(target, source_module=None):
if not module and source_module: if not module and source_module:
module = source_module module = source_module
if not 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] actual_module = sys.modules[module]
if not klass: if not klass:
return getattr(actual_module, function) return getattr(actual_module, function)

View File

@ -41,21 +41,21 @@ class TestSimport(unittest.TestCase):
def test_good_external_targets(self): def test_good_external_targets(self):
self.assertEquals(("localmodule", "Foo", "method_a"), self.assertEquals(("localmodule", "Foo", "method_a"),
simport._get_module("tests|" simport._get_module("tests|"
"localmodule:Foo.method_a")) "localmodule:Foo.method_a"))
self.assertRaises(simport.ImportFailed, simport._get_module, self.assertRaises(simport.ImportFailed, simport._get_module,
"tests|that_module:function_a") "tests|that_module:function_a")
def test_bad_load(self): def test_bad_load(self):
self.assertRaises(AttributeError, simport.load, self.assertRaises(AttributeError, simport.load,
"test_simport:missing") "test_simport:missing")
def test_good_load_internal(self): def test_good_load_internal(self):
self.assertEquals(dummy_function, self.assertEquals(dummy_function,
simport.load("test_simport:dummy_function")) simport.load("test_simport:dummy_function"))
self.assertEquals(DummyClass.method_a, self.assertEquals(DummyClass.method_a,
simport.load("test_simport:DummyClass.method_a")) simport.load("test_simport:DummyClass.method_a"))
def test_good_load_local(self): def test_good_load_local(self):
method = simport.load("tests|" method = simport.load("tests|"
@ -63,11 +63,11 @@ class TestSimport(unittest.TestCase):
import localmodule import localmodule
self.assertEquals(method, localmodule.Foo.method_a) self.assertEquals(method, localmodule.Foo.method_a)
self.assertEquals(localmodule.function_a, self.assertEquals(localmodule.function_a,
simport.load("localmodule:function_a")) simport.load("localmodule:function_a"))
def test_good_load_external(self): def test_good_load_external(self):
method = simport.load("tests/external|" method = simport.load("tests/external|"
"external.externalmodule:Blah.method_b") "external.externalmodule:Blah.method_b")
self.assertTrue('external.externalmodule' in sys.modules) self.assertTrue('external.externalmodule' in sys.modules)
old = sys.modules['external.externalmodule'] old = sys.modules['external.externalmodule']
@ -80,7 +80,7 @@ class TestSimport(unittest.TestCase):
def test_import_class(self): def test_import_class(self):
klass = simport.load("tests/external|" klass = simport.load("tests/external|"
"external.externalmodule:Blah") "external.externalmodule:Blah")
import external.externalmodule import external.externalmodule
self.assertEqual(klass, external.externalmodule.Blah) self.assertEqual(klass, external.externalmodule.Blah)

16
tox.ini
View File

@ -1,10 +1,22 @@
[tox] [tox]
envlist = py26, py27 envlist = py26,py27,pep8
[testenv] [testenv]
deps = deps =
coverage coverage
nose nose
mock mock
flake8
setenv = VIRTUAL_ENV={envdir}
commands = nosetests -d -v --with-coverage --cover-inclusive --cover-package simport [] commands = nosetests -d -v --with-coverage --cover-inclusive --cover-package simport []
[testenv:pep8]
commands =
flake8
[flake8]
ignore = H405
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,timex/__init__.py
show-source = True