Skip to content
Snippets Groups Projects
Commit d0efaeeb authored by Qinusty's avatar Qinusty
Browse files

tests: Add tests for configurable warnings

This adds multiple tests for custom plugin warnings and core warnings,
providing checks for both cases which should cause warnings and errors
when configured as fatal.
parent 547f784e
No related branches found
No related tags found
Loading
Pipeline #27652416 passed
import pytest
import os
from buildstream.plugin import CoreWarnings
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream import _yaml
from tests.testutils.runcli import cli
TOP_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"configuredwarning"
)
def get_project(fatal_warnings):
return {
"name": "test",
"element-path": "elements",
"plugins": [
{
"origin": "local",
"path": "plugins",
"elements": {
"warninga": 0,
"warningb": 0,
"corewarn": 0,
}
}
],
"fatal-warnings": fatal_warnings
}
def build_project(datafiles, fatal_warnings):
project_path = os.path.join(datafiles.dirname, datafiles.basename)
project = get_project(fatal_warnings)
_yaml.dump(project, os.path.join(project_path, "project.conf"))
return project_path
@pytest.mark.datafiles(TOP_DIR)
@pytest.mark.parametrize("element_name, fatal_warnings, expect_fatal, error_domain", [
("corewarn.bst", [CoreWarnings.OVERLAPS], True, ErrorDomain.STREAM),
("warninga.bst", ["warninga:warning-a"], True, ErrorDomain.STREAM),
("warningb.bst", ["warningb:warning-b"], True, ErrorDomain.STREAM),
("corewarn.bst", [], False, None),
("warninga.bst", [], False, None),
("warningb.bst", [], False, None),
("corewarn.bst", "true", True, ErrorDomain.STREAM),
("warninga.bst", "true", True, ErrorDomain.STREAM),
("warningb.bst", "true", True, ErrorDomain.STREAM),
("warninga.bst", [CoreWarnings.OVERLAPS], False, None),
("warningb.bst", [CoreWarnings.OVERLAPS], False, None),
])
def test_fatal_warnings(cli, datafiles, element_name,
fatal_warnings, expect_fatal, error_domain):
project_path = build_project(datafiles, fatal_warnings)
result = cli.run(project=project_path, args=["build", element_name])
if expect_fatal:
result.assert_main_error(error_domain, None, "Expected fatal execution")
else:
result.assert_success("Unexpected fatal execution")
kind: corewarn
\ No newline at end of file
kind: warninga
kind: warningb
from buildstream import Element
from buildstream.plugin import CoreWarnings
class CoreWarn(Element):
def configure(self, node):
pass
def preflight(self):
pass
def get_unique_key(self):
pass
def get_warnings(self):
return [] # CoreWarnings should be included regardless of plugins.
def configure_sandbox(self, sandbox):
pass
def stage(self, sandbox):
pass
def assemble(self, sandbox):
self.warn("Testing: CoreWarning produced during assemble",
warning_token=CoreWarnings.OVERLAPS)
def setup():
return CoreWarn
from buildstream import Element
WARNING_A = "warning-a"
class WarningA(Element):
def configure(self, node):
pass
def preflight(self):
pass
def get_unique_key(self):
pass
def configure_sandbox(self, sandbox):
pass
def stage(self, sandbox):
pass
def assemble(self, sandbox):
self.warn("Testing: warning-a produced during assemble", warning_token=WARNING_A)
def setup():
return WarningA
from buildstream import Element
WARNING_B = "warning-b"
class WarningB(Element):
def configure(self, node):
pass
def preflight(self):
pass
def get_unique_key(self):
pass
def configure_sandbox(self, sandbox):
pass
def stage(self, sandbox):
pass
def assemble(self, sandbox):
self.warn("Testing: warning-b produced during assemble", warning_token=WARNING_B)
def setup():
return WarningB
name: test
element-path: elements
plugins:
- origin: local
path: element_plugins
elements:
warninga: 0
warningb: 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment