summaryrefslogtreecommitdiff
path: root/tests/integration/shell.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration/shell.py')
-rw-r--r--tests/integration/shell.py142
1 files changed, 31 insertions, 111 deletions
diff --git a/tests/integration/shell.py b/tests/integration/shell.py
index 124770aad..e03b38563 100644
--- a/tests/integration/shell.py
+++ b/tests/integration/shell.py
@@ -32,13 +32,9 @@ DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project")
# element (str): The element to build and run a shell with
# isolate (bool): Whether to pass --isolate to `bst shell`
#
-def execute_shell(
- cli, project, command, *, config=None, mount=None, element="base.bst", isolate=False
-):
+def execute_shell(cli, project, command, *, config=None, mount=None, element="base.bst", isolate=False):
# Ensure the element is built
- result = cli.run_project_config(
- project=project, project_config=config, args=["build", element]
- )
+ result = cli.run_project_config(project=project, project_config=config, args=["build", element])
assert result.exit_code == 0
args = ["shell"]
@@ -55,9 +51,7 @@ def execute_shell(
# Test running something through a shell, allowing it to find the
# executable
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
def test_shell(cli, datafiles):
project = str(datafiles)
@@ -68,9 +62,7 @@ def test_shell(cli, datafiles):
# Test running an executable directly
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
def test_executable(cli, datafiles):
project = str(datafiles)
@@ -82,19 +74,14 @@ def test_executable(cli, datafiles):
# Test shell environment variable explicit assignments
@pytest.mark.parametrize("animal", [("Horse"), ("Pony")])
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
# This test seems to fail or pass depending on if this file is run or the hole test suite
def test_env_assign(cli, datafiles, animal):
project = str(datafiles)
expected = animal + "\n"
result = execute_shell(
- cli,
- project,
- ["/bin/sh", "-c", "echo ${ANIMAL}"],
- config={"shell": {"environment": {"ANIMAL": animal}}},
+ cli, project, ["/bin/sh", "-c", "echo ${ANIMAL}"], config={"shell": {"environment": {"ANIMAL": animal}}},
)
assert result.exit_code == 0
@@ -104,9 +91,7 @@ def test_env_assign(cli, datafiles, animal):
# Test shell environment variable explicit assignments with host env var expansion
@pytest.mark.parametrize("animal", [("Horse"), ("Pony")])
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
# This test seems to fail or pass depending on if this file is run or the hole test suite
def test_env_assign_expand_host_environ(cli, datafiles, animal):
project = str(datafiles)
@@ -129,9 +114,7 @@ def test_env_assign_expand_host_environ(cli, datafiles, animal):
# when running an isolated shell
@pytest.mark.parametrize("animal", [("Horse"), ("Pony")])
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
# This test seems to faili or pass depending on if this file is run or the hole test suite
def test_env_assign_isolated(cli, datafiles, animal):
project = str(datafiles)
@@ -150,9 +133,7 @@ def test_env_assign_isolated(cli, datafiles, animal):
# Test running an executable in a runtime with no shell (i.e., no
# /bin/sh)
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
def test_no_shell(cli, datafiles):
project = str(datafiles)
element_path = os.path.join(project, "elements")
@@ -165,14 +146,10 @@ def test_no_shell(cli, datafiles):
"variables": {"install-root": "/"},
"config": {"commands": ["rm /bin/sh"]},
}
- os.makedirs(
- os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True
- )
+ os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
_yaml.roundtrip_dump(element, os.path.join(element_path, element_name))
- result = execute_shell(
- cli, project, ["/bin/echo", "Pegasissies!"], element=element_name
- )
+ result = execute_shell(cli, project, ["/bin/echo", "Pegasissies!"], element=element_name)
assert result.exit_code == 0
assert result.output == "Pegasissies!\n"
@@ -180,18 +157,13 @@ def test_no_shell(cli, datafiles):
# Test that bind mounts defined in project.conf work
@pytest.mark.parametrize("path", [("/etc/pony.conf"), ("/usr/share/pony/pony.txt")])
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
@pytest.mark.xfail(HAVE_SANDBOX == "buildbox", reason="Not working with BuildBox")
def test_host_files(cli, datafiles, path):
project = str(datafiles)
ponyfile = os.path.join(project, "files", "shell-mount", "pony.txt")
result = execute_shell(
- cli,
- project,
- ["cat", path],
- config={"shell": {"host-files": [{"host_path": ponyfile, "path": path}]}},
+ cli, project, ["cat", path], config={"shell": {"host-files": [{"host_path": ponyfile, "path": path}]}},
)
assert result.exit_code == 0
assert result.output == "pony\n"
@@ -200,9 +172,7 @@ def test_host_files(cli, datafiles, path):
# Test that bind mounts defined in project.conf work
@pytest.mark.parametrize("path", [("/etc"), ("/usr/share/pony")])
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
@pytest.mark.xfail(HAVE_SANDBOX == "buildbox", reason="Not working with BuildBox")
def test_host_files_expand_environ(cli, datafiles, path):
project = str(datafiles)
@@ -217,14 +187,7 @@ def test_host_files_expand_environ(cli, datafiles, path):
project,
["cat", fullpath],
config={
- "shell": {
- "host-files": [
- {
- "host_path": "${HOST_PONY_PATH}/pony.txt",
- "path": "${BASE_PONY}/pony.txt",
- }
- ]
- }
+ "shell": {"host-files": [{"host_path": "${HOST_PONY_PATH}/pony.txt", "path": "${BASE_PONY}/pony.txt",}]}
},
)
assert result.exit_code == 0
@@ -234,9 +197,7 @@ def test_host_files_expand_environ(cli, datafiles, path):
# Test that bind mounts defined in project.conf dont mount in isolation
@pytest.mark.parametrize("path", [("/etc/pony.conf"), ("/usr/share/pony/pony.txt")])
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
def test_isolated_no_mount(cli, datafiles, path):
project = str(datafiles)
ponyfile = os.path.join(project, "files", "shell-mount", "pony.txt")
@@ -256,9 +217,7 @@ def test_isolated_no_mount(cli, datafiles, path):
# declared as optional, and that there is no warning if it is optional
@pytest.mark.parametrize("optional", [("mandatory"), ("optional")])
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
def test_host_files_missing(cli, datafiles, optional):
project = str(datafiles)
ponyfile = os.path.join(project, "files", "shell-mount", "horsy.txt")
@@ -270,17 +229,7 @@ def test_host_files_missing(cli, datafiles, optional):
cli,
project,
["echo", "Hello"],
- config={
- "shell": {
- "host-files": [
- {
- "host_path": ponyfile,
- "path": "/etc/pony.conf",
- "optional": option,
- }
- ]
- }
- },
+ config={"shell": {"host-files": [{"host_path": ponyfile, "path": "/etc/pony.conf", "optional": option,}]}},
)
assert result.exit_code == 0
assert result.output == "Hello\n"
@@ -296,9 +245,7 @@ def test_host_files_missing(cli, datafiles, optional):
# Test that bind mounts defined in project.conf work
@pytest.mark.parametrize("path", [("/etc/pony.conf"), ("/usr/share/pony/pony.txt")])
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
@pytest.mark.xfail(HAVE_SANDBOX == "buildbox", reason="Not working with BuildBox")
def test_cli_mount(cli, datafiles, path):
project = str(datafiles)
@@ -311,9 +258,7 @@ def test_cli_mount(cli, datafiles, path):
# Test that we can see the workspace files in a shell
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
def test_workspace_visible(cli, datafiles):
project = str(datafiles)
workspace = os.path.join(cli.directory, "workspace")
@@ -321,10 +266,7 @@ def test_workspace_visible(cli, datafiles):
# Open a workspace on our build failing element
#
- res = cli.run(
- project=project,
- args=["workspace", "open", "--directory", workspace, element_name],
- )
+ res = cli.run(project=project, args=["workspace", "open", "--directory", workspace, element_name],)
assert res.exit_code == 0
# Ensure the dependencies of our build failing element are built
@@ -341,18 +283,14 @@ def test_workspace_visible(cli, datafiles):
# Cat the hello.c file from a bst shell command, and assert
# that we got the same content here
#
- result = cli.run(
- project=project, args=["shell", "--build", element_name, "--", "cat", "hello.c"]
- )
+ result = cli.run(project=project, args=["shell", "--build", element_name, "--", "cat", "hello.c"])
assert result.exit_code == 0
assert result.output == workspace_hello
# Test that '--sysroot' works
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
@pytest.mark.xfail(HAVE_SANDBOX == "buildbox", reason="Not working with BuildBox")
def test_sysroot(cli, tmpdir, datafiles):
project = str(datafiles)
@@ -365,10 +303,7 @@ def test_sysroot(cli, tmpdir, datafiles):
# Build and check out a sysroot
res = cli.run(project=project, args=["build", base_element])
res.assert_success()
- res = cli.run(
- project=project,
- args=["artifact", "checkout", base_element, "--directory", checkout_dir],
- )
+ res = cli.run(project=project, args=["artifact", "checkout", base_element, "--directory", checkout_dir],)
res.assert_success()
# Mutate the sysroot
@@ -397,9 +332,7 @@ def test_sysroot(cli, tmpdir, datafiles):
# Test system integration commands can access devices in /dev
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
def test_integration_devices(cli, datafiles):
project = str(datafiles)
element_name = "integration.bst"
@@ -412,12 +345,8 @@ def test_integration_devices(cli, datafiles):
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
@pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
-def test_integration_external_workspace(
- cli, tmpdir_factory, datafiles, build_shell, guess_element
-):
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
+def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell, guess_element):
tmpdir = tmpdir_factory.mktemp("")
project = str(datafiles)
element_name = "autotools/amhello.bst"
@@ -430,10 +359,7 @@ def test_integration_external_workspace(
with open(project_file, "a") as f:
f.write(config_text)
- result = cli.run(
- project=project,
- args=["workspace", "open", "--directory", workspace_dir, element_name],
- )
+ result = cli.run(project=project, args=["workspace", "open", "--directory", workspace_dir, element_name],)
result.assert_success()
result = cli.run(project=project, args=["-C", workspace_dir, "build", element_name])
@@ -449,9 +375,7 @@ def test_integration_external_workspace(
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.skipif(
- not HAVE_SANDBOX, reason="Only available with a functioning sandbox"
-)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
def test_integration_partial_artifact(cli, datafiles, tmpdir, integration_cache):
project = str(datafiles)
@@ -484,9 +408,7 @@ def test_integration_partial_artifact(cli, datafiles, tmpdir, integration_cache)
],
)
result.assert_success()
- digest = utils.sha256sum(
- os.path.join(str(tmpdir), "tmp", "usr", "bin", "hello")
- )
+ digest = utils.sha256sum(os.path.join(str(tmpdir), "tmp", "usr", "bin", "hello"))
# Remove the binary from the CAS
cachedir = cli.config["cachedir"]
@@ -498,8 +420,6 @@ def test_integration_partial_artifact(cli, datafiles, tmpdir, integration_cache)
result.assert_main_error(ErrorDomain.APP, None)
# check the artifact gets completed with '--pull' specified
- result = cli.run(
- project=project, args=["shell", "--pull", element_name, "--", "hello"]
- )
+ result = cli.run(project=project, args=["shell", "--pull", element_name, "--", "hello"])
result.assert_success()
assert "autotools/amhello.bst" in result.get_pulled_elements()