[test] Extract out method-which-is-not-a-method mocking iter_entry_points
to ease reuse and improve readability.
--- a/cubicweb/test/unittest_cwconfig.py Wed Mar 29 10:32:24 2017 +0200
+++ b/cubicweb/test/unittest_cwconfig.py Wed Mar 29 10:34:16 2017 +0200
@@ -93,6 +93,21 @@
del sys.modules[module]
+def iter_entry_points(group, name):
+ """Mock pkg_resources.iter_entry_points to yield EntryPoint from
+ packages found in test/data/libpython even though these are not
+ installed.
+ """
+ libpython = CubicWebConfigurationTC.datapath('libpython')
+ prefix = 'cubicweb_'
+ for pkgname in os.listdir(libpython):
+ if not pkgname.startswith(prefix):
+ continue
+ location = join(libpython, pkgname)
+ yield EntryPoint(pkgname[len(prefix):], pkgname,
+ dist=Distribution(location))
+
+
class CubicWebConfigurationTC(BaseTestCase):
@classmethod
@@ -110,20 +125,6 @@
def tearDown(self):
ApptestConfiguration.CUBES_PATH = []
- def iter_entry_points(group, name):
- """Mock pkg_resources.iter_entry_points to yield EntryPoint from
- packages found in test/data/libpython even though these are not
- installed.
- """
- libpython = CubicWebConfigurationTC.datapath('libpython')
- prefix = 'cubicweb_'
- for pkgname in os.listdir(libpython):
- if not pkgname.startswith(prefix):
- continue
- location = join(libpython, pkgname)
- yield EntryPoint(pkgname[len(prefix):], pkgname,
- dist=Distribution(location))
-
@patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points)
def test_available_cubes(self, mock_iter_entry_points):
expected_cubes = [