def test_discover(extra_pythonpath, tmp_config_path): with pytest.warns(PendingDeprecationWarning): registry = discovery.autodiscover(do_package_scan=True) # Check that package scan (name-based) discovery worked. assert 'foo' in registry registry['foo']() # Check that entrypoints-based discovery worked. assert 'some_test_driver' in registry registry['some_test_driver']() # Now again, giving the special PYTHONPATH explicit via kwarg. with pytest.warns(PendingDeprecationWarning): registry = discovery.autodiscover(path=[extra_pythonpath], do_package_scan=True) # Check that package scan (name-based) discovery worked. assert 'foo' in registry registry['foo']() # Check that entrypoints-based discovery worked. assert 'some_test_driver' in registry registry['some_test_driver']() # Now again, turning off the package scan. registry = discovery.autodiscover(path=[extra_pythonpath], do_package_scan=False) # Check that package scan (name-based) discovery did *not* happen. assert 'foo' not in registry # Check that entrypoints-based discovery worked. assert 'some_test_driver' in registry registry['some_test_driver']()
def test_enable_and_disable(extra_pythonpath, tmp_config_path): # Disable and then enable a package scan result. try: discovery.disable('foo') with pytest.warns(PendingDeprecationWarning): registry = discovery.autodiscover(do_package_scan=True) assert 'foo' not in registry discovery.enable('foo', 'intake_foo.FooPlugin') with pytest.warns(PendingDeprecationWarning): registry = discovery.autodiscover(do_package_scan=True) assert 'foo' in registry finally: discovery.enable('foo', 'intake_foo.FooPlugin') # Disable and then enable an entrypoint result. try: discovery.disable('some_test_driver') with pytest.warns(PendingDeprecationWarning): registry = discovery.autodiscover(do_package_scan=True) assert 'some_test_driver' not in registry discovery.enable('some_test_driver', 'driver_with_entrypoints.SomeTestDriver') with pytest.warns(PendingDeprecationWarning): registry = discovery.autodiscover(do_package_scan=True) assert 'some_test_driver' in registry finally: discovery.enable('some_test_driver', 'driver_with_entrypoints.SomeTestDriver')
def test_discover(extra_pythonpath): registry = discovery.autodiscover() # possible other plugins in environment 'foo' in registry registry['foo']() registry.pop('foo', None)
def test_discover_pluginprefix(extra_pythonpath, tmp_config_path): with pytest.warns(PendingDeprecationWarning): registry = discovery.autodiscover(plugin_prefix='not_intake_') assert 'otherfoo' in registry registry['otherfoo']() registry.pop('otherfoo', None)
def _list(self, args): if args.verbose: fmt = '{name:<30}{cls.__module__}.{cls.__name__} @ {file}' else: fmt = '{name:<30}{cls.__module__}.{cls.__name__}' drivers_by_name = autodiscover() # dict mapping name to driver all_drivers = autodiscover_all() # listof (name, driver) direct = { k: v for k, v in intake.registry.items() if k not in all_drivers and k not in drivers_by_name } print("Direct:", file=sys.stderr) none = True for name in sorted(direct, key=str): cls = direct[name] print(fmt.format(name=str(name), cls=cls, file=inspect.getfile(cls)), file=sys.stderr) none = False if none: print("<none>") print("\nEnabled:", file=sys.stderr) none = True for name in sorted(drivers_by_name, key=str): cls = drivers_by_name[name] print(fmt.format(name=str(name), cls=cls, file=inspect.getfile(cls)), file=sys.stderr) none = False if none: print("<none>") print("\nNot enabled:", file=sys.stderr) none = True for name, cls in sorted(all_drivers, key=lambda x: str(x[0])): if drivers_by_name.get(name, None) is not cls: print(fmt.format(name=str(name), cls=cls, file=inspect.getfile(cls)), file=sys.stderr) none = False if none: print("<none>")
def test_discover_collision(extra_pythonpath): with pytest.warns(UserWarning): registry = discovery.autodiscover(plugin_prefix='collision_')
def test_discover_pluginprefix(extra_pythonpath): registry = discovery.autodiscover(plugin_prefix='not_intake_') assert 'otherfoo' in registry registry['otherfoo']() registry.pop('otherfoo', None)
def test_discover_collision(extra_pythonpath, tmp_config_path): with pytest.warns(UserWarning): discovery.autodiscover(plugin_prefix='collision_', do_package_scan=True)
def test_discover_collision(extra_pythonpath): with pytest.warns(UserWarning): registry = discovery.autodiscover(plugin_prefix='collision_') assert set(registry.keys()) == set(['foo']) assert registry['foo'].open() == 'open_worked'
def test_discover_pluginprefix(extra_pythonpath): registry = discovery.autodiscover(plugin_prefix='not_intake_') assert set(registry.keys()) == set(['otherfoo']) assert registry['otherfoo'].open() == 'open_worked'
def test_discover(extra_pythonpath): registry = discovery.autodiscover() # possible other plugins in environment assert set(registry.keys()) >= set(['foo']) assert registry['foo'].open() == 'open_worked'