You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Tools/LyTestTools/tests/unit/test_reg_cleaner.py

94 lines
3.8 KiB
Python

"""
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
import pytest
from pytest_mock import MockFixture
import ly_test_tools.environment.reg_cleaner
from ly_test_tools import WINDOWS
pytestmark = pytest.mark.SUITE_smoke
if not WINDOWS:
pytestmark = pytest.mark.skipif(
not WINDOWS,
reason="tests.unit.test_reg_cleaner is restricted to the Windows platform.")
def test_DeleteKey_KeyDoesNotExist_SilentlyFails(mocker):
# type: (MockFixture) -> None
mock_delete_child_keys_and_values = mocker.patch(
"ly_test_tools.environment.reg_cleaner._delete_child_keys_and_values")
mock_delete_child_keys_and_values.side_effect = WindowsError
ly_test_tools.environment.reg_cleaner._delete_key("key_1")
def test_DeleteKey_KeyIsEmpty_KeyDeleted(mocker):
# type: (MockFixture) -> None
mockwinreg = mocker.patch("ly_test_tools.environment.reg_cleaner.winreg")
mock_delete_child_keys_and_values = mocker.patch(
"ly_test_tools.environment.reg_cleaner._delete_child_keys_and_values")
mock_delete_child_keys_and_values.return_value = True
ly_test_tools.environment.reg_cleaner._delete_key("key_1")
assert mockwinreg.DeleteKey.called
def test_DeleteKey_KeyIsNotEmpty_KeyNotDeleted(mocker):
# type: (MockFixture) -> None
mockwinreg = mocker.patch("ly_test_tools.environment.reg_cleaner.winreg")
mock_delete_child_keys_and_values = mocker.patch(
"ly_test_tools.environment.reg_cleaner._delete_child_keys_and_values")
mock_delete_child_keys_and_values.return_value = False
ly_test_tools.environment.reg_cleaner._delete_key("key_1")
assert not mockwinreg.DeleteKey.called
def test_DeleteChildKeysAndValues_KeyDoesNotExist_RaisesWindowsError(mocker):
# type: (MockFixture) -> None
mockwinreg = mocker.patch("ly_test_tools.environment.reg_cleaner.winreg")
mockwinreg.OpenKey.side_effect = WindowsError
with pytest.raises(WindowsError):
ly_test_tools.environment.reg_cleaner._delete_child_keys_and_values("key_1")
def test_DeleteChildKeysAndValues_KeyIsEmpty_ReturnsTrue(mocker):
# type: (MockFixture) -> None
mockwinreg = mocker.patch("ly_test_tools.environment.reg_cleaner.winreg")
mockwinreg.EnumKey.side_effect = WindowsError
mockwinreg.EnumValue.side_effect = WindowsError
assert ly_test_tools.environment.reg_cleaner._delete_child_keys_and_values("key_1")
def test_DeleteChildKeysAndValues_KeyWithNoChildrenInExceptionList_ReturnsTrue(mocker):
# type: (MockFixture) -> None
mockwinreg = mocker.patch("ly_test_tools.environment.reg_cleaner.winreg")
mockwinreg.EnumKey.side_effect = ["child_key_1", WindowsError, WindowsError]
mockwinreg.EnumValue.side_effect = [WindowsError, ("child_value_1", None, None), WindowsError]
assert ly_test_tools.environment.reg_cleaner._delete_child_keys_and_values("key_1")
def test_DeleteChildKeysAndValues_KeyWithChildrenInExceptionList_ReturnsFalse(mocker):
# type: (MockFixture) -> None
mockwinreg = mocker.patch("ly_test_tools.environment.reg_cleaner.winreg")
mockwinreg.EnumKey.side_effect = ["child_key_1", WindowsError]
mockwinreg.EnumValue.side_effect = [("child_value_1", None, None), WindowsError]
exception_list = ["key_1\\child_key_1", "key_1\\child_value_1"]
assert not ly_test_tools.environment.reg_cleaner._delete_child_keys_and_values("key_1", exception_list)