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/buildstream/testing/_yaml.py | |
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/buildstream/testing/_yaml.py')
-rw-r--r-- | src/buildstream/testing/_yaml.py | 19 |
1 files changed, 19 insertions, 0 deletions
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) |