test_launcher_mac.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. Unit Tests for mac launcher-wrappers: all are sanity code-path tests, since no interprocess actions should be taken
  6. """
  7. import os
  8. import pytest
  9. import unittest.mock as mock
  10. import ly_test_tools.launchers
  11. pytestmark = pytest.mark.SUITE_smoke
  12. class TestMacLauncher(object):
  13. def test_Construct_TestDoubles_MacLauncherCreated(self):
  14. under_test = ly_test_tools.launchers.MacLauncher(mock.MagicMock(), ["some_args"])
  15. assert isinstance(under_test, ly_test_tools.launchers.Launcher)
  16. assert isinstance(under_test, ly_test_tools.launchers.MacLauncher)
  17. def test_BinaryPath_DummyPath_AddPathToApp(self):
  18. dummy_path = "dummy_workspace_path"
  19. dummy_project = "dummy_project"
  20. mock_workspace = mock.MagicMock()
  21. mock_workspace.paths.build_directory.return_value = dummy_path
  22. mock_workspace.project = dummy_project
  23. launcher = ly_test_tools.launchers.MacLauncher(mock_workspace, ["some_args"])
  24. under_test = launcher.binary_path()
  25. expected = os.path.join(f'{dummy_path}',
  26. f"{dummy_project}.GameLauncher.app",
  27. "Contents",
  28. "MacOS",
  29. f"{dummy_project}.GameLauncher")
  30. assert under_test == expected
  31. @mock.patch('ly_test_tools.launchers.MacLauncher.binary_path', mock.MagicMock)
  32. @mock.patch('subprocess.Popen')
  33. def test_Launch_DummyArgs_ArgsPassedToPopen(self, mock_subprocess):
  34. dummy_args = ["some_args"]
  35. launcher = ly_test_tools.launchers.MacLauncher(mock.MagicMock(), dummy_args)
  36. launcher.launch()
  37. mock_subprocess.assert_called_once()
  38. name, args, kwargs = mock_subprocess.mock_calls[0]
  39. unpacked_args = args[0] # args is a list inside a tuple
  40. assert len(dummy_args) > 0, "accidentally removed dummy_args"
  41. for expected_arg in dummy_args:
  42. assert expected_arg in unpacked_args
  43. @mock.patch('ly_test_tools.launchers.MacLauncher.is_alive')
  44. def test_Kill_MockAliveFalse_SilentSuccess(self, mock_alive):
  45. mock_alive.return_value = False
  46. mock_proc = mock.MagicMock()
  47. launcher = ly_test_tools.launchers.MacLauncher(mock.MagicMock(), ["dummy"])
  48. launcher._proc = mock_proc
  49. launcher.stop()
  50. mock_proc.kill.assert_called_once()
  51. mock_alive.assert_called()