Exemple #1
0
def test_compute_match_types_duplicate(mocker, caplog):
    iep = mocker.patch("raincoat.match.iter_entry_points")

    class MatchFactory(object):
        def __init__(self, name):
            self.name = name

        def __repr__(self):
            return self.name

    MatchA, MatchB = MatchFactory("A"), MatchFactory("B")

    entry_a, entry_b = iep.return_value = [
        EntryPoint("a", "aaa"),
        EntryPoint("a", "bbb"),
    ]
    entry_a.load = lambda: MatchA
    entry_b.load = lambda: MatchB

    assert match_module.compute_match_types() == {"a": MatchA}

    assert "Several classes registered for the match type a" in caplog.records[
        0].message
    assert "B will be ignored" in caplog.records[0].message
    assert "A will be used" in caplog.records[0].message
Exemple #2
0
def event_entrypoints():
    """Declare some events by mocking the invenio_stats.events entrypoint.

    It yields a list like [{event_type: <event_type_name>}, ...].
    """
    data = []
    result = []
    for idx in range(5):
        event_type_name = 'event_{}'.format(idx)
        from pkg_resources import EntryPoint
        entrypoint = EntryPoint(event_type_name, event_type_name)
        conf = dict(event_type=event_type_name,
                    templates='/',
                    processor_class=EventsIndexer)
        entrypoint.load = lambda conf=conf: (lambda: [conf])
        data.append(entrypoint)
        result.append(conf)

    # including file_download
    event_type_name = 'file-download'
    from pkg_resources import EntryPoint
    entrypoint = EntryPoint('invenio_files_rest', 'test_dir')
    conf = dict(event_type=event_type_name,
                templates='contrib/file-download',
                processor_class=EventsIndexer)
    entrypoint.load = lambda conf=conf: (lambda: [conf])
    data.append(entrypoint)

    entrypoints = mock_iter_entry_points_factory(data, 'invenio_stats.events')

    with patch('invenio_stats.ext.iter_entry_points', entrypoints):
        yield result
def test_load_plugins(mocker):

    cli = click.Group()

    grp_internal = click.MultiCommand('internal')
    grp_external = click.MultiCommand('external')

    mocker.patch.object(
        EntryPoint,
        'load',
        side_effect=[
            lambda: grp_internal,
            lambda: grp_external,
        ],
    )
    mocker.patch(
        'connect.cli.core.plugins.pkg_resources.iter_entry_points',
        return_value=iter([
            EntryPoint('internal', 'connect.cli.plugins.internal'),
            EntryPoint('external', 'external.cli.plugin'),
        ]),
    )

    load_plugins(cli)

    assert 'internal' in cli.commands
    assert 'plugin' in cli.commands
    assert 'external' in cli.commands['plugin'].commands
Exemple #4
0
 def iter_entry_points(*, group):
     if group == "asdf.resource_mappings":
         yield EntryPoint(
             "one", "asdf.tests.test_entry_points",
             attrs=("resource_mappings_entry_point_one",),
             dist=pkg_resources.get_distribution("asdf")
         )
         yield EntryPoint(
             "two", "asdf.tests.test_entry_points",
             attrs=("resource_mappings_entry_point_two",),
             dist=pkg_resources.get_distribution("asdf")
         )
Exemple #5
0
def _mock_entry_points(group, name=None):
    """Return EntryPoints from different groups."""
    data = {
        'only_first_tasks': [EntryPoint('first_tasks', 'first_tasks')],
        'only_second_tasks': [EntryPoint('second_tasks', 'second_tasks')],
        'invenio_celery.tasks': [
            EntryPoint('first_tasks', 'first_tasks'),
            EntryPoint('second_tasks', 'second_tasks'),
        ],
    }
    assert name is None
    for entry_point in data[group]:
        yield entry_point
Exemple #6
0
def query_entrypoints(custom_permission_factory):
    """Same as event_entrypoints for queries."""
    from pkg_resources import EntryPoint
    entrypoint = EntryPoint('invenio_stats', 'queries')
    data = []
    result = []
    conf = [
        dict(query_name='test-query',
             query_class=CustomQuery,
             query_config=dict(index='stats-file-download',
                               copy_fields=dict(bucket_id='bucket_id', ),
                               required_filters=dict(bucket_id='bucket_id', )),
             permission_factory=custom_permission_factory),
        dict(query_name='test-query2',
             query_class=CustomQuery,
             query_config=dict(index='stats-file-download',
                               copy_fields=dict(bucket_id='bucket_id', ),
                               required_filters=dict(bucket_id='bucket_id', )),
             permission_factory=custom_permission_factory)
    ]

    result += conf
    result += register_queries()
    entrypoint.load = lambda conf=conf: (lambda: result)
    data.append(entrypoint)

    entrypoints = mock_iter_entry_points_factory(data, 'invenio_stats.queries')

    with patch('invenio_stats.ext.iter_entry_points', entrypoints):
        yield result
 def setUp(self):
     self.mgr = cmds.CommandManager()
     self.mgr.load_namespace('contrail_api_cli.shell_command')
     ep = EntryPoint('cmd', 'contrail_api_cli.tests.test_command', attrs=('Cmd',))
     cls = ep.load(require=False)
     ext = Extension('cmd', ep, cls, cls('cmd'))
     self.mgr.mgrs[0].extensions.append(ext)
Exemple #8
0
 def testDeprecationWarnings(self):
     ep = EntryPoint(
         "foo", "pkg_resources.tests.test_resources", ["TestEntryPoints"],
         ["x"]
     )
     with pytest.warns(pkg_resources.PkgResourcesDeprecationWarning):
         ep.load(require=False)
def test_plugins():
    # Declaring the plugin
    dist = get_distribution("FAST-OAD")
    dummy_plugin = EntryPoint(
        "test_plugin", "fastoad.module_management.tests.data.dummy_plugin", dist=dist,
    )
    dist.get_entry_map(MODEL_PLUGIN_ID)["test_plugin"] = dummy_plugin

    # Before load_plugins(), services are not registered
    with pytest.raises(FastBundleLoaderUnknownFactoryNameError):
        declared_dummy_1 = RegisterDummyService.get_provider("test.plugin.declared.1")
    with pytest.raises(FastBundleLoaderUnknownFactoryNameError):
        decorated_dummy_1 = RegisterDummyService.get_provider("test.plugin.decorated.1")

    load_plugins()

    declared_dummy_1 = RegisterDummyService.get_provider("test.plugin.declared.1")
    assert declared_dummy_1.my_class() == "DeclaredDummy1"
    declared_dummy_2 = RegisterDummyService.get_provider("test.plugin.declared.2")
    assert declared_dummy_2.my_class() == "DeclaredDummy2"

    decorated_dummy_1 = RegisterDummyService.get_provider("test.plugin.decorated.1")
    assert decorated_dummy_1.my_class() == "DecoratedDummy1"
    decorated_dummy_2 = RegisterDummyService.get_provider("test.plugin.decorated.2")
    assert decorated_dummy_2.my_class() == "DecoratedDummy2"
    # This one is in a subpackage
    decorated_dummy_3 = RegisterDummyService.get_provider("test.plugin.decorated.3")
    assert decorated_dummy_3.my_class() == "DecoratedDummy3"

    # Checking variable description.
    assert Variable("dummy:variable").description == "Some dummy variable."
Exemple #10
0
 def container(self):
     container = PluginContainer('asphalt.core.test_plugin_container',
                                 BaseDummyPlugin)
     entrypoint = EntryPoint('dummy', 'test_util')
     entrypoint.load = Mock(return_value=DummyPlugin)
     container._entrypoints = {'dummy': entrypoint}
     return container
Exemple #11
0
def test_get_primitives_paths_entry_points(iep_mock):
    # setup
    something_else_ep = EntryPoint('something_else', 'mlblocks.__version__')
    jsons_path_ep = EntryPoint('jsons_path',
                               'tests.test_primitives',
                               attrs=['FAKE_MLPRIMITIVES_PATH'],
                               dist=Distribution())
    iep_mock.return_value = [something_else_ep, jsons_path_ep]

    # run
    paths = primitives.get_primitives_paths()

    # assert
    expected = ['a', 'b', 'this/is/a/fake']
    assert paths == expected

    iep_mock.assert_called_once_with('mlprimitives')
Exemple #12
0
 def test_raise(self) -> None:
     # arrange
     entry = EntryPoint('Test',
                        '__.does.not.exist',
                        attrs=('UnknownClass', ),
                        dist=_TEST_PLUGIN_DIST)
     # act & assert
     with self.assertRaises(ImportError):
         KnownImageCrawlers._load(entry)
def processor_entrypoints():
    """Entrypoint fixture."""
    eps = []
    event_type_name = DummyProcessor.id
    entrypoint = EntryPoint(event_type_name, event_type_name)
    entrypoint.load = lambda: lambda: DummyProcessor
    eps.append(entrypoint)

    return mock_iter_entry_points_factory(eps, 'invenio_files_processor')
Exemple #14
0
 def register_module(self, name=None, module_name=None, attrs=(), entry_point=None):
     if entry_point:
         ep = EntryPoint.parse(entry_point)
     else:
         ep = EntryPoint(name, module_name, attrs)
     loaded = self._load_one_plugin(ep, invoke_on_load=True, invoke_args=(), invoke_kwds={})
     if loaded:
         self.extensions.append(loaded)
         self.extensions = self.order_extensions(self.extensions)
         self._extensions_by_name = None
Exemple #15
0
 def register_module(self, name, module_name):
     ep = EntryPoint(name, module_name)
     loaded = self._load_one_plugin(ep,
                                    invoke_on_load=True,
                                    invoke_args=(),
                                    invoke_kwds={})
     if loaded:
         self.extensions.append(loaded)
         self.extensions = self.order_extensions(self.extensions)
         self._extensions_by_name = None
Exemple #16
0
def test_compute_match_types(mocker):
    iep = mocker.patch("raincoat.match.iter_entry_points")

    class MatchFactory(object):
        def __init__(self, name):
            self.name = name

        def __repr__(self):
            return self.name

    MatchA, MatchB = MatchFactory("A"), MatchFactory("B")

    entry_a, entry_b = iep.return_value = [
        EntryPoint("a", "aaa"),
        EntryPoint("b", "bbb"),
    ]
    entry_a.load = lambda: MatchA
    entry_b.load = lambda: MatchB

    assert match_module.compute_match_types() == {"a": MatchA, "b": MatchB}
    assert MatchA.match_type == "a"
    assert MatchB.match_type == "b"
Exemple #17
0
def iter_entry_points(group, name):
    """Mock pkg_resources.iter_entry_points to yield EntryPoint from
    packages found in test/data even though these are not
    installed.
    """
    libpython = CubicWebConfigurationTC.datapath()
    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))
Exemple #18
0
def test_duplicate_queue(app):
    """Check that duplicate queues raise an exception."""
    with app.app_context():
        data = []
        for idx in range(2):
            queue_name = 'myqueue'
            entrypoint = EntryPoint(queue_name, queue_name)
            conf = dict(name=queue_name, exchange=MOCK_MQ_EXCHANGE)
            entrypoint.load = lambda conf=conf: (lambda: [conf])
            data.append(entrypoint)

        entrypoints = mock_iter_entry_points_factory(data)

        with patch('pkg_resources.iter_entry_points', entrypoints):
            with pytest.raises(DuplicateQueueError):
                current_queues.queues()
Exemple #19
0
def template_entrypoints():
    """Declare some events by mocking the invenio_stats.events entrypoint.

    It yields a list like [{event_type: <event_type_name>}, ...].
    """
    eps = []
    for idx in range(5):
        event_type_name = 'mock_module'
        from pkg_resources import EntryPoint
        entrypoint = EntryPoint(event_type_name, event_type_name)
        entrypoint.load = lambda: lambda: ['mock_module.templates']
        eps.append(entrypoint)

    entrypoints = mock_iter_entry_points_factory(eps,
                                                 'invenio_search.templates')
    return entrypoints
Exemple #20
0
    def load_all(cls):
        if cls.__plugins__ is not None:
            return cls.__plugins__

        entry_points = []

        # builtin plugins
        for _, m, _ in iter_modules(['squad/plugins']):
            e = EntryPoint(m, 'squad.plugins.' + m, attrs=('Plugin', ))
            entry_points.append(e)

        # external plugins
        plugins = iter_entry_points('squad_plugins')
        entry_points += list(plugins)

        cls.__plugins__ = {e.name: e.resolve() for e in entry_points}
        return cls.__plugins__
Exemple #21
0
def _mock_entry_points(group, name=None):
    """Return EntryPoints from different groups."""
    data = {
        'only_first_tasks': [EntryPoint('bpackage', 'bpackage.first_tasks')],
        'only_second_tasks': [EntryPoint('bpackage', 'bpackage.second_tasks')],
        'bare_module_tasks': [EntryPoint('second_tasks', 'second_tasks')],
        'invenio_celery.tasks': [
            EntryPoint('bpackage_1', 'bpackage.first_tasks'),
            EntryPoint('bpackage_2', 'bpackage.second_tasks'),
            EntryPoint('apackage', 'apackage.third_tasks'),
        ],
    }
    assert name is None
    for entry_point in data[group]:
        yield entry_point
Exemple #22
0
def test_queues_entrypoints(app):
    """Declare some queues by mocking the invenio_queues.queues entrypoint.

    It yields a list like [{name: queue_name, exchange: conf}, ...].
    """
    data = []
    result = []
    for idx in range(5):
        queue_name = 'queue{}'.format(idx)
        from pkg_resources import EntryPoint
        entrypoint = EntryPoint(queue_name, queue_name)
        conf = dict(name=queue_name, exchange=MOCK_MQ_EXCHANGE)
        entrypoint.load = lambda conf=conf: (lambda: [conf])
        data.append(entrypoint)
        result.append(conf)

    entrypoints = mock_iter_entry_points_factory(data)

    with patch('pkg_resources.iter_entry_points',
               entrypoints):
        try:
            yield result
        finally:
            remove_queues(app)
Exemple #23
0
def add_entry_point(group, name, module, attr):
    pybtex_dist = get_distribution('pybtex')
    entry_point = EntryPoint(name, module, (attr, ), dist=pybtex_dist)
    entry_point_map = pybtex_dist.get_entry_map()
    entry_point_map.setdefault(group, {})[name] = entry_point
Exemple #24
0
 def testBasics(self):
     ep = EntryPoint("foo", "pkg_resources.tests.test_resources",
                     ["TestEntryPoints"], ["x"], self.dist)
     self.assertfields(ep)
Exemple #25
0
class TestEntryPoints:
    def assertfields(self, ep):
        assert ep.name == "foo"
        assert ep.module_name == "pkg_resources.tests.test_resources"
        assert ep.attrs == ("TestEntryPoints", )
        assert ep.extras == ("x", )
        assert ep.load() is TestEntryPoints
        expect = "foo = pkg_resources.tests.test_resources:TestEntryPoints [x]"
        assert str(ep) == expect

    def setup_method(self, method):
        self.dist = Distribution.from_filename("FooPkg-1.2-py2.4.egg",
                                               metadata=Metadata(
                                                   ('requires.txt', '[x]')))

    def testBasics(self):
        ep = EntryPoint("foo", "pkg_resources.tests.test_resources",
                        ["TestEntryPoints"], ["x"], self.dist)
        self.assertfields(ep)

    def testParse(self):
        s = "foo = pkg_resources.tests.test_resources:TestEntryPoints [x]"
        ep = EntryPoint.parse(s, self.dist)
        self.assertfields(ep)

        ep = EntryPoint.parse("bar baz=  spammity[PING]")
        assert ep.name == "bar baz"
        assert ep.module_name == "spammity"
        assert ep.attrs == ()
        assert ep.extras == ("ping", )

        ep = EntryPoint.parse(" fizzly =  wocka:foo")
        assert ep.name == "fizzly"
        assert ep.module_name == "wocka"
        assert ep.attrs == ("foo", )
        assert ep.extras == ()

        # plus in the name
        spec = "html+mako = mako.ext.pygmentplugin:MakoHtmlLexer"
        ep = EntryPoint.parse(spec)
        assert ep.name == 'html+mako'

    reject_specs = "foo", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2"

    @pytest.mark.parametrize("reject_spec", reject_specs)
    def test_reject_spec(self, reject_spec):
        with pytest.raises(ValueError):
            EntryPoint.parse(reject_spec)

    def test_printable_name(self):
        """
        Allow any printable character in the name.
        """
        # Create a name with all printable characters; strip the whitespace.
        name = string.printable.strip()
        spec = "{name} = module:attr".format(**locals())
        ep = EntryPoint.parse(spec)
        assert ep.name == name

    def checkSubMap(self, m):
        assert len(m) == len(self.submap_expect)
        for key, ep in self.submap_expect.items():
            assert m.get(key).name == ep.name
            assert m.get(key).module_name == ep.module_name
            assert sorted(m.get(key).attrs) == sorted(ep.attrs)
            assert sorted(m.get(key).extras) == sorted(ep.extras)

    submap_expect = dict(feature1=EntryPoint('feature1', 'somemodule',
                                             ['somefunction']),
                         feature2=EntryPoint('feature2', 'another.module',
                                             ['SomeClass'],
                                             ['extra1', 'extra2']),
                         feature3=EntryPoint('feature3',
                                             'this.module',
                                             extras=['something']))
    submap_str = """
            # define features for blah blah
            feature1 = somemodule:somefunction
            feature2 = another.module:SomeClass [extra1,extra2]
            feature3 = this.module [something]
    """

    def testParseList(self):
        self.checkSubMap(EntryPoint.parse_group("xyz", self.submap_str))
        with pytest.raises(ValueError):
            EntryPoint.parse_group("x a", "foo=bar")
        with pytest.raises(ValueError):
            EntryPoint.parse_group("x", ["foo=baz", "foo=bar"])

    def testParseMap(self):
        m = EntryPoint.parse_map({'xyz': self.submap_str})
        self.checkSubMap(m['xyz'])
        assert list(m.keys()) == ['xyz']
        m = EntryPoint.parse_map("[xyz]\n" + self.submap_str)
        self.checkSubMap(m['xyz'])
        assert list(m.keys()) == ['xyz']
        with pytest.raises(ValueError):
            EntryPoint.parse_map(["[xyz]", "[xyz]"])
        with pytest.raises(ValueError):
            EntryPoint.parse_map(self.submap_str)
Exemple #26
0
class TestEntryPoints:
    def assertfields(self, ep):
        assert ep.name == "foo"
        assert ep.module_name == "pkg_resources.tests.test_resources"
        assert ep.attrs == ("TestEntryPoints", )
        assert ep.extras == ("x", )
        assert ep.load() is TestEntryPoints
        expect = "foo = pkg_resources.tests.test_resources:TestEntryPoints [x]"
        assert str(ep) == expect

    def setup_method(self, method):
        self.dist = Distribution.from_filename("FooPkg-1.2-py2.4.egg",
                                               metadata=Metadata(
                                                   ('requires.txt', '[x]')))

    def testBasics(self):
        ep = EntryPoint("foo", "pkg_resources.tests.test_resources",
                        ["TestEntryPoints"], ["x"], self.dist)
        self.assertfields(ep)

    def testParse(self):
        s = "foo = pkg_resources.tests.test_resources:TestEntryPoints [x]"
        ep = EntryPoint.parse(s, self.dist)
        self.assertfields(ep)

        ep = EntryPoint.parse("bar baz=  spammity[PING]")
        assert ep.name == "bar baz"
        assert ep.module_name == "spammity"
        assert ep.attrs == ()
        assert ep.extras == ("ping", )

        ep = EntryPoint.parse(" fizzly =  wocka:foo")
        assert ep.name == "fizzly"
        assert ep.module_name == "wocka"
        assert ep.attrs == ("foo", )
        assert ep.extras == ()

        # plus in the name
        spec = "html+mako = mako.ext.pygmentplugin:MakoHtmlLexer"
        ep = EntryPoint.parse(spec)
        assert ep.name == 'html+mako'

    def testRejects(self):
        for ep in [
                "foo",
                "x=1=2",
                "x=a:b:c",
                "q=x/na",
                "fez=pish:tush-z",
                "x=f[a]>2",
        ]:
            try:
                EntryPoint.parse(ep)
            except ValueError:
                pass
            else:
                raise AssertionError("Should've been bad", ep)

    def checkSubMap(self, m):
        assert len(m) == len(self.submap_expect)
        for key, ep in pkg_resources.iteritems(self.submap_expect):
            assert repr(m.get(key)) == repr(ep)

    submap_expect = dict(feature1=EntryPoint('feature1', 'somemodule',
                                             ['somefunction']),
                         feature2=EntryPoint('feature2', 'another.module',
                                             ['SomeClass'],
                                             ['extra1', 'extra2']),
                         feature3=EntryPoint('feature3',
                                             'this.module',
                                             extras=['something']))
    submap_str = """
            # define features for blah blah
            feature1 = somemodule:somefunction
            feature2 = another.module:SomeClass [extra1,extra2]
            feature3 = this.module [something]
    """

    def testParseList(self):
        self.checkSubMap(EntryPoint.parse_group("xyz", self.submap_str))
        with pytest.raises(ValueError):
            EntryPoint.parse_group("x a", "foo=bar")
        with pytest.raises(ValueError):
            EntryPoint.parse_group("x", ["foo=baz", "foo=bar"])

    def testParseMap(self):
        m = EntryPoint.parse_map({'xyz': self.submap_str})
        self.checkSubMap(m['xyz'])
        assert list(m.keys()) == ['xyz']
        m = EntryPoint.parse_map("[xyz]\n" + self.submap_str)
        self.checkSubMap(m['xyz'])
        assert list(m.keys()) == ['xyz']
        with pytest.raises(ValueError):
            EntryPoint.parse_map(["[xyz]", "[xyz]"])
        with pytest.raises(ValueError):
            EntryPoint.parse_map(self.submap_str)
Exemple #27
0
class TestAddonManagerDialog(QAppTestCase):
    def test_widget(self):
        items = [
            Installed(
                Installable("foo", "1.1", "", "", "", []),
                Distribution(project_name="foo", version="1.0"),
            ),
            Available(Installable("q", "1.2", "", "", "", [])),
            Installed(None, Distribution(project_name="a", version="0.0")),
        ]
        w = AddonManagerDialog()
        w.setItems(items)
        _ = w.items()
        state = w.itemState()
        self.assertSequenceEqual(state, [])
        state = [(Install, items[1])]
        w.setItemState(state)
        self.assertSequenceEqual(state, w.itemState())
        state = state + [(Upgrade, items[0])]
        w.setItemState(state)
        self.assertSequenceEqual(state, w.itemState()[::-1])
        state = [(Uninstall, items[0])]
        w.setItemState(state)
        self.assertSequenceEqual(state, w.itemState())
        updateTopLayout = w._AddonManagerDialog__updateTopLayout
        updateTopLayout(False)
        updateTopLayout(True)

    @patch("orangecanvas.config.default.addon_entry_points",
           return_value=[
               EntryPoint("a",
                          "b",
                          dist=Distribution(project_name="foo", version="1.0"))
           ])
    def test_drop(self, p1):
        items = [
            Installed(
                Installable("foo", "1.1", "", "", "", []),
                Distribution(project_name="foo", version="1.0"),
            ),
        ]
        w = AddonManagerDialog()
        w.setItems(items)

        # drop an addon already in the list
        pkginfo = "Metadata-Version: 1.0\nName: foo\nVersion: 0.9"
        with addon_archive(pkginfo) as fn:
            event = self._drop_event(QUrl.fromLocalFile(fn))
            w.dropEvent(event)
        items = w.items()
        self.assertEqual(1, len(items))
        self.assertEqual("0.9", items[0].installable.version)
        self.assertEqual(True, items[0].installable.force)
        state = [(Upgrade, items[0])]
        self.assertSequenceEqual(state, w.itemState())

        # drop a new addon
        pkginfo = "Metadata-Version: 1.0\nName: foo2\nVersion: 0.8"
        with addon_archive(pkginfo) as fn:
            event = self._drop_event(QUrl.fromLocalFile(fn))
            w.dropEvent(event)
        items = w.items()
        self.assertEqual(2, len(items))
        self.assertEqual("0.8", items[1].installable.version)
        self.assertEqual(True, items[1].installable.force)
        state = state + [(Install, items[1])]
        self.assertSequenceEqual(state, w.itemState())

    def _drop_event(self, url):
        # make sure data does not get garbage collected before it used
        # pylint: disable=attribute-defined-outside-init
        self.event_data = data = QMimeData()
        data.setUrls([QUrl(url)])

        return QDropEvent(QPoint(0, 0), Qt.MoveAction, data, Qt.NoButton,
                          Qt.NoModifier, QDropEvent.Drop)

    def test_run_query(self):
        w = AddonManagerDialog()

        query_res = [
            addons._QueryResult("uber-pkg", None),
            addons._QueryResult(
                "unter-pkg", Installable("unter-pkg", "0.0.0", "", "", "", []))
        ]

        def query(names):
            return query_res

        with patch.object(QMessageBox, "exec_", return_value=QMessageBox.Cancel), \
             patch.object(addons, "query_pypi", query):
            f = w.runQueryAndAddResults(["uber-pkg", "unter-pkg"], )
            loop = QEventLoop()
            f.add_done_callback(qinvoke(lambda f: loop.quit(), loop))
            loop.exec()
            items = w.items()
            self.assertEqual(items, [Available(query_res[1].installable)])

    def test_install(self):
        w = AddonManagerDialog()
        foo = Available(Installable("foo", "1.1", "", "", "", []))
        w.setItems([foo])
        w.setItemState([(Install, foo)])
        with patch.object(addons.PipInstaller, "install",
                          lambda self, pkg: None), \
             patch.object(QMessageBox, "exec_", return_value=QMessageBox.Cancel):
            b = w.findChild(QDialogButtonBox)
            b.accepted.emit()
            QTest.qWait(1)
            w.reject()
            QTest.qWait(1)

        w.deleteLater()