From 53b7374d6962b750e453a85d793f1a59038b4a65 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Sun, 3 May 2020 14:15:12 +0900 Subject: tests/plugins/loading.py: Added test for loading pip pluings This test is automatically skipped when the required package is not installed, which can happen when running pytest directly, which is supported in order to help distribution maintainers test whether BuildStream works properly on their distribution. --- tests/plugins/loading.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/plugins/loading.py b/tests/plugins/loading.py index 152f4080b..1c5dc4546 100644 --- a/tests/plugins/loading.py +++ b/tests/plugins/loading.py @@ -42,6 +42,37 @@ def setup_element(project_path, plugin_type, plugin_name): _yaml.roundtrip_dump(element, element_path) +# This function is used for pytest skipif() expressions. +# +# Tests which require our plugins in tests/plugins/pip-samples need +# to check if these plugins are installed, they are only guaranteed +# to be installed when running tox, but not when using pytest directly +# to test that BuildStream works when integrated in your system. +# +def pip_sample_packages(): + import pkg_resources + + required = {"sample-plugins"} + installed = {pkg.key for pkg in pkg_resources.working_set} # pylint: disable=not-an-iterable + missing = required - installed + + if missing: + return False + + return True + + +SAMPLE_PACKAGES_SKIP_REASON = """ +The sample plugins package used to test pip plugin origins is not installed. + +This is usually tested automatically with `tox`, if you are running +`pytest` directly then you can install these plugins directly using pip. + +The plugins are located in the tests/plugins/sample-plugins directory +of your BuildStream checkout. +""" + + #################################################### # Tests # #################################################### @@ -303,3 +334,18 @@ def test_deprecation_warning_suppressed_specifically(cli, datafiles, plugin_type result = cli.run(project=project, args=["show", "element.bst"]) result.assert_success() assert "Here is some detail." not in result.stderr + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")]) +@pytest.mark.skipif("not pip_sample_packages()", reason=SAMPLE_PACKAGES_SKIP_REASON) +def test_pip_origin_load_success(cli, datafiles, plugin_type): + project = str(datafiles) + + update_project( + project, {"plugins": [{"origin": "pip", "package-name": "sample-plugins", plugin_type: ["sample"],}]}, + ) + setup_element(project, plugin_type, "sample") + + result = cli.run(project=project, args=["show", "element.bst"]) + result.assert_success() -- cgit v1.2.1