grim/pyscovery

got all the unittests working again

2013-03-29, Gary Kramlich
e79b8a133fa5
Parents 2205d2b30dbd
Children adda7018de02
got all the unittests working again
--- a/setup.py Fri Mar 29 01:49:53 2013 -0500
+++ b/setup.py Fri Mar 29 01:58:36 2013 -0500
@@ -27,15 +27,23 @@
modules and optionally use the file system to recurse into packages.
"""
-setup(
- name='pyscovery',
- version=__version__,
- description=DESC,
- py_modules=['pyscovery'],
- zip_safe=True,
- test_suite='nose.collector',
- author='Gary Kramlich',
- author_email='grim@reaperworld.com',
- url='http://www.bitbucket.org/rw_grim/pyplugin',
-)
+def main():
+ """ Main function to create our package """
+ setup(
+ name='pyscovery',
+ version=__version__,
+ description=DESC,
+ py_modules=['pyscovery'],
+ zip_safe=True,
+ test_suite='tests',
+ author='Gary Kramlich',
+ author_email='grim@reaperworld.com',
+ url='http://www.bitbucket.org/rw_grim/pyplugin',
+ )
+
+
+if __name__ == '__main__':
+ main()
+
+
\ No newline at end of file
--- a/tests/modules/deep/__init__.py Fri Mar 29 01:49:53 2013 -0500
+++ b/tests/modules/deep/__init__.py Fri Mar 29 01:58:36 2013 -0500
@@ -19,7 +19,7 @@
to test deep recursion
"""
-from tests import Plugin
+from tests.pyscovery_test import Plugin
class DeepRecursion(Plugin): # pylint:disable-msg=R0903
--- a/tests/modules/deep/deeper.py Fri Mar 29 01:49:53 2013 -0500
+++ b/tests/modules/deep/deeper.py Fri Mar 29 01:58:36 2013 -0500
@@ -19,7 +19,7 @@
to test deep recursion
"""
-from tests import Plugin
+from tests.pyscovery_test import Plugin
class DeeperRecursion(Plugin): # pylint:disable-msg=R0903
--- a/tests/modules/mixed.py Fri Mar 29 01:49:53 2013 -0500
+++ b/tests/modules/mixed.py Fri Mar 29 01:58:36 2013 -0500
@@ -20,7 +20,7 @@
import abc
-from tests import Plugin
+from tests.pyscovery_test import Plugin
CONSTANT = 3.14
--- a/tests/modules/multiple.py Fri Mar 29 01:49:53 2013 -0500
+++ b/tests/modules/multiple.py Fri Mar 29 01:58:36 2013 -0500
@@ -18,7 +18,7 @@
A module with multiple plugins
"""
-from tests import Plugin
+from tests.pyscovery_test import Plugin
class First(Plugin): # pylint:disable-msg=R0903
"""
--- a/tests/modules/single.py Fri Mar 29 01:49:53 2013 -0500
+++ b/tests/modules/single.py Fri Mar 29 01:58:36 2013 -0500
@@ -18,7 +18,7 @@
Plugins in a module
"""
-from tests import Plugin
+from tests.pyscovery_test import Plugin
class Single(Plugin): # pylint:disable-msg=R0903
"""
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/pyscovery_test.py Fri Mar 29 01:58:36 2013 -0500
@@ -0,0 +1,231 @@
+# pyscovery - A python plugin finder
+# Copyright (C) 2013 Gary Kramlich <grim@reaperworld.com>
+#
+# This program 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.
+#
+# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+Unit tests for pyscovery
+"""
+
+import inspect
+import unittest
+
+import pyscovery
+
+
+def _test_module(test, module, count, recurse=False):
+ """
+ Given a module, test that we find count plugins
+ """
+
+ pyscovery.add_module(module)
+
+ gen = pyscovery.find(Plugin, recurse=recurse)
+ test.assertTrue(inspect.isgenerator(gen))
+
+ found = list(gen)
+ test.assertEqual(len(found), count, 'plugins found: {}'.format(found))
+
+
+def _test_module_count(test, count):
+ """
+ Asserts if the number of paths doesn't match count
+ """
+
+ modules = pyscovery.get_modules()
+ test.assertEqual(len(modules), count, 'search paths {}'.format(modules))
+
+
+class Plugin(object): # pylint:disable-msg=R0903
+ """
+ The class all the test plugins descend from
+ """
+
+ pass
+
+
+class TestModules(unittest.TestCase): # pylint:disable-msg=R0904
+ """
+ Unit tests for path manipulation
+ """
+
+ module = 'test'
+
+
+ def setUp(self): # pylint:disable-msg=C0103
+ pyscovery.clear_modules()
+
+
+ def tearDown(self): # pylint:disable-msg=C0103
+ _test_module_count(self, 0)
+ pyscovery.clear_modules()
+
+
+ def test_add_remove(self):
+ """
+ Add and remove a single plugin path
+ """
+
+ pyscovery.add_module(TestModules.module)
+ _test_module_count(self, 1)
+ pyscovery.remove_module(TestModules.module)
+
+
+ def test_add_existing(self):
+ """
+ Add the same plugin path twice, and make sure it's only in there once
+ """
+
+ pyscovery.add_module(TestModules.module)
+ pyscovery.add_module(TestModules.module)
+ _test_module_count(self, 1)
+
+ pyscovery.remove_module(TestModules.module)
+
+
+ def test_remove_nonexistant(self): # pylint:disable-msg=R0201
+ """
+ Try to remove a non-existant plugin path
+ """
+
+ pyscovery.remove_module(TestModules.module)
+
+
+ def test_add_multiple(self):
+ """
+ Add multiple paths to the search paths
+ """
+
+ second = '{}.1'.format(TestModules.module)
+
+ pyscovery.add_module(TestModules.module)
+ _test_module_count(self, 1)
+
+ pyscovery.add_module(second)
+ _test_module_count(self, 2)
+
+ pyscovery.remove_module(TestModules.module)
+ pyscovery.remove_module(second)
+
+
+class TestFind(unittest.TestCase): # pylint:disable-msg=R0904
+ """
+ Basic tests for the find function
+ """
+
+ def test_none(self):
+ """
+ Test that a TypeError is raised when find is called with None
+ """
+
+ self.assertRaises(TypeError, pyscovery.find(None))
+
+
+ def test_string(self):
+ """
+ Test that a TypeError is raised when find is called with a string
+ """
+
+ self.assertRaises(TypeError, pyscovery.find(''))
+
+
+ def test_int(self):
+ """
+ Test that a TypeError is raised when find is called with an int
+ """
+
+ self.assertRaises(TypeError, pyscovery.find(0))
+
+
+ def test_old_style_class(self): # pylint:disable-msg=R0201
+ """
+ Test that a TypeError is NOT raised when find is called with an old
+ style class
+ """
+
+ class Test: # pylint:disable-msg=R0903,W0232
+ """ old style class """
+ pass
+
+
+ pyscovery.find(Test)
+
+
+ def test_new_style_class(self): # pylint:disable-msg=R0201
+ """
+ Test that a TypeError is NOT raised when find is called with an new
+ style class
+ """
+
+ class Test(object): # pylint:disable-msg=R0903
+ """ new style class """
+ pass
+
+
+ pyscovery.find(Test)
+
+
+class TestModule(unittest.TestCase): # pylint:disable-msg=R0904
+ """ Tests the discovery method of pyscovery """
+
+
+ def setUp(self): # pylint:disable-msg=C0103
+ pyscovery.clear_modules()
+
+
+ def tearDown(self): # pylint:disable-msg=C0103
+ pyscovery.clear_modules()
+
+
+ def test_single(self):
+ """ Test a module with a single plugin """
+ _test_module(self, 'tests.modules.single', 1)
+
+
+ def test_multiple(self):
+ """ Test a module with multiple plugins """
+ _test_module(self, 'tests.modules.multiple', 2)
+
+
+ def test_mixed(self):
+ """ Test a module with more than just plugins """
+ _test_module(self, 'tests.modules.mixed', 2)
+
+
+class TestPackage(unittest.TestCase): # pylint:disable-msg=R0904
+ """ Tests the find method of pyscovery on a package """
+
+
+ def setUp(self): # pylint:disable-msg=C0103
+ pyscovery.clear_modules()
+
+
+ def tearDown(self): # pylint:disable-msg=C0103
+ pyscovery.clear_modules()
+
+
+ def test_package_without_recurse(self):
+ """ Test a package without recursion """
+ _test_module(self, 'tests.modules', 0)
+
+
+ def test_package_recursion(self):
+ """ Test a package with recursion """
+ _test_module(self, 'tests.modules.deep', 2, recurse=True)
+
+
+ def test_package_deep_recursion(self):
+ """ Test a package with recursion """
+ _test_module(self, 'tests.modules', 7, recurse=True)
+
--- a/tests/tests.py Fri Mar 29 01:49:53 2013 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,231 +0,0 @@
-# pyscovery - A python plugin finder
-# Copyright (C) 2013 Gary Kramlich <grim@reaperworld.com>
-#
-# This program 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.
-#
-# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-
-"""
-Unit tests for pyscovery
-"""
-
-import inspect
-import unittest
-
-import pyscovery
-
-
-def _test_module(test, module, count, recurse=False):
- """
- Given a module, test that we find count plugins
- """
-
- pyscovery.add_module(module)
-
- gen = pyscovery.find(Plugin, recurse=recurse)
- test.assertTrue(inspect.isgenerator(gen))
-
- found = list(gen)
- test.assertEqual(len(found), count, 'plugins found: {}'.format(found))
-
-
-def _test_module_count(test, count):
- """
- Asserts if the number of paths doesn't match count
- """
-
- modules = pyscovery.get_modules()
- test.assertEqual(len(modules), count, 'search paths {}'.format(modules))
-
-
-class Plugin(object): # pylint:disable-msg=R0903
- """
- The class all the test plugins descend from
- """
-
- pass
-
-
-class TestModules(unittest.TestCase): # pylint:disable-msg=R0904
- """
- Unit tests for path manipulation
- """
-
- module = 'test'
-
-
- def setUp(self): # pylint:disable-msg=C0103
- pyscovery.clear_modules()
-
-
- def tearDown(self): # pylint:disable-msg=C0103
- _test_module_count(self, 0)
- pyscovery.clear_modules()
-
-
- def test_add_remove(self):
- """
- Add and remove a single plugin path
- """
-
- pyscovery.add_module(TestModules.module)
- _test_module_count(self, 1)
- pyscovery.remove_module(TestModules.module)
-
-
- def test_add_existing(self):
- """
- Add the same plugin path twice, and make sure it's only in there once
- """
-
- pyscovery.add_module(TestModules.module)
- pyscovery.add_module(TestModules.module)
- _test_module_count(self, 1)
-
- pyscovery.remove_module(TestModules.module)
-
-
- def test_remove_nonexistant(self): # pylint:disable-msg=R0201
- """
- Try to remove a non-existant plugin path
- """
-
- pyscovery.remove_module(TestModules.module)
-
-
- def test_add_multiple(self):
- """
- Add multiple paths to the search paths
- """
-
- second = '{}.1'.format(TestModules.module)
-
- pyscovery.add_module(TestModules.module)
- _test_module_count(self, 1)
-
- pyscovery.add_module(second)
- _test_module_count(self, 2)
-
- pyscovery.remove_module(TestModules.module)
- pyscovery.remove_module(second)
-
-
-class TestFind(unittest.TestCase): # pylint:disable-msg=R0904
- """
- Basic tests for the find function
- """
-
- def test_none(self):
- """
- Test that a TypeError is raised when find is called with None
- """
-
- self.assertRaises(TypeError, pyscovery.find(None))
-
-
- def test_string(self):
- """
- Test that a TypeError is raised when find is called with a string
- """
-
- self.assertRaises(TypeError, pyscovery.find(''))
-
-
- def test_int(self):
- """
- Test that a TypeError is raised when find is called with an int
- """
-
- self.assertRaises(TypeError, pyscovery.find(0))
-
-
- def test_old_style_class(self): # pylint:disable-msg=R0201
- """
- Test that a TypeError is NOT raised when find is called with an old
- style class
- """
-
- class Test: # pylint:disable-msg=R0903,W0232
- """ old style class """
- pass
-
-
- pyscovery.find(Test)
-
-
- def test_new_style_class(self): # pylint:disable-msg=R0201
- """
- Test that a TypeError is NOT raised when find is called with an new
- style class
- """
-
- class Test(object): # pylint:disable-msg=R0903
- """ new style class """
- pass
-
-
- pyscovery.find(Test)
-
-
-class TestModule(unittest.TestCase): # pylint:disable-msg=R0904
- """ Tests the discovery method of pyscovery """
-
-
- def setUp(self): # pylint:disable-msg=C0103
- pyscovery.clear_modules()
-
-
- def tearDown(self): # pylint:disable-msg=C0103
- pyscovery.clear_modules()
-
-
- def test_single(self):
- """ Test a module with a single plugin """
- _test_module(self, 'modules.single', 1)
-
-
- def test_multiple(self):
- """ Test a module with multiple plugins """
- _test_module(self, 'modules.multiple', 2)
-
-
- def test_mixed(self):
- """ Test a module with more than just plugins """
- _test_module(self, 'modules.mixed', 2)
-
-
-class TestPackage(unittest.TestCase): # pylint:disable-msg=R0904
- """ Tests the find method of pyscovery on a package """
-
-
- def setUp(self): # pylint:disable-msg=C0103
- pyscovery.clear_modules()
-
-
- def tearDown(self): # pylint:disable-msg=C0103
- pyscovery.clear_modules()
-
-
- def test_package_without_recurse(self):
- """ Test a package without recursion """
- _test_module(self, 'modules', 0)
-
-
- def test_package_recursion(self):
- """ Test a package with recursion """
- _test_module(self, 'modules.deep', 2, recurse=True)
-
-
- def test_package_deep_recursion(self):
- """ Test a package with recursion """
- _test_module(self, 'modules', 7, recurse=True)
-