Skip to content

Commit 4cb1852

Browse files
Add source provenance attribute tests
1 parent 6b76609 commit 4cb1852

5 files changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
#
14+
15+
# Pylint doesn't play well with fixtures and dependency injection from pytest
16+
# pylint: disable=redefined-outer-name
17+
18+
import os
19+
import pytest
20+
21+
from buildstream._testing import generate_project, load_yaml
22+
from buildstream._testing import cli # pylint: disable=unused-import
23+
from buildstream.exceptions import ErrorDomain
24+
25+
26+
DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "source_provenance_attributes")
27+
28+
29+
##################################################################
30+
# Tests #
31+
##################################################################
32+
# Test that no defined source provenance attributes blocks all source provenance data
33+
@pytest.mark.datafiles(DATA_DIR)
34+
def test_source_provenance_disallow_top_level(cli, datafiles):
35+
project = str(datafiles)
36+
37+
# Set the project_dir alias in project.conf to the path to the tested project
38+
project_config_path = os.path.join(project, "project.conf")
39+
project_config = load_yaml(project_config_path)
40+
aliases = project_config.get_mapping("aliases")
41+
aliases["project_dir"] = "file://{}".format(project)
42+
43+
generate_project(project, project_config)
44+
45+
# Make sure disallowed usage of top-level source proveance fails
46+
result = cli.run(
47+
project=project,
48+
args=["show", "target.bst"],
49+
)
50+
51+
result.assert_main_error(ErrorDomain.SOURCE, "top-level-provenance-on-custom-implementation")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: import
2+
3+
sources:
4+
- kind: multisource-plugin
5+
url: project_dir:/files/file
6+
provenance:
7+
homepage: bar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World!
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from buildstream import Node, Source
2+
3+
4+
class MultiSource(Source):
5+
BST_MIN_VERSION = "2.0"
6+
7+
BST_CUSTOM_SOURCE_PROVENANCE = True
8+
9+
def configure(self, node):
10+
pass
11+
12+
def preflight(self):
13+
pass
14+
15+
def get_unique_key(self):
16+
return {}
17+
18+
def load_ref(self, node):
19+
pass
20+
21+
def get_ref(self):
22+
return {}
23+
24+
def set_ref(self, ref, node):
25+
pass
26+
27+
def is_cached(self):
28+
return False
29+
30+
def collect_source_info(self):
31+
return []
32+
33+
34+
# Plugin entry point
35+
def setup():
36+
return MultiSource
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Project with source provenance attributes
2+
name: foo
3+
min-version: 2.0
4+
5+
element-path: elements
6+
7+
aliases:
8+
project_dir: file://{project_dir}
9+
10+
plugins:
11+
- origin: local
12+
path: plugins
13+
sources:
14+
- multisource-plugin

0 commit comments

Comments
 (0)