summaryrefslogtreecommitdiff
path: root/tests/format
diff options
context:
space:
mode:
Diffstat (limited to 'tests/format')
-rw-r--r--tests/format/optionarch.py32
-rw-r--r--tests/format/optionos.py27
2 files changed, 14 insertions, 45 deletions
diff --git a/tests/format/optionarch.py b/tests/format/optionarch.py
index 86363b834..3f779e5ea 100644
--- a/tests/format/optionarch.py
+++ b/tests/format/optionarch.py
@@ -1,7 +1,6 @@
# Pylint doesn't play well with fixtures and dependency injection from pytest
# pylint: disable=redefined-outer-name
-from contextlib import contextmanager
import os
import pytest
@@ -10,29 +9,14 @@ from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream.plugintestutils.runcli import cli # pylint: disable=unused-import
+from tests.testutils import override_os_uname
+
# Project directory
DATA_DIR = os.path.dirname(os.path.realpath(__file__))
-# Context manager to override the reported value of `os.uname()`
-@contextmanager
-def override_uname_arch(name):
- orig_uname = os.uname
- orig_tuple = tuple(os.uname())
- override_result = (orig_tuple[0], orig_tuple[1],
- orig_tuple[2], orig_tuple[3],
- name)
-
- def override():
- return override_result
-
- os.uname = override
- yield
- os.uname = orig_uname
-
-
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.parametrize("uname,value,expected", [
+@pytest.mark.parametrize("machine,value,expected", [
# Test explicitly provided arches
('arm', 'aarch32', 'Army'),
('arm', 'aarch64', 'Aarchy'),
@@ -46,8 +30,8 @@ def override_uname_arch(name):
('i386', 'aarch32', 'Army'),
('x86_64', 'aarch64', 'Aarchy'),
])
-def test_conditional(cli, datafiles, uname, value, expected):
- with override_uname_arch(uname):
+def test_conditional(cli, datafiles, machine, value, expected):
+ with override_os_uname(machine=machine):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch')
bst_args = []
@@ -70,7 +54,7 @@ def test_conditional(cli, datafiles, uname, value, expected):
@pytest.mark.datafiles(DATA_DIR)
def test_unsupported_arch(cli, datafiles):
- with override_uname_arch("x86_64"):
+ with override_os_uname(machine="x86_64"):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch')
result = cli.run(project=project, silent=True, args=[
'show',
@@ -85,7 +69,7 @@ def test_unsupported_arch(cli, datafiles):
@pytest.mark.datafiles(DATA_DIR)
def test_alias(cli, datafiles):
- with override_uname_arch("arm"):
+ with override_os_uname(machine="arm"):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch-alias')
result = cli.run(project=project, silent=True, args=[
'show',
@@ -100,7 +84,7 @@ def test_alias(cli, datafiles):
@pytest.mark.datafiles(DATA_DIR)
def test_unknown_host_arch(cli, datafiles):
- with override_uname_arch("x86_128"):
+ with override_os_uname(machine="x86_128"):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch')
result = cli.run(project=project, silent=True, args=[
'show',
diff --git a/tests/format/optionos.py b/tests/format/optionos.py
index 989989a99..a4e2a6cf9 100644
--- a/tests/format/optionos.py
+++ b/tests/format/optionos.py
@@ -1,7 +1,6 @@
# Pylint doesn't play well with fixtures and dependency injection from pytest
# pylint: disable=redefined-outer-name
-from contextlib import contextmanager
import os
import pytest
@@ -10,27 +9,13 @@ from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream.plugintestutils.runcli import cli # pylint: disable=unused-import
-DATA_DIR = os.path.dirname(os.path.realpath(__file__))
-
-
-@contextmanager
-def override_uname_os(name):
- orig_uname = os.uname
- orig_tuple = tuple(os.uname())
- override_result = (name, orig_tuple[1],
- orig_tuple[2], orig_tuple[3],
- orig_tuple[4])
+from tests.testutils import override_os_uname
- def override():
- return override_result
-
- os.uname = override
- yield
- os.uname = orig_uname
+DATA_DIR = os.path.dirname(os.path.realpath(__file__))
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.parametrize("uname,value,expected", [
+@pytest.mark.parametrize("system,value,expected", [
# Test explicitly provided arches
('Darwin', 'Linux', 'Linuxy'),
('SunOS', 'FreeBSD', 'FreeBSDy'),
@@ -44,8 +29,8 @@ def override_uname_os(name):
('AIX', 'Linux', 'Linuxy'),
('HaikuOS', 'SunOS', 'SunOSy'),
])
-def test_conditionals(cli, datafiles, uname, value, expected):
- with override_uname_os(uname):
+def test_conditionals(cli, datafiles, system, value, expected):
+ with override_os_uname(system=system):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-os')
bst_args = []
@@ -68,7 +53,7 @@ def test_conditionals(cli, datafiles, uname, value, expected):
@pytest.mark.datafiles(DATA_DIR)
def test_unsupported_arch(cli, datafiles):
- with override_uname_os("AIX"):
+ with override_os_uname(system="AIX"):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-os')
result = cli.run(project=project, silent=True, args=[
'show',