diff options
author | Thomas Coldrick <thomas.coldrick@codethink.co.uk> | 2020-01-20 09:28:28 +0000 |
---|---|---|
committer | Thomas Coldrick <thomas.coldrick@codethink.co.uk> | 2020-01-23 16:45:39 +0000 |
commit | 3ae24057522c458d78dcb006d02b90bb205444da (patch) | |
tree | e493e259f611b9c96f6e1b961650d921a6595cbd /src | |
parent | 8aa7e8b6c2ca418aafddf4ce308a9d0ff56cf467 (diff) | |
download | buildstream-coldtom/testing-api.tar.gz |
testing: Add functions to generate yaml filescoldtom/testing-api
Adds functions to the `buildstream.testing` package to allow plugins to
dump elements and projects on the fly. Before this plugins were just
accessing the private yaml API for tests and loading/dumping directly. I
also allow access to just `_yaml.load()` from testing.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildstream/testing/__init__.py | 2 | ||||
-rw-r--r-- | src/buildstream/testing/_yaml.py | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/buildstream/testing/__init__.py b/src/buildstream/testing/__init__.py index 46cadbbfa..dafc3a9fe 100644 --- a/src/buildstream/testing/__init__.py +++ b/src/buildstream/testing/__init__.py @@ -22,6 +22,8 @@ This package contains various utilities which make it easier to test plugins. import os from collections import OrderedDict from buildstream.exceptions import ErrorDomain, LoadErrorReason +from buildstream._yaml import load as load_yaml # type: ignore +from ._yaml import generate_project, generate_element from .repo import Repo from .runcli import cli, cli_integration, cli_remote_execution from .integration import integration_cache diff --git a/src/buildstream/testing/_yaml.py b/src/buildstream/testing/_yaml.py new file mode 100644 index 000000000..ccf65a1ae --- /dev/null +++ b/src/buildstream/testing/_yaml.py @@ -0,0 +1,19 @@ +import os + +from buildstream._yaml import roundtrip_dump # type: ignore + + +def generate_project(project_dir, config=None): + if config is None: + config = {} + project_file = os.path.join(project_dir, "project.conf") + if "name" not in config: + config["name"] = os.path.basename(project_dir) + roundtrip_dump(config, project_file) + + +def generate_element(element_dir, element_name, config=None): + if config is None: + config = {} + element_path = os.path.join(element_dir, element_name) + roundtrip_dump(config, element_path) |