summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2012-11-26 14:22:37 +0100
committerMartin Sivak <msivak@redhat.com>2012-11-26 14:22:37 +0100
commit7ce2995ee6cab68d1f171b4d050ffb543185def3 (patch)
treee26fd98a77f7ff5c52066984e8d43c63d6213c0c
parent402715358322359b43b90a460ea43cce35a0122f (diff)
downloadpython-di-7ce2995ee6cab68d1f171b4d050ffb543185def3.tar.gz
python-di-7ce2995ee6cab68d1f171b4d050ffb543185def3.tar.xz
python-di-7ce2995ee6cab68d1f171b4d050ffb543185def3.zip
SPEC file cleanup and move to nosetests
-rw-r--r--di/core_test.py89
-rw-r--r--python-di.spec4
-rw-r--r--setup.py24
3 files changed, 104 insertions, 13 deletions
diff --git a/di/core_test.py b/di/core_test.py
new file mode 100644
index 0000000..17d88fa
--- /dev/null
+++ b/di/core_test.py
@@ -0,0 +1,89 @@
+from .core import *
+import unittest
+
+
+class BareFuncEnableTestCase(unittest.TestCase):
+ @inject(injected_func = str.lower)
+ def method(self, arg):
+ return injected_func(arg)
+
+class BareFuncTestCase(unittest.TestCase):
+ @inject(injected_func = str.lower)
+ def method(self, arg):
+ return injected_func(arg)
+
+ @inject(injected_func = method)
+ def method2(self, arg):
+ return injected_func(self, arg)
+
+ def test_bare_inject(self):
+ """Tests the injection to plain methods."""
+ self.assertEqual("a", self.method("A"))
+
+ def test_double_inject(self):
+ """Tests the injection to two plain methods."""
+ self.assertEqual("a", self.method2("A"))
+
+ def test_inject_global_tainting(self):
+ """Tests whether the global namespace is clean
+ after the injection is done."""
+ global injected_func
+ injected_func = None
+ self.method("A")
+ self.assertEqual(None, injected_func)
+
+
+@inject(injected_func = str.lower)
+class Test(object):
+ """Test fixture for class injection."""
+ @usesclassinject
+ def method(self, arg):
+ return injected_func(arg)
+
+
+@inject(injected_func = str.lower)
+class TestInit(object):
+ """Test fixture for injection to __init__."""
+ @usesclassinject
+ def __init__(self, arg):
+ self.value = injected_func(arg)
+
+
+@inject(injected_func = str.lower)
+class TestCallable(object):
+ """Test fixture for callable classes."""
+ @usesclassinject
+ def __call__(self, arg):
+ return injected_func(arg)
+
+class TestCallableSingle(object):
+ """Test fixture for callable classes with
+ simple method injection."""
+ @inject(injected_func = str.lower)
+ def __call__(self, arg):
+ return injected_func(arg)
+
+class ClassDITestCase(unittest.TestCase):
+
+ def test_class_inject(self):
+ """Test injection to instance method."""
+ obj = Test()
+ self.assertEqual("a", obj.method("A"))
+
+ def test_class_init_inject(self):
+ """Test injection to class constructor."""
+ obj = TestInit("A")
+ self.assertEqual("a", obj.value)
+
+ def test_callable_class(self):
+ """Test class injection to callable class."""
+ obj = TestCallable()
+ self.assertEqual("a", obj("A"))
+
+ def test_callable_class_single(self):
+ """Test method injection to callable class."""
+ obj = TestCallableSingle()
+ self.assertEqual("a", obj("A"))
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/python-di.spec b/python-di.spec
index f8d74c9..a5034d5 100644
--- a/python-di.spec
+++ b/python-di.spec
@@ -18,7 +18,7 @@ URL: http://fedorapeople.org/cgit/msivak/public_git/python-di.git/
Source0: http://pypi.python.org/packages/source/d/di/di-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-#BuildRequires:
+BuildRequires: python-nose
#Requires:
BuildArch: noarch
@@ -40,7 +40,7 @@ It is intended to be used in unit testing environments.
rm -rf ${buildroot}%{python_sitelib}/setuptools/tests
%check
-%{__python} setup.py test
+%{__python} setup.py nosetests
%clean
rm -rf $RPM_BUILD_ROOT
diff --git a/setup.py b/setup.py
index 2f1a99c..4008561 100644
--- a/setup.py
+++ b/setup.py
@@ -15,15 +15,17 @@ setup(
author_email = "msivak@redhat.com",
description = ("Python module which provides decorators to make "
"dependency injection easy to use."),
- license = "GPLv2+",
- keywords = "testing dependency injection IoC",
- url = "http://fedorapeople.org/cgit/msivak/public_git/python-di.git/",
- packages = ['di'],
- long_description=read('README'),
- classifiers=[
- "Development Status :: 3 - Alpha",
- "Intended Audience :: Developers",
- "Topic :: Software Development :: Testing",
- "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
- ],
+ license = "GPLv2+",
+ keywords = "testing dependency injection IoC",
+ url = "http://fedorapeople.org/cgit/msivak/public_git/python-di.git/",
+ packages = ['di'],
+ setup_requires= ['nose>=1.0'],
+ test_suite = "di",
+ long_description=read('README'),
+ classifiers=[
+ "Development Status :: 3 - Alpha",
+ "Intended Audience :: Developers",
+ "Topic :: Software Development :: Testing",
+ "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
+ ],
)