summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-07-09 15:52:11 +0200
committerJürg Billeter <j@bitron.ch>2019-07-16 15:36:10 +0200
commit2fc76fca4d48e8dfcfa815f06aafe8f406619dc4 (patch)
tree389f93fa533c4046b2fcc5c7effc6618738a2906
parent20ba24b5c4233f02c9a9c973edf584589f920fc1 (diff)
downloadbuildstream-2fc76fca4d48e8dfcfa815f06aafe8f406619dc4.tar.gz
tests/testutils: Add dummy_context() helper
-rw-r--r--tests/testutils/__init__.py1
-rw-r--r--tests/testutils/context.py46
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/testutils/__init__.py b/tests/testutils/__init__.py
index 9913e880d..25fa6d763 100644
--- a/tests/testutils/__init__.py
+++ b/tests/testutils/__init__.py
@@ -24,6 +24,7 @@
#
from .artifactshare import create_artifact_share, assert_shared, assert_not_shared
+from .context import dummy_context
from .element_generators import create_element_size, update_element_size
from .junction import generate_junction
from .runner_integration import wait_for_cache_granularity
diff --git a/tests/testutils/context.py b/tests/testutils/context.py
new file mode 100644
index 000000000..899bad247
--- /dev/null
+++ b/tests/testutils/context.py
@@ -0,0 +1,46 @@
+#
+# Copyright (C) 2019 Bloomberg Finance LP
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+
+from contextlib import contextmanager
+
+from buildstream._context import Context
+
+
+# Handle messages from the pipeline
+def _dummy_message_handler(message, is_silenced):
+ pass
+
+
+# dummy_context()
+#
+# Context manager to create minimal context for tests.
+#
+# Args:
+# config (filename): The configuration file, if any
+#
+@contextmanager
+def dummy_context(*, config=None):
+ with Context() as context:
+ if not config:
+ config = os.devnull
+
+ context.load(config=config)
+
+ context.messenger.set_message_handler(_dummy_message_handler)
+
+ yield context