summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-07-09 17:14:35 +0200
committerJürg Billeter <j@bitron.ch>2019-07-16 15:36:10 +0200
commit858c51902e603726e70d076a96cbd174f376295c (patch)
treed552d28fc2dfb87565f08c70e298fe0571e9ec89
parent4f1d1b6ceb0a4eb19ad9f1f8c0f5dcd08eba28e4 (diff)
downloadbuildstream-858c51902e603726e70d076a96cbd174f376295c.tar.gz
tests/internals/pluginloading.py: Use dummy_context()
-rw-r--r--tests/internals/pluginloading.py41
1 files changed, 19 insertions, 22 deletions
diff --git a/tests/internals/pluginloading.py b/tests/internals/pluginloading.py
index 9093680f4..4b6baf229 100644
--- a/tests/internals/pluginloading.py
+++ b/tests/internals/pluginloading.py
@@ -1,56 +1,53 @@
+from contextlib import contextmanager
import os
import pytest
-from buildstream._context import Context
from buildstream._project import Project
from buildstream._exceptions import LoadError, LoadErrorReason
from buildstream._pipeline import Pipeline
+from tests.testutils import dummy_context
+
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'pluginloading',
)
+@contextmanager
def create_pipeline(tmpdir, basedir, target):
- context = Context()
- context.load(config=os.devnull)
- context.deploydir = os.path.join(str(tmpdir), 'deploy')
- context.casdir = os.path.join(str(tmpdir), 'cas')
- project = Project(basedir, context)
-
- def dummy_handler(message, is_silenced):
- pass
+ with dummy_context() as context:
+ context.deploydir = os.path.join(str(tmpdir), 'deploy')
+ context.casdir = os.path.join(str(tmpdir), 'cas')
+ project = Project(basedir, context)
- context.messenger.set_message_handler(dummy_handler)
-
- pipeline = Pipeline(context, project, None)
- targets, = pipeline.load([(target,)])
- return targets
+ pipeline = Pipeline(context, project, None)
+ targets, = pipeline.load([(target,)])
+ yield targets
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'customsource'))
def test_customsource(datafiles, tmpdir):
basedir = str(datafiles)
- targets = create_pipeline(tmpdir, basedir, 'simple.bst')
- assert targets[0].get_kind() == "autotools"
+ with create_pipeline(tmpdir, basedir, 'simple.bst') as targets:
+ assert targets[0].get_kind() == "autotools"
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'customelement'))
def test_customelement(datafiles, tmpdir):
basedir = str(datafiles)
- targets = create_pipeline(tmpdir, basedir, 'simple.bst')
- assert targets[0].get_kind() == "foo"
+ with create_pipeline(tmpdir, basedir, 'simple.bst') as targets:
+ assert targets[0].get_kind() == "foo"
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionsource'))
def test_badversionsource(datafiles, tmpdir):
basedir = str(datafiles)
- with pytest.raises(LoadError) as exc:
- create_pipeline(tmpdir, basedir, 'simple.bst')
+ with pytest.raises(LoadError) as exc, create_pipeline(tmpdir, basedir, 'simple.bst'):
+ pass
assert exc.value.reason == LoadErrorReason.UNSUPPORTED_PLUGIN
@@ -59,7 +56,7 @@ def test_badversionsource(datafiles, tmpdir):
def test_badversionelement(datafiles, tmpdir):
basedir = str(datafiles)
- with pytest.raises(LoadError) as exc:
- create_pipeline(tmpdir, basedir, 'simple.bst')
+ with pytest.raises(LoadError) as exc, create_pipeline(tmpdir, basedir, 'simple.bst'):
+ pass
assert exc.value.reason == LoadErrorReason.UNSUPPORTED_PLUGIN