summaryrefslogtreecommitdiff
path: root/tests/plugins/third_party.py
blob: b82f112fe3e2a5629c81564f21fda7356b669872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import pytest
import pkg_resources

from pluginbase import PluginBase
from buildstream._elementfactory import ElementFactory
from buildstream._sourcefactory import SourceFactory

from tests.testutils.setuptools import entry_fixture

DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    'third_party'
)


# Simple fixture to create a PluginBase object that
# we use for loading plugins.
@pytest.fixture()
def plugin_fixture():
    return {
        'base': PluginBase(package='buildstream.plugins')
    }


##################################################################
#                              Tests                             #
##################################################################
# Test that external element plugin loading works.
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'third_party_element'))
def test_custom_pip_element(plugin_fixture, entry_fixture, datafiles):
    factory = ElementFactory(plugin_fixture['base'], [])
    assert(isinstance(factory, ElementFactory))

    entry_fixture(datafiles, 'buildstream.plugins', 'third_party_element:foop')

    foo_type, _ = factory.lookup('third_party_element:foop')
    assert(foo_type.__name__ == 'FooElement')


# Test that external source plugin loading works.
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'third_party_source'))
def test_custom_pip_source(plugin_fixture, entry_fixture, datafiles):
    factory = SourceFactory(plugin_fixture['base'], [])
    assert(isinstance(factory, SourceFactory))

    entry_fixture(datafiles, 'buildstream.plugins', 'third_party_source:foop')

    foo_type, _ = factory.lookup('third_party_source:foop')
    assert(foo_type.__name__ == 'FooSource')