test_launcher_linux.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 linux 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 TestLinuxLauncher(object):
  13. def test_Construct_TestDoubles_LinuxLauncherCreated(self):
  14. under_test = ly_test_tools.launchers.LinuxLauncher(mock.MagicMock(), ["some_args"])
  15. assert isinstance(under_test, ly_test_tools.launchers.Launcher)
  16. assert isinstance(under_test, ly_test_tools.launchers.LinuxLauncher)
  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.LinuxLauncher(mock_workspace, ["some_args"])
  24. under_test = launcher.binary_path()
  25. expected = os.path.join(dummy_path, f"{dummy_project}.GameLauncher")
  26. assert under_test == expected
  27. @mock.patch('ly_test_tools.launchers.LinuxLauncher.binary_path', mock.MagicMock)
  28. @mock.patch('subprocess.Popen')
  29. def test_Launch_DummyArgs_ArgsPassedToPopen(self, mock_subprocess):
  30. dummy_args = ["some_args"]
  31. launcher = ly_test_tools.launchers.LinuxLauncher(mock.MagicMock(), dummy_args)
  32. launcher.launch()
  33. mock_subprocess.assert_called_once()
  34. name, args, kwargs = mock_subprocess.mock_calls[0]
  35. unpacked_args = args[0] # args is a list inside a tuple
  36. assert len(dummy_args) > 0, "accidentally removed dummy_args"
  37. for expected_arg in dummy_args:
  38. assert expected_arg in unpacked_args
  39. @mock.patch('ly_test_tools.launchers.LinuxLauncher.is_alive')
  40. def test_Kill_MockAliveFalse_SilentSuccess(self, mock_alive):
  41. mock_alive.return_value = False
  42. mock_proc = mock.MagicMock()
  43. launcher = ly_test_tools.launchers.LinuxLauncher(mock.MagicMock(), ["dummy"])
  44. launcher._proc = mock_proc
  45. launcher.stop()
  46. mock_proc.kill.assert_called_once()
  47. mock_alive.assert_called()