From d53501a26ea1ab379bc6d555d9603fc3c4e37867 Mon Sep 17 00:00:00 2001 From: Callahan Kovacs Date: Tue, 15 Aug 2023 09:05:29 -0500 Subject: [PATCH] tests: add another test, mock platform Signed-off-by: Callahan Kovacs --- .../unit/pluginhandler/test_environment.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/legacy/unit/pluginhandler/test_environment.py b/tests/legacy/unit/pluginhandler/test_environment.py index b34c83ae14..284e281399 100644 --- a/tests/legacy/unit/pluginhandler/test_environment.py +++ b/tests/legacy/unit/pluginhandler/test_environment.py @@ -14,6 +14,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import sys + +import pytest + from snapcraft_legacy.internal.pluginhandler._part_environment import ( get_snapcraft_global_environment, ) @@ -21,6 +25,12 @@ from tests.legacy.fixture_setup import SnapcraftYaml +@pytest.fixture(autouse=True) +def mock_platform(mocker): + mocker.patch.object(sys, "platform", "linux") + mocker.patch("platform.machine", return_value="aarch64") + + def test_no_build_for_arch(tmp_path): """build-for envvars should exist when the build-for arch can be determined.""" snapcraft_yaml = SnapcraftYaml( @@ -45,6 +55,30 @@ def test_no_build_for_arch(tmp_path): ) +def test_implicit_build_for_arch(tmp_path): + """build-for envvars should exist for when the build-for arch is implicit.""" + snapcraft_yaml = SnapcraftYaml( + tmp_path, + base="core20", + parts={"test-part": {"plugin": "nil"}}, + architectures=[{"build-on": "arm64"}], + ) + snapcraft_yaml.write_snapcraft_yaml() + project = Project(snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path) + + environment = get_snapcraft_global_environment(project) + + assert environment["SNAPCRAFT_ARCH_BUILD_ON"] == project.arch_build_on + assert ( + environment["SNAPCRAFT_ARCH_TRIPLET_BUILD_ON"] == project.arch_triplet_build_on + ) + assert environment["SNAPCRAFT_ARCH_BUILD_FOR"] == project.arch_build_for + assert ( + environment["SNAPCRAFT_ARCH_TRIPLET_BUILD_FOR"] + == project.arch_triplet_build_for + ) + + def test_no_build_for_unknown_arch(tmp_path): """build-for envvars should not be defined for unknown build-for architectures.""" snapcraft_yaml = SnapcraftYaml(