123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- """
- Copyright (c) Contributors to the Open 3D Engine Project.
- For complete copyright and license terms please see the LICENSE at the root of this distribution.
- SPDX-License-Identifier: Apache-2.0 OR MIT
- Unit Tests for mac launcher-wrappers: all are sanity code-path tests, since no interprocess actions should be taken
- """
- import os
- import pytest
- import unittest.mock as mock
- import ly_test_tools.launchers
- pytestmark = pytest.mark.SUITE_smoke
- class TestMacLauncher(object):
- def test_Construct_TestDoubles_MacLauncherCreated(self):
- under_test = ly_test_tools.launchers.MacLauncher(mock.MagicMock(), ["some_args"])
- assert isinstance(under_test, ly_test_tools.launchers.Launcher)
- assert isinstance(under_test, ly_test_tools.launchers.MacLauncher)
- def test_BinaryPath_DummyPath_AddPathToApp(self):
- dummy_path = "dummy_workspace_path"
- dummy_project = "dummy_project"
- mock_workspace = mock.MagicMock()
- mock_workspace.paths.build_directory.return_value = dummy_path
- mock_workspace.project = dummy_project
- launcher = ly_test_tools.launchers.MacLauncher(mock_workspace, ["some_args"])
- under_test = launcher.binary_path()
- expected = os.path.join(f'{dummy_path}',
- f"{dummy_project}.GameLauncher.app",
- "Contents",
- "MacOS",
- f"{dummy_project}.GameLauncher")
- assert under_test == expected
- @mock.patch('ly_test_tools.launchers.MacLauncher.binary_path', mock.MagicMock)
- @mock.patch('subprocess.Popen')
- def test_Launch_DummyArgs_ArgsPassedToPopen(self, mock_subprocess):
- dummy_args = ["some_args"]
- launcher = ly_test_tools.launchers.MacLauncher(mock.MagicMock(), dummy_args)
- launcher.launch()
- mock_subprocess.assert_called_once()
- name, args, kwargs = mock_subprocess.mock_calls[0]
- unpacked_args = args[0] # args is a list inside a tuple
- assert len(dummy_args) > 0, "accidentally removed dummy_args"
- for expected_arg in dummy_args:
- assert expected_arg in unpacked_args
- @mock.patch('ly_test_tools.launchers.MacLauncher.is_alive')
- def test_Kill_MockAliveFalse_SilentSuccess(self, mock_alive):
- mock_alive.return_value = False
- mock_proc = mock.MagicMock()
- launcher = ly_test_tools.launchers.MacLauncher(mock.MagicMock(), ["dummy"])
- launcher._proc = mock_proc
- launcher.stop()
- mock_proc.kill.assert_called_once()
- mock_alive.assert_called()
|