From 858c51902e603726e70d076a96cbd174f376295c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Tue, 9 Jul 2019 17:14:35 +0200 Subject: tests/internals/pluginloading.py: Use dummy_context() --- tests/internals/pluginloading.py | 41 +++++++++++++++++++--------------------- 1 file 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 -- cgit v1.2.1