Initial update for this module's unit tests on Linux

Signed-off-by: sweeneys <sweeneys@amazon.com>
This commit is contained in:
sweeneys
2021-09-22 17:50:12 -07:00
parent 92c4b22445
commit 09ce73aa44
14 changed files with 417 additions and 76 deletions
@@ -8,7 +8,6 @@ Unit tests for ly_test_tools.builtin.helpers functions.
"""
import unittest.mock as mock
import os
import pytest
import ly_test_tools.builtin.helpers
@@ -112,10 +111,11 @@ class TestBuiltinHelpers(object):
ly_test_tools._internal.managers.abstract_resource_locator._find_engine_root(
initial_path='mock_dev_dir')
@mock.patch('ly_test_tools._internal.managers.workspace.AbstractWorkspaceManager.teardown')
@mock.patch('ly_test_tools._internal.managers.workspace.AbstractWorkspaceManager.setup')
@mock.patch('ly_test_tools._internal.managers.artifact_manager.NullArtifactManager', mock.MagicMock())
@mock.patch('os.path.exists', mock.MagicMock(return_value=True))
def test_SetupBuiltinWorkspace_ValidWorkspaceSetup_ReturnsWorkspaceObject(self, mock_setup):
def test_SetupTeardownBuiltinWorkspace_ValidWorkspaceSetup_ReturnsWorkspaceObject(self, mock_setup, mock_teardown):
mock_test_name = 'mock_test_name'
mock_test_amount = 10
mock_workspace = ly_test_tools.builtin.helpers.create_builtin_workspace(
@@ -125,25 +125,16 @@ class TestBuiltinHelpers(object):
output_path='mock_output_path',
)
under_test = ly_test_tools.builtin.helpers.setup_builtin_workspace(
setup_test = ly_test_tools.builtin.helpers.setup_builtin_workspace(
mock_workspace, mock_test_name, mock_test_amount)
assert under_test == mock_workspace
assert setup_test == mock_workspace
assert mock_setup.call_count == 1
mock_workspace.artifact_manager.set_test_name.assert_called_with(
test_name=mock_test_name, amount=mock_test_amount)
@mock.patch('ly_test_tools._internal.managers.workspace.AbstractWorkspaceManager.teardown')
@mock.patch('os.path.exists', mock.MagicMock(return_value=True))
def test_TeardownBuiltinWorkspace_ValidWorkspaceSetup_ReturnsWorkspaceObject(self, mock_teardown):
mock_workspace = ly_test_tools.builtin.helpers.create_builtin_workspace(
build_directory='build_directory',
project='mock_project',
tmp_path='mock_tmp_path',
output_path='mock_output_path',
)
# Teardown not tested separately due to patched MockedAbstractResourceLocator creating a StopIteration error on Linux
teardown_test = ly_test_tools.builtin.helpers.teardown_builtin_workspace(mock_workspace)
under_test = ly_test_tools.builtin.helpers.teardown_builtin_workspace(mock_workspace)
assert under_test == mock_workspace
assert teardown_test == mock_workspace
assert mock_teardown.call_count == 1
@@ -208,20 +208,6 @@ class TestUnZip(unittest.TestCase):
self.assertEqual(path, expected_path)
@mock.patch('os.path.exists')
@mock.patch('ly_test_tools.environment.file_system.check_free_space')
@mock.patch('os.path.join')
def test_Unzip_ReleaseBuild_JoinCalledWithNoPathNoExtension(self, mock_join, mock_check_free, mock_exists):
path = ''
self.src_path = r'C:\packages\lumberyard-1.2.0.3-54321-pc-1234.zip'
mock_exists.return_value = self.exists
with mock.patch(self.decomp_obj_name, self.mock_decomp):
path = self.call_decomp(self.dest_path, self.src_path)
mock_join.assert_called_once_with(self.dest_path, 'lumberyard-1.2.0.3-54321-pc-1234')
@mock.patch('ly_test_tools.environment.file_system.logger')
@mock.patch('os.path.exists')
@mock.patch('ly_test_tools.environment.file_system.check_free_space')
@@ -375,20 +361,6 @@ class TestUnTgz(unittest.TestCase):
self.assertEqual(path, expected_path)
@mock.patch('ly_test_tools.environment.file_system.check_free_space')
@mock.patch('os.path.join')
@mock.patch('os.stat')
def test_Untgz_ReleaseBuild_JoinCalledWithNoPathNoExtension(self, mock_stat, mock_join, mock_check_free):
mock_stat.return_value = self.src_stat
path = ''
self.src_path = r'C:\packages\lumberyard-1.2.0.3-54321-pc-1234.zip'
with mock.patch(self.decomp_obj_name, self.mock_decomp):
path = self.call_decomp(self.dest_path, self.src_path)
mock_join.assert_called_once_with(self.dest_path, 'lumberyard-1.2.0.3-54321-pc-1234')
@mock.patch('ly_test_tools.environment.file_system.logger')
@mock.patch('os.path.exists')
@mock.patch('ly_test_tools.environment.file_system.check_free_space')
@@ -204,21 +204,20 @@ class TestLauncherBuilder(object):
"""
def test_CreateLauncher_DummyWorkspace_DefaultLauncher(self):
dummy_workspace = mock.MagicMock()
launcher_platform = 'windows'
under_test = ly_test_tools.launchers.launcher_helper.create_launcher(
dummy_workspace, launcher_platform)
dummy_workspace, ly_test_tools.HOST_OS_EDITOR)
assert isinstance(under_test, ly_test_tools.launchers.Launcher)
def test_CreateDedicateLauncher_DummyWorkspace_DefaultLauncher(self):
dummy_workspace = mock.MagicMock()
launcher_platform = 'windows_dedicated'
under_test = ly_test_tools.launchers.launcher_helper.create_dedicated_launcher(
dummy_workspace, launcher_platform)
dummy_workspace, ly_test_tools.HOST_OS_DEDICATED_SERVER)
assert isinstance(under_test, ly_test_tools.launchers.Launcher)
@mock.patch('os.path.exists', mock.MagicMock(return_value=True))
def test_CreateEditor_DummyWorkspace_DefaultLauncher(self):
dummy_workspace = mock.MagicMock()
launcher_platform = 'windows_editor'
dummy_workspace.paths.build_directory.return_value = 'dummy'
under_test = ly_test_tools.launchers.launcher_helper.create_editor(
dummy_workspace, launcher_platform)
dummy_workspace, ly_test_tools.HOST_OS_GENERIC_EXECUTABLE)
assert isinstance(under_test, ly_test_tools.launchers.Launcher)
@@ -0,0 +1,63 @@
"""
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 linux 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 TestLinuxLauncher(object):
def test_Construct_TestDoubles_LinuxLauncherCreated(self):
under_test = ly_test_tools.launchers.LinuxLauncher(mock.MagicMock(), ["some_args"])
assert isinstance(under_test, ly_test_tools.launchers.Launcher)
assert isinstance(under_test, ly_test_tools.launchers.LinuxLauncher)
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.LinuxLauncher(mock_workspace, ["some_args"])
under_test = launcher.binary_path()
expected = os.path.join(dummy_path, f"{dummy_project}.GameLauncher")
assert under_test == expected
@mock.patch('ly_test_tools.launchers.LinuxLauncher.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.LinuxLauncher(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.LinuxLauncher.is_alive')
def test_Kill_MockAliveFalse_SilentSuccess(self, mock_alive):
mock_alive.return_value = False
mock_proc = mock.MagicMock()
launcher = ly_test_tools.launchers.LinuxLauncher(mock.MagicMock(), ["dummy"])
launcher._proc = mock_proc
launcher.kill()
mock_proc.kill.assert_called_once()
mock_alive.assert_called_once()
@@ -191,7 +191,7 @@ class TestSubprocessCheckCallWrapperSafe(unittest.TestCase):
reason="tests.unit.test_process_utils is restricted to the Windows platform.")
class TestCloseWindowsProcess(unittest.TestCase):
@mock.patch('ly_test_tools.environment.process_utils.WINDOWS', False)
@mock.patch('ly_test_tools.WINDOWS', False)
def test_CloseWindowsProccess_NotOnWindows_Error(self):
with pytest.raises(NotImplementedError):
process_utils.close_windows_process(1)