Addon Manager: Reformat with new Black line length
This commit is contained in:
committed by
Chris Hennes
parent
c989a8506e
commit
89579cff6e
@@ -148,9 +148,7 @@ class MockMacro:
|
||||
with open(os.path.join(location, self.icon), "wb") as f:
|
||||
f.write(b"Fake icon data - nothing to see here\n")
|
||||
if self.xpm:
|
||||
with open(
|
||||
os.path.join(location, "MockMacro_icon.xpm"), "w", encoding="utf-8"
|
||||
) as f:
|
||||
with open(os.path.join(location, "MockMacro_icon.xpm"), "w", encoding="utf-8") as f:
|
||||
f.write(self.xpm)
|
||||
for name in self.other_files:
|
||||
if "/" in name:
|
||||
@@ -233,12 +231,8 @@ class MockGitManager:
|
||||
self.current_branch_response = "main"
|
||||
self.get_remote_response = "No remote set"
|
||||
self.get_branches_response = ["main"]
|
||||
self.get_last_committers_response = {
|
||||
"John Doe": {"email": "jdoe@freecad.org", "count": 1}
|
||||
}
|
||||
self.get_last_authors_response = {
|
||||
"Jane Doe": {"email": "jdoe@freecad.org", "count": 1}
|
||||
}
|
||||
self.get_last_committers_response = {"John Doe": {"email": "jdoe@freecad.org", "count": 1}}
|
||||
self.get_last_authors_response = {"Jane Doe": {"email": "jdoe@freecad.org", "count": 1}}
|
||||
self.should_fail = False
|
||||
self.fail_once = False # Switch back to success after the simulated failure
|
||||
|
||||
@@ -252,9 +246,7 @@ class MockGitManager:
|
||||
self.called_methods.append("clone")
|
||||
self._check_for_failure()
|
||||
|
||||
def async_clone(
|
||||
self, _remote, _local_path, _progress_monitor, _args: List[str] = None
|
||||
):
|
||||
def async_clone(self, _remote, _local_path, _progress_monitor, _args: List[str] = None):
|
||||
self.called_methods.append("async_clone")
|
||||
self._check_for_failure()
|
||||
|
||||
|
||||
@@ -89,9 +89,7 @@ class TestAddon(unittest.TestCase):
|
||||
Addon.Status.NOT_INSTALLED,
|
||||
"master",
|
||||
)
|
||||
addon_with_workbench.load_metadata_file(
|
||||
os.path.join(self.test_dir, "workbench_only.xml")
|
||||
)
|
||||
addon_with_workbench.load_metadata_file(os.path.join(self.test_dir, "workbench_only.xml"))
|
||||
self.assertTrue(addon_with_workbench.contains_workbench())
|
||||
self.assertFalse(addon_with_workbench.contains_macro())
|
||||
self.assertFalse(addon_with_workbench.contains_preference_pack())
|
||||
@@ -103,9 +101,7 @@ class TestAddon(unittest.TestCase):
|
||||
Addon.Status.NOT_INSTALLED,
|
||||
"master",
|
||||
)
|
||||
addon_with_macro.load_metadata_file(
|
||||
os.path.join(self.test_dir, "macro_only.xml")
|
||||
)
|
||||
addon_with_macro.load_metadata_file(os.path.join(self.test_dir, "macro_only.xml"))
|
||||
self.assertFalse(addon_with_macro.contains_workbench())
|
||||
self.assertTrue(addon_with_macro.contains_macro())
|
||||
self.assertFalse(addon_with_macro.contains_preference_pack())
|
||||
@@ -117,9 +113,7 @@ class TestAddon(unittest.TestCase):
|
||||
Addon.Status.NOT_INSTALLED,
|
||||
"master",
|
||||
)
|
||||
addon_with_prefpack.load_metadata_file(
|
||||
os.path.join(self.test_dir, "prefpack_only.xml")
|
||||
)
|
||||
addon_with_prefpack.load_metadata_file(os.path.join(self.test_dir, "prefpack_only.xml"))
|
||||
self.assertFalse(addon_with_prefpack.contains_workbench())
|
||||
self.assertFalse(addon_with_prefpack.contains_macro())
|
||||
self.assertTrue(addon_with_prefpack.contains_preference_pack())
|
||||
@@ -131,9 +125,7 @@ class TestAddon(unittest.TestCase):
|
||||
Addon.Status.NOT_INSTALLED,
|
||||
"master",
|
||||
)
|
||||
addon_with_all.load_metadata_file(
|
||||
os.path.join(self.test_dir, "combination.xml")
|
||||
)
|
||||
addon_with_all.load_metadata_file(os.path.join(self.test_dir, "combination.xml"))
|
||||
self.assertTrue(addon_with_all.contains_workbench())
|
||||
self.assertTrue(addon_with_all.contains_macro())
|
||||
self.assertTrue(addon_with_all.contains_preference_pack())
|
||||
@@ -263,9 +255,7 @@ class TestAddon(unittest.TestCase):
|
||||
Addon.Status.NOT_INSTALLED,
|
||||
"master",
|
||||
)
|
||||
addon.load_metadata_file(
|
||||
os.path.join(self.test_dir, "depends_on_all_workbenches.xml")
|
||||
)
|
||||
addon.load_metadata_file(os.path.join(self.test_dir, "depends_on_all_workbenches.xml"))
|
||||
deps = Addon.Dependencies()
|
||||
addon.walk_dependency_tree({}, deps)
|
||||
self.assertEqual(len(deps.internal_workbenches), len(INTERNAL_WORKBENCHES))
|
||||
@@ -277,9 +267,7 @@ class TestAddon(unittest.TestCase):
|
||||
Addon.Status.NOT_INSTALLED,
|
||||
"master",
|
||||
)
|
||||
addon.load_metadata_file(
|
||||
os.path.join(self.test_dir, "test_version_detection.xml")
|
||||
)
|
||||
addon.load_metadata_file(os.path.join(self.test_dir, "test_version_detection.xml"))
|
||||
|
||||
self.assertEqual(
|
||||
len(addon.tags),
|
||||
|
||||
@@ -74,19 +74,11 @@ class TestDependencyInstaller(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.subprocess_mock = SubprocessMock()
|
||||
self.test_object = DependencyInstaller(
|
||||
[], ["required_py_package"], ["optional_py_package"]
|
||||
)
|
||||
self.test_object._subprocess_wrapper = (
|
||||
self.subprocess_mock.subprocess_interceptor
|
||||
)
|
||||
self.test_object = DependencyInstaller([], ["required_py_package"], ["optional_py_package"])
|
||||
self.test_object._subprocess_wrapper = self.subprocess_mock.subprocess_interceptor
|
||||
self.signals_caught = []
|
||||
self.test_object.failure.connect(
|
||||
functools.partial(self.catch_signal, "failure")
|
||||
)
|
||||
self.test_object.finished.connect(
|
||||
functools.partial(self.catch_signal, "finished")
|
||||
)
|
||||
self.test_object.failure.connect(functools.partial(self.catch_signal, "failure"))
|
||||
self.test_object.finished.connect(functools.partial(self.catch_signal, "finished"))
|
||||
self.test_object.no_pip.connect(functools.partial(self.catch_signal, "no_pip"))
|
||||
self.test_object.no_python_exe.connect(
|
||||
functools.partial(self.catch_signal, "no_python_exe")
|
||||
|
||||
@@ -64,9 +64,7 @@ class TestConsole(unittest.TestCase):
|
||||
"""Test that if the FreeCAD import fails, the logger is set up correctly, and
|
||||
implements PrintLog"""
|
||||
sys.modules["FreeCAD"] = None
|
||||
with patch(
|
||||
"addonmanager_freecad_interface.logging", new=MagicMock()
|
||||
) as mock_logging:
|
||||
with patch("addonmanager_freecad_interface.logging", new=MagicMock()) as mock_logging:
|
||||
import addonmanager_freecad_interface as fc
|
||||
|
||||
fc.Console.PrintLog("Test output")
|
||||
@@ -76,9 +74,7 @@ class TestConsole(unittest.TestCase):
|
||||
def test_message_no_freecad(self):
|
||||
"""Test that if the FreeCAD import fails the logger implements PrintMessage"""
|
||||
sys.modules["FreeCAD"] = None
|
||||
with patch(
|
||||
"addonmanager_freecad_interface.logging", new=MagicMock()
|
||||
) as mock_logging:
|
||||
with patch("addonmanager_freecad_interface.logging", new=MagicMock()) as mock_logging:
|
||||
import addonmanager_freecad_interface as fc
|
||||
|
||||
fc.Console.PrintMessage("Test output")
|
||||
@@ -87,9 +83,7 @@ class TestConsole(unittest.TestCase):
|
||||
def test_warning_no_freecad(self):
|
||||
"""Test that if the FreeCAD import fails the logger implements PrintWarning"""
|
||||
sys.modules["FreeCAD"] = None
|
||||
with patch(
|
||||
"addonmanager_freecad_interface.logging", new=MagicMock()
|
||||
) as mock_logging:
|
||||
with patch("addonmanager_freecad_interface.logging", new=MagicMock()) as mock_logging:
|
||||
import addonmanager_freecad_interface as fc
|
||||
|
||||
fc.Console.PrintWarning("Test output")
|
||||
@@ -98,9 +92,7 @@ class TestConsole(unittest.TestCase):
|
||||
def test_error_no_freecad(self):
|
||||
"""Test that if the FreeCAD import fails the logger implements PrintError"""
|
||||
sys.modules["FreeCAD"] = None
|
||||
with patch(
|
||||
"addonmanager_freecad_interface.logging", new=MagicMock()
|
||||
) as mock_logging:
|
||||
with patch("addonmanager_freecad_interface.logging", new=MagicMock()) as mock_logging:
|
||||
import addonmanager_freecad_interface as fc
|
||||
|
||||
fc.Console.PrintError("Test output")
|
||||
|
||||
@@ -78,9 +78,7 @@ class TestGit(unittest.TestCase):
|
||||
checkout_dir = self._clone_test_repo()
|
||||
self.assertTrue(os.path.exists(checkout_dir))
|
||||
self.assertTrue(os.path.exists(os.path.join(checkout_dir, ".git")))
|
||||
self.assertEqual(
|
||||
os.getcwd(), self.cwd, "We should be left in the same CWD we started"
|
||||
)
|
||||
self.assertEqual(os.getcwd(), self.cwd, "We should be left in the same CWD we started")
|
||||
|
||||
def test_checkout(self):
|
||||
"""Test git checkout"""
|
||||
@@ -91,9 +89,7 @@ class TestGit(unittest.TestCase):
|
||||
expected_status = "## HEAD (no branch)"
|
||||
self.assertEqual(status, expected_status)
|
||||
|
||||
self.assertEqual(
|
||||
os.getcwd(), self.cwd, "We should be left in the same CWD we started"
|
||||
)
|
||||
self.assertEqual(os.getcwd(), self.cwd, "We should be left in the same CWD we started")
|
||||
|
||||
def test_update(self):
|
||||
"""Test using git to update the local repo"""
|
||||
@@ -103,9 +99,7 @@ class TestGit(unittest.TestCase):
|
||||
self.assertTrue(self.git.update_available(checkout_dir))
|
||||
self.git.update(checkout_dir)
|
||||
self.assertFalse(self.git.update_available(checkout_dir))
|
||||
self.assertEqual(
|
||||
os.getcwd(), self.cwd, "We should be left in the same CWD we started"
|
||||
)
|
||||
self.assertEqual(os.getcwd(), self.cwd, "We should be left in the same CWD we started")
|
||||
|
||||
def test_tag_and_branch(self):
|
||||
"""Test checking the currently checked-out tag"""
|
||||
@@ -129,9 +123,7 @@ class TestGit(unittest.TestCase):
|
||||
self.assertEqual(found_branch, expected_branch)
|
||||
self.assertFalse(self.git.update_available(checkout_dir))
|
||||
|
||||
self.assertEqual(
|
||||
os.getcwd(), self.cwd, "We should be left in the same CWD we started"
|
||||
)
|
||||
self.assertEqual(os.getcwd(), self.cwd, "We should be left in the same CWD we started")
|
||||
|
||||
def test_get_remote(self):
|
||||
"""Test getting the remote location"""
|
||||
@@ -139,9 +131,7 @@ class TestGit(unittest.TestCase):
|
||||
expected_remote = self.test_repo_remote
|
||||
returned_remote = self.git.get_remote(checkout_dir)
|
||||
self.assertEqual(expected_remote, returned_remote)
|
||||
self.assertEqual(
|
||||
os.getcwd(), self.cwd, "We should be left in the same CWD we started"
|
||||
)
|
||||
self.assertEqual(os.getcwd(), self.cwd, "We should be left in the same CWD we started")
|
||||
|
||||
def test_repair(self):
|
||||
"""Test the repair feature (and some exception throwing)"""
|
||||
@@ -158,9 +148,7 @@ class TestGit(unittest.TestCase):
|
||||
self.git.repair(remote, checkout_dir)
|
||||
status = self.git.status(checkout_dir)
|
||||
self.assertEqual(status, "## main...origin/main\n")
|
||||
self.assertEqual(
|
||||
os.getcwd(), self.cwd, "We should be left in the same CWD we started"
|
||||
)
|
||||
self.assertEqual(os.getcwd(), self.cwd, "We should be left in the same CWD we started")
|
||||
|
||||
def _rmdir(self, path):
|
||||
try:
|
||||
|
||||
@@ -116,9 +116,7 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
os.path.join(self.test_data_dir, "good_package.xml"),
|
||||
os.path.join(addon_dir, "package.xml"),
|
||||
)
|
||||
good_metadata = MetadataReader.from_file(
|
||||
os.path.join(addon_dir, "package.xml")
|
||||
)
|
||||
good_metadata = MetadataReader.from_file(os.path.join(addon_dir, "package.xml"))
|
||||
installer._update_metadata()
|
||||
self.assertEqual(self.real_addon.installed_version, good_metadata.version)
|
||||
|
||||
@@ -133,34 +131,24 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
installer.installation_path = temp_dir
|
||||
installer._finalize_zip_installation(test_simple_repo)
|
||||
expected_location = os.path.join(temp_dir, non_gh_mock.name, "README")
|
||||
self.assertTrue(
|
||||
os.path.isfile(expected_location), "Non-GitHub zip extraction failed"
|
||||
)
|
||||
self.assertTrue(os.path.isfile(expected_location), "Non-GitHub zip extraction failed")
|
||||
|
||||
def test_finalize_zip_installation_github(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
test_github_style_repo = os.path.join(
|
||||
self.test_data_dir, "test_github_style_repo.zip"
|
||||
)
|
||||
test_github_style_repo = os.path.join(self.test_data_dir, "test_github_style_repo.zip")
|
||||
self.mock_addon.url = test_github_style_repo
|
||||
self.mock_addon.branch = "master"
|
||||
installer = AddonInstaller(self.mock_addon, [])
|
||||
installer.installation_path = temp_dir
|
||||
installer._finalize_zip_installation(test_github_style_repo)
|
||||
expected_location = os.path.join(temp_dir, self.mock_addon.name, "README")
|
||||
self.assertTrue(
|
||||
os.path.isfile(expected_location), "GitHub zip extraction failed"
|
||||
)
|
||||
self.assertTrue(os.path.isfile(expected_location), "GitHub zip extraction failed")
|
||||
|
||||
def test_code_in_branch_subdirectory_true(self):
|
||||
"""When there is a subdirectory with the branch name in it, find it"""
|
||||
installer = AddonInstaller(self.mock_addon, [])
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
os.mkdir(
|
||||
os.path.join(
|
||||
temp_dir, f"{self.mock_addon.name}-{self.mock_addon.branch}"
|
||||
)
|
||||
)
|
||||
os.mkdir(os.path.join(temp_dir, f"{self.mock_addon.name}-{self.mock_addon.branch}"))
|
||||
result = installer._code_in_branch_subdirectory(temp_dir)
|
||||
self.assertTrue(result, "Failed to find ZIP subdirectory")
|
||||
|
||||
@@ -176,30 +164,20 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
"""When there are multiple subdirectories, never find a branch subdirectory"""
|
||||
installer = AddonInstaller(self.mock_addon, [])
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
os.mkdir(
|
||||
os.path.join(
|
||||
temp_dir, f"{self.mock_addon.name}-{self.mock_addon.branch}"
|
||||
)
|
||||
)
|
||||
os.mkdir(os.path.join(temp_dir, f"{self.mock_addon.name}-{self.mock_addon.branch}"))
|
||||
os.mkdir(os.path.join(temp_dir, "AnotherSubdir"))
|
||||
result = installer._code_in_branch_subdirectory(temp_dir)
|
||||
self.assertFalse(
|
||||
result, "Found ZIP subdirectory when there were multiple subdirs"
|
||||
)
|
||||
self.assertFalse(result, "Found ZIP subdirectory when there were multiple subdirs")
|
||||
|
||||
def test_move_code_out_of_subdirectory(self):
|
||||
"""All files are moved out and the subdirectory is deleted"""
|
||||
installer = AddonInstaller(self.mock_addon, [])
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
subdir = os.path.join(
|
||||
temp_dir, f"{self.mock_addon.name}-{self.mock_addon.branch}"
|
||||
)
|
||||
subdir = os.path.join(temp_dir, f"{self.mock_addon.name}-{self.mock_addon.branch}")
|
||||
os.mkdir(subdir)
|
||||
with open(os.path.join(subdir, "README.txt"), "w", encoding="utf-8") as f:
|
||||
f.write("# Test file for unit testing")
|
||||
with open(
|
||||
os.path.join(subdir, "AnotherFile.txt"), "w", encoding="utf-8"
|
||||
) as f:
|
||||
with open(os.path.join(subdir, "AnotherFile.txt"), "w", encoding="utf-8") as f:
|
||||
f.write("# Test file for unit testing")
|
||||
installer._move_code_out_of_subdirectory(temp_dir)
|
||||
self.assertTrue(os.path.isfile(os.path.join(temp_dir, "README.txt")))
|
||||
@@ -260,23 +238,15 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
installer = AddonInstaller(self.mock_addon, [])
|
||||
method = installer._determine_install_method(
|
||||
temp_dir, InstallationMethod.COPY
|
||||
)
|
||||
method = installer._determine_install_method(temp_dir, InstallationMethod.COPY)
|
||||
self.assertEqual(method, InstallationMethod.COPY)
|
||||
git_manager = initialize_git()
|
||||
if git_manager:
|
||||
method = installer._determine_install_method(
|
||||
temp_dir, InstallationMethod.GIT
|
||||
)
|
||||
method = installer._determine_install_method(temp_dir, InstallationMethod.GIT)
|
||||
self.assertEqual(method, InstallationMethod.GIT)
|
||||
method = installer._determine_install_method(
|
||||
temp_dir, InstallationMethod.ZIP
|
||||
)
|
||||
method = installer._determine_install_method(temp_dir, InstallationMethod.ZIP)
|
||||
self.assertIsNone(method)
|
||||
method = installer._determine_install_method(
|
||||
temp_dir, InstallationMethod.ANY
|
||||
)
|
||||
method = installer._determine_install_method(temp_dir, InstallationMethod.ANY)
|
||||
self.assertEqual(method, InstallationMethod.COPY)
|
||||
|
||||
def test_determine_install_method_file_url(self):
|
||||
@@ -285,23 +255,15 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
installer = AddonInstaller(self.mock_addon, [])
|
||||
temp_dir = "file://" + temp_dir.replace(os.path.sep, "/")
|
||||
method = installer._determine_install_method(
|
||||
temp_dir, InstallationMethod.COPY
|
||||
)
|
||||
method = installer._determine_install_method(temp_dir, InstallationMethod.COPY)
|
||||
self.assertEqual(method, InstallationMethod.COPY)
|
||||
git_manager = initialize_git()
|
||||
if git_manager:
|
||||
method = installer._determine_install_method(
|
||||
temp_dir, InstallationMethod.GIT
|
||||
)
|
||||
method = installer._determine_install_method(temp_dir, InstallationMethod.GIT)
|
||||
self.assertEqual(method, InstallationMethod.GIT)
|
||||
method = installer._determine_install_method(
|
||||
temp_dir, InstallationMethod.ZIP
|
||||
)
|
||||
method = installer._determine_install_method(temp_dir, InstallationMethod.ZIP)
|
||||
self.assertIsNone(method)
|
||||
method = installer._determine_install_method(
|
||||
temp_dir, InstallationMethod.ANY
|
||||
)
|
||||
method = installer._determine_install_method(temp_dir, InstallationMethod.ANY)
|
||||
self.assertEqual(method, InstallationMethod.COPY)
|
||||
|
||||
def test_determine_install_method_local_zip(self):
|
||||
@@ -310,21 +272,13 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
installer = AddonInstaller(self.mock_addon, [])
|
||||
temp_file = os.path.join(temp_dir, "dummy.zip")
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.COPY
|
||||
)
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.COPY)
|
||||
self.assertEqual(method, InstallationMethod.ZIP)
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.GIT
|
||||
)
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.GIT)
|
||||
self.assertIsNone(method)
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.ZIP
|
||||
)
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.ZIP)
|
||||
self.assertEqual(method, InstallationMethod.ZIP)
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.ANY
|
||||
)
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.ANY)
|
||||
self.assertEqual(method, InstallationMethod.ZIP)
|
||||
|
||||
def test_determine_install_method_remote_zip(self):
|
||||
@@ -351,12 +305,8 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
|
||||
for site in ["github.org", "gitlab.org", "framagit.org", "salsa.debian.org"]:
|
||||
with self.subTest(site=site):
|
||||
temp_file = (
|
||||
f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
)
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.COPY
|
||||
)
|
||||
temp_file = f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.COPY)
|
||||
self.assertIsNone(method, f"Allowed copying from {site} URL")
|
||||
|
||||
def test_determine_install_method_https_known_sites_git(self):
|
||||
@@ -367,12 +317,8 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
|
||||
for site in ["github.org", "gitlab.org", "framagit.org", "salsa.debian.org"]:
|
||||
with self.subTest(site=site):
|
||||
temp_file = (
|
||||
f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
)
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.GIT
|
||||
)
|
||||
temp_file = f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.GIT)
|
||||
self.assertEqual(
|
||||
method,
|
||||
InstallationMethod.GIT,
|
||||
@@ -387,12 +333,8 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
|
||||
for site in ["github.org", "gitlab.org", "framagit.org", "salsa.debian.org"]:
|
||||
with self.subTest(site=site):
|
||||
temp_file = (
|
||||
f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
)
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.ZIP
|
||||
)
|
||||
temp_file = f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.ZIP)
|
||||
self.assertEqual(
|
||||
method,
|
||||
InstallationMethod.ZIP,
|
||||
@@ -407,12 +349,8 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
|
||||
for site in ["github.org", "gitlab.org", "framagit.org", "salsa.debian.org"]:
|
||||
with self.subTest(site=site):
|
||||
temp_file = (
|
||||
f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
)
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.ANY
|
||||
)
|
||||
temp_file = f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.ANY)
|
||||
self.assertEqual(
|
||||
method,
|
||||
InstallationMethod.GIT,
|
||||
@@ -427,12 +365,8 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
|
||||
for site in ["github.org", "gitlab.org", "framagit.org", "salsa.debian.org"]:
|
||||
with self.subTest(site=site):
|
||||
temp_file = (
|
||||
f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
)
|
||||
method = installer._determine_install_method(
|
||||
temp_file, InstallationMethod.ANY
|
||||
)
|
||||
temp_file = f"https://{site}/dummy/dummy" # Doesn't have to actually exist!
|
||||
method = installer._determine_install_method(temp_file, InstallationMethod.ANY)
|
||||
self.assertEqual(
|
||||
method,
|
||||
InstallationMethod.ZIP,
|
||||
@@ -442,9 +376,7 @@ class TestAddonInstaller(unittest.TestCase):
|
||||
def test_fcmacro_copying(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
mock_addon = MockAddon()
|
||||
mock_addon.url = os.path.join(
|
||||
self.test_data_dir, "test_addon_with_fcmacro.zip"
|
||||
)
|
||||
mock_addon.url = os.path.join(self.test_data_dir, "test_addon_with_fcmacro.zip")
|
||||
installer = AddonInstaller(mock_addon, [])
|
||||
installer.installation_path = temp_dir
|
||||
installer.macro_installation_path = os.path.join(temp_dir, "Macros")
|
||||
@@ -475,6 +407,4 @@ class TestMacroInstaller(unittest.TestCase):
|
||||
installer.installation_path = temp_dir
|
||||
installation_succeeded = installer.run()
|
||||
self.assertTrue(installation_succeeded)
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock.macro.filename))
|
||||
)
|
||||
self.assertTrue(os.path.exists(os.path.join(temp_dir, self.mock.macro.filename)))
|
||||
|
||||
@@ -100,9 +100,7 @@ class TestMacroParser(unittest.TestCase):
|
||||
catcher = CallCatcher()
|
||||
self.test_object._process_key = catcher.catch_call
|
||||
self.test_object._process_line(read_in_line, content_lines)
|
||||
self.assertTrue(
|
||||
catcher.called, "_process_key was not called for a known key"
|
||||
)
|
||||
self.assertTrue(catcher.called, "_process_key was not called for a known key")
|
||||
|
||||
def test_process_line_unknown_lines(self):
|
||||
"""Lines starting with non-keys are not processed"""
|
||||
@@ -123,9 +121,7 @@ class TestMacroParser(unittest.TestCase):
|
||||
catcher = CallCatcher()
|
||||
self.test_object._process_key = catcher.catch_call
|
||||
self.test_object._process_line(read_in_line, content_lines)
|
||||
self.assertFalse(
|
||||
catcher.called, "_process_key was called for an unknown key"
|
||||
)
|
||||
self.assertFalse(catcher.called, "_process_key was called for an unknown key")
|
||||
|
||||
def test_process_key_standard(self):
|
||||
"""Normal expected data is processed"""
|
||||
|
||||
@@ -51,15 +51,9 @@ class TestAddonUninstaller(unittest.TestCase):
|
||||
self.signals_caught = []
|
||||
self.test_object = AddonUninstaller(self.mock_addon)
|
||||
|
||||
self.test_object.finished.connect(
|
||||
functools.partial(self.catch_signal, "finished")
|
||||
)
|
||||
self.test_object.success.connect(
|
||||
functools.partial(self.catch_signal, "success")
|
||||
)
|
||||
self.test_object.failure.connect(
|
||||
functools.partial(self.catch_signal, "failure")
|
||||
)
|
||||
self.test_object.finished.connect(functools.partial(self.catch_signal, "finished"))
|
||||
self.test_object.success.connect(functools.partial(self.catch_signal, "success"))
|
||||
self.test_object.failure.connect(functools.partial(self.catch_signal, "failure"))
|
||||
|
||||
def tearDown(self):
|
||||
"""Finalize the test."""
|
||||
@@ -149,9 +143,7 @@ class TestAddonUninstaller(unittest.TestCase):
|
||||
self.assertNotIn("failure", self.signals_caught)
|
||||
self.assertIn("success", self.signals_caught)
|
||||
self.assertIn("finished", self.signals_caught)
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(macro_directory, "FakeMacro.FCMacro"))
|
||||
)
|
||||
self.assertFalse(os.path.exists(os.path.join(macro_directory, "FakeMacro.FCMacro")))
|
||||
self.assertTrue(os.path.exists(macro_directory))
|
||||
|
||||
def test_uninstall_calls_script(self):
|
||||
@@ -218,9 +210,7 @@ class TestAddonUninstaller(unittest.TestCase):
|
||||
os.path.join(toplevel_path, "AM_INSTALLATION_DIGEST.txt"),
|
||||
)
|
||||
self.test_object.remove_extra_files(toplevel_path) # Shouldn't throw
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(macro_directory, "FakeMacro.FCMacro"))
|
||||
)
|
||||
self.assertFalse(os.path.exists(os.path.join(macro_directory, "FakeMacro.FCMacro")))
|
||||
|
||||
def test_remove_extra_files_normal_case(self):
|
||||
"""Test that a digest that is a "normal" case removes the requested files"""
|
||||
@@ -244,35 +234,21 @@ class TestAddonUninstaller(unittest.TestCase):
|
||||
)
|
||||
|
||||
# Make sure the setup worked as expected, otherwise the test is meaningless
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(macro_directory, "FakeMacro1.FCMacro"))
|
||||
)
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(macro_directory, "FakeMacro2.FCMacro"))
|
||||
)
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(macro_directory, "FakeMacro3.FCMacro"))
|
||||
)
|
||||
self.assertTrue(os.path.exists(os.path.join(macro_directory, "FakeMacro1.FCMacro")))
|
||||
self.assertTrue(os.path.exists(os.path.join(macro_directory, "FakeMacro2.FCMacro")))
|
||||
self.assertTrue(os.path.exists(os.path.join(macro_directory, "FakeMacro3.FCMacro")))
|
||||
|
||||
self.test_object.remove_extra_files(toplevel_path) # Shouldn't throw
|
||||
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(macro_directory, "FakeMacro1.FCMacro"))
|
||||
)
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(macro_directory, "FakeMacro2.FCMacro"))
|
||||
)
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(macro_directory, "FakeMacro3.FCMacro"))
|
||||
)
|
||||
self.assertFalse(os.path.exists(os.path.join(macro_directory, "FakeMacro1.FCMacro")))
|
||||
self.assertFalse(os.path.exists(os.path.join(macro_directory, "FakeMacro2.FCMacro")))
|
||||
self.assertFalse(os.path.exists(os.path.join(macro_directory, "FakeMacro3.FCMacro")))
|
||||
|
||||
def test_runs_uninstaller_script_successful(self):
|
||||
"""Tests that the uninstall.py script is called"""
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
toplevel_path = self.setup_dummy_installation(temp_dir)
|
||||
with open(
|
||||
os.path.join(toplevel_path, "uninstall.py"), "w", encoding="utf-8"
|
||||
) as f:
|
||||
with open(os.path.join(toplevel_path, "uninstall.py"), "w", encoding="utf-8") as f:
|
||||
double_escaped = temp_dir.replace("\\", "\\\\")
|
||||
f.write(
|
||||
f"""# Mock uninstaller script
|
||||
@@ -282,28 +258,20 @@ with open(os.path.join(path,"RAN_UNINSTALLER.txt"),"w",encoding="utf-8") as f:
|
||||
f.write("File created by uninstall.py from unit tests")
|
||||
"""
|
||||
)
|
||||
self.test_object.run_uninstall_script(
|
||||
toplevel_path
|
||||
) # The exception does not leak out
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(temp_dir, "RAN_UNINSTALLER.txt"))
|
||||
)
|
||||
self.test_object.run_uninstall_script(toplevel_path) # The exception does not leak out
|
||||
self.assertTrue(os.path.exists(os.path.join(temp_dir, "RAN_UNINSTALLER.txt")))
|
||||
|
||||
def test_runs_uninstaller_script_failure(self):
|
||||
"""Tests that exceptions in the uninstall.py script do not leak out"""
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
toplevel_path = self.setup_dummy_installation(temp_dir)
|
||||
with open(
|
||||
os.path.join(toplevel_path, "uninstall.py"), "w", encoding="utf-8"
|
||||
) as f:
|
||||
with open(os.path.join(toplevel_path, "uninstall.py"), "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
f"""# Mock uninstaller script
|
||||
raise RuntimeError("Fake exception for unit testing")
|
||||
"""
|
||||
)
|
||||
self.test_object.run_uninstall_script(
|
||||
toplevel_path
|
||||
) # The exception does not leak out
|
||||
self.test_object.run_uninstall_script(toplevel_path) # The exception does not leak out
|
||||
|
||||
|
||||
class TestMacroUninstaller(unittest.TestCase):
|
||||
@@ -317,15 +285,9 @@ class TestMacroUninstaller(unittest.TestCase):
|
||||
self.test_object = MacroUninstaller(self.mock_addon)
|
||||
self.signals_caught = []
|
||||
|
||||
self.test_object.finished.connect(
|
||||
functools.partial(self.catch_signal, "finished")
|
||||
)
|
||||
self.test_object.success.connect(
|
||||
functools.partial(self.catch_signal, "success")
|
||||
)
|
||||
self.test_object.failure.connect(
|
||||
functools.partial(self.catch_signal, "failure")
|
||||
)
|
||||
self.test_object.finished.connect(functools.partial(self.catch_signal, "finished"))
|
||||
self.test_object.success.connect(functools.partial(self.catch_signal, "success"))
|
||||
self.test_object.failure.connect(functools.partial(self.catch_signal, "failure"))
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
@@ -339,13 +301,9 @@ class TestMacroUninstaller(unittest.TestCase):
|
||||
self.test_object.installation_location = temp_dir
|
||||
self.mock_addon.macro.install(temp_dir)
|
||||
# Make sure the setup worked, otherwise the test is meaningless
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename))
|
||||
)
|
||||
self.assertTrue(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename)))
|
||||
self.test_object.run()
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename))
|
||||
)
|
||||
self.assertFalse(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename)))
|
||||
self.assertNotIn("failure", self.signals_caught)
|
||||
self.assertIn("success", self.signals_caught)
|
||||
self.assertIn("finished", self.signals_caught)
|
||||
@@ -356,19 +314,11 @@ class TestMacroUninstaller(unittest.TestCase):
|
||||
self.mock_addon.macro.icon = "mock_icon_test.svg"
|
||||
self.mock_addon.macro.install(temp_dir)
|
||||
# Make sure the setup worked, otherwise the test is meaningless
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename))
|
||||
)
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.icon))
|
||||
)
|
||||
self.assertTrue(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename)))
|
||||
self.assertTrue(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.icon)))
|
||||
self.test_object.run()
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename))
|
||||
)
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.icon))
|
||||
)
|
||||
self.assertFalse(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename)))
|
||||
self.assertFalse(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.icon)))
|
||||
self.assertNotIn("failure", self.signals_caught)
|
||||
self.assertIn("success", self.signals_caught)
|
||||
self.assertIn("finished", self.signals_caught)
|
||||
@@ -379,19 +329,11 @@ class TestMacroUninstaller(unittest.TestCase):
|
||||
self.mock_addon.macro.xpm = "/*Fake XPM data*/"
|
||||
self.mock_addon.macro.install(temp_dir)
|
||||
# Make sure the setup worked, otherwise the test is meaningless
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename))
|
||||
)
|
||||
self.assertTrue(
|
||||
os.path.exists(os.path.join(temp_dir, "MockMacro_icon.xpm"))
|
||||
)
|
||||
self.assertTrue(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename)))
|
||||
self.assertTrue(os.path.exists(os.path.join(temp_dir, "MockMacro_icon.xpm")))
|
||||
self.test_object.run()
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename))
|
||||
)
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(temp_dir, "MockMacro_icon.xpm"))
|
||||
)
|
||||
self.assertFalse(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename)))
|
||||
self.assertFalse(os.path.exists(os.path.join(temp_dir, "MockMacro_icon.xpm")))
|
||||
self.assertNotIn("failure", self.signals_caught)
|
||||
self.assertIn("success", self.signals_caught)
|
||||
self.assertIn("finished", self.signals_caught)
|
||||
@@ -430,13 +372,9 @@ class TestMacroUninstaller(unittest.TestCase):
|
||||
self.test_object.installation_location = temp_dir
|
||||
# Don't run the installer:
|
||||
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename))
|
||||
)
|
||||
self.assertFalse(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename)))
|
||||
self.test_object.run() # Should not raise an exception
|
||||
self.assertFalse(
|
||||
os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename))
|
||||
)
|
||||
self.assertFalse(os.path.exists(os.path.join(temp_dir, self.mock_addon.macro.filename)))
|
||||
self.assertNotIn("failure", self.signals_caught)
|
||||
self.assertIn("success", self.signals_caught)
|
||||
self.assertIn("finished", self.signals_caught)
|
||||
@@ -489,9 +427,7 @@ class TestMacroUninstaller(unittest.TestCase):
|
||||
full_path = os.path.join(temp_dir, directory)
|
||||
os.mkdir(full_path)
|
||||
full_paths.add(full_path)
|
||||
with open(
|
||||
os.path.join(full_path, "test.txt"), "w", encoding="utf-8"
|
||||
) as f:
|
||||
with open(os.path.join(full_path, "test.txt"), "w", encoding="utf-8") as f:
|
||||
f.write("Unit test dummy data\n")
|
||||
|
||||
for directory in full_paths:
|
||||
|
||||
@@ -53,9 +53,7 @@ class TestUtilities(unittest.TestCase):
|
||||
]
|
||||
for url in recognized_urls:
|
||||
repo = Addon("Test Repo", url, Addon.Status.NOT_INSTALLED, "branch")
|
||||
self.assertTrue(
|
||||
recognized_git_location(repo), f"{url} was unexpectedly not recognized"
|
||||
)
|
||||
self.assertTrue(recognized_git_location(repo), f"{url} was unexpectedly not recognized")
|
||||
|
||||
unrecognized_urls = [
|
||||
"https://google.com",
|
||||
@@ -65,9 +63,7 @@ class TestUtilities(unittest.TestCase):
|
||||
]
|
||||
for url in unrecognized_urls:
|
||||
repo = Addon("Test Repo", url, Addon.Status.NOT_INSTALLED, "branch")
|
||||
self.assertFalse(
|
||||
recognized_git_location(repo), f"{url} was unexpectedly recognized"
|
||||
)
|
||||
self.assertFalse(recognized_git_location(repo), f"{url} was unexpectedly recognized")
|
||||
|
||||
def test_get_readme_url(self):
|
||||
github_urls = [
|
||||
|
||||
@@ -27,4 +27,4 @@ static char * blarg_xpm[] = {
|
||||
".............**."
|
||||
};"""
|
||||
|
||||
print("Well, not quite *nothing*... it does print this line out.")
|
||||
print("Well, not quite *nothing*... it does print this line out.")
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -34,4 +34,4 @@ __Help__ = ""
|
||||
__Status__ = ""
|
||||
__Requires__ = ""
|
||||
__Communication__ = ""
|
||||
__Files__ = ""
|
||||
__Files__ = ""
|
||||
|
||||
@@ -25,4 +25,4 @@
|
||||
</preferencepack>
|
||||
</content>
|
||||
|
||||
</package>
|
||||
</package>
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
url = https://github.com/tomate44/CurvesWB.git
|
||||
[submodule "Defeaturing"]
|
||||
path = Defeaturing
|
||||
url = https://github.com/easyw/Defeaturing_WB.git
|
||||
url = https://github.com/easyw/Defeaturing_WB.git
|
||||
|
||||
@@ -34,4 +34,4 @@ __Help__ = ""
|
||||
__Status__ = ""
|
||||
__Requires__ = ""
|
||||
__Communication__ = ""
|
||||
__Files__ = ""
|
||||
__Files__ = ""
|
||||
|
||||
@@ -22,4 +22,4 @@
|
||||
</workbench>
|
||||
</content>
|
||||
|
||||
</package>
|
||||
</package>
|
||||
|
||||
@@ -19,4 +19,4 @@
|
||||
</macro>
|
||||
</content>
|
||||
|
||||
</package>
|
||||
</package>
|
||||
|
||||
@@ -34,4 +34,4 @@ __Help__ = "HELP"
|
||||
__Status__ = "STATUS"
|
||||
__Requires__ = "REQUIRES"
|
||||
__Communication__ = "COMMUNICATION"
|
||||
__Files__ = "FILES"
|
||||
__Files__ = "FILES"
|
||||
|
||||
@@ -22,4 +22,4 @@
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
# This file contains no metadata
|
||||
# This file contains no metadata
|
||||
|
||||
@@ -21,4 +21,4 @@
|
||||
</preferencepack>
|
||||
</content>
|
||||
|
||||
</package>
|
||||
</package>
|
||||
|
||||
@@ -30,4 +30,4 @@
|
||||
</macro>
|
||||
</content>
|
||||
|
||||
</package>
|
||||
</package>
|
||||
|
||||
@@ -24,4 +24,4 @@
|
||||
</workbench>
|
||||
</content>
|
||||
|
||||
</package>
|
||||
</package>
|
||||
|
||||
@@ -55,12 +55,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Ok,
|
||||
)
|
||||
self.installer_gui._installation_succeeded()
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_failure_dialog(self):
|
||||
# Pop the modal dialog and verify that it opens, and responds to a Cancel click
|
||||
@@ -71,12 +67,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
self.installer_gui._installation_failed(
|
||||
self.addon_to_install, "Test of installation failure"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_no_python_dialog(self):
|
||||
# Pop the modal dialog and verify that it opens, and responds to a No click
|
||||
@@ -85,12 +77,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.No,
|
||||
)
|
||||
self.installer_gui._report_no_python_exe()
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_no_pip_dialog(self):
|
||||
# Pop the modal dialog and verify that it opens, and responds to a No click
|
||||
@@ -99,12 +87,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.No,
|
||||
)
|
||||
self.installer_gui._report_no_pip("pip not actually run, this was a test")
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_dependency_failure_dialog(self):
|
||||
# Pop the modal dialog and verify that it opens, and responds to a No click
|
||||
@@ -115,12 +99,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
self.installer_gui._report_dependency_failure(
|
||||
"Unit test", "Nothing really failed, this is a test of the dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_install(self):
|
||||
# Run the installation code and make sure it puts the directory in place
|
||||
@@ -130,9 +110,7 @@ class TestInstallerGui(unittest.TestCase):
|
||||
self.installer_gui.installer.success.disconnect(
|
||||
self.installer_gui._installation_succeeded
|
||||
)
|
||||
self.installer_gui.installer.failure.disconnect(
|
||||
self.installer_gui._installation_failed
|
||||
)
|
||||
self.installer_gui.installer.failure.disconnect(self.installer_gui._installation_failed)
|
||||
while not self.installer_gui.worker_thread.isFinished():
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 100)
|
||||
self.assertTrue(
|
||||
@@ -147,12 +125,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Cancel,
|
||||
)
|
||||
self.installer_gui._handle_disallowed_python(disallowed_packages)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_handle_disallowed_python_long_list(self):
|
||||
"""A separate test for when there are MANY packages, which takes a separate code path."""
|
||||
@@ -164,12 +138,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Cancel,
|
||||
)
|
||||
self.installer_gui._handle_disallowed_python(disallowed_packages)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_report_missing_workbenches_single(self):
|
||||
"""Test only missing one workbench"""
|
||||
@@ -179,12 +149,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Cancel,
|
||||
)
|
||||
self.installer_gui._report_missing_workbenches(wbs)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_report_missing_workbenches_multiple(self):
|
||||
"""Test only missing one workbench"""
|
||||
@@ -194,12 +160,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Cancel,
|
||||
)
|
||||
self.installer_gui._report_missing_workbenches(wbs)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_resolve_dependencies_then_install(self):
|
||||
class MissingDependenciesMock:
|
||||
@@ -214,12 +176,8 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Cancel,
|
||||
)
|
||||
self.installer_gui._resolve_dependencies_then_install(missing)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_check_python_version_bad(self):
|
||||
class MissingDependenciesMock:
|
||||
@@ -232,15 +190,9 @@ class TestInstallerGui(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Cancel,
|
||||
)
|
||||
stop_installing = self.installer_gui._check_python_version(missing)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(
|
||||
stop_installing, "Failed to halt installation on bad Python version"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
self.assertTrue(stop_installing, "Failed to halt installation on bad Python version")
|
||||
|
||||
def test_check_python_version_good(self):
|
||||
class MissingDependenciesMock:
|
||||
@@ -249,9 +201,7 @@ class TestInstallerGui(unittest.TestCase):
|
||||
|
||||
missing = MissingDependenciesMock()
|
||||
stop_installing = self.installer_gui._check_python_version(missing)
|
||||
self.assertFalse(
|
||||
stop_installing, "Failed to continue installation on good Python version"
|
||||
)
|
||||
self.assertFalse(stop_installing, "Failed to continue installation on good Python version")
|
||||
|
||||
def test_clean_up_optional(self):
|
||||
class MissingDependenciesMock:
|
||||
@@ -270,9 +220,7 @@ class TestInstallerGui(unittest.TestCase):
|
||||
self.assertTrue("allowed_packages_2" in missing.python_optional)
|
||||
self.assertFalse("disallowed_package" in missing.python_optional)
|
||||
|
||||
def intercept_run_dependency_installer(
|
||||
self, addons, python_requires, python_optional
|
||||
):
|
||||
def intercept_run_dependency_installer(self, addons, python_requires, python_optional):
|
||||
self.assertEqual(python_requires, ["py_req_1", "py_req_2"])
|
||||
self.assertEqual(python_optional, ["py_opt_1", "py_opt_2"])
|
||||
self.assertEqual(addons[0].name, "addon_1")
|
||||
@@ -294,9 +242,7 @@ class TestInstallerGui(unittest.TestCase):
|
||||
def __init__(self, items):
|
||||
self.list = []
|
||||
for item in items:
|
||||
self.list.append(
|
||||
DialogMock.ListWidgetMock.ListWidgetItemMock(item)
|
||||
)
|
||||
self.list.append(DialogMock.ListWidgetMock.ListWidgetItemMock(item))
|
||||
|
||||
def count(self):
|
||||
return len(self.list)
|
||||
@@ -305,15 +251,9 @@ class TestInstallerGui(unittest.TestCase):
|
||||
return self.list[i]
|
||||
|
||||
def __init__(self):
|
||||
self.listWidgetAddons = DialogMock.ListWidgetMock(
|
||||
["addon_1", "addon_2"]
|
||||
)
|
||||
self.listWidgetPythonRequired = DialogMock.ListWidgetMock(
|
||||
["py_req_1", "py_req_2"]
|
||||
)
|
||||
self.listWidgetPythonOptional = DialogMock.ListWidgetMock(
|
||||
["py_opt_1", "py_opt_2"]
|
||||
)
|
||||
self.listWidgetAddons = DialogMock.ListWidgetMock(["addon_1", "addon_2"])
|
||||
self.listWidgetPythonRequired = DialogMock.ListWidgetMock(["py_req_1", "py_req_2"])
|
||||
self.listWidgetPythonOptional = DialogMock.ListWidgetMock(["py_opt_1", "py_opt_2"])
|
||||
|
||||
class AddonMock:
|
||||
def __init__(self, name):
|
||||
@@ -321,9 +261,7 @@ class TestInstallerGui(unittest.TestCase):
|
||||
|
||||
self.installer_gui.dependency_dialog = DialogMock()
|
||||
self.installer_gui.addons = [AddonMock("addon_1"), AddonMock("addon_2")]
|
||||
self.installer_gui._run_dependency_installer = (
|
||||
self.intercept_run_dependency_installer
|
||||
)
|
||||
self.installer_gui._run_dependency_installer = self.intercept_run_dependency_installer
|
||||
self.installer_gui._dependency_dialog_yes_clicked()
|
||||
|
||||
|
||||
@@ -481,9 +419,7 @@ class TestMacroInstallerGui(unittest.TestCase):
|
||||
self.assertEqual(name, "UnitTestCustomToolbar")
|
||||
self.assertIn("alwaysAskForToolbar", self.installer.addon_params.params)
|
||||
self.assertFalse(self.installer.addon_params.get("alwaysAskForToolbar", True))
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_ask_for_toolbar_with_dialog_selection(self):
|
||||
|
||||
@@ -530,9 +466,7 @@ class TestMacroInstallerGui(unittest.TestCase):
|
||||
def test_macro_button_exists_true(self):
|
||||
# Test 2: Macro is in the list of buttons
|
||||
ut_tb_1 = self.installer.toolbar_params.GetGroup("UnitTestCommand")
|
||||
ut_tb_1.set(
|
||||
"UnitTestCommand", "FreeCAD"
|
||||
) # This is what the real thing looks like...
|
||||
ut_tb_1.set("UnitTestCommand", "FreeCAD") # This is what the real thing looks like...
|
||||
self.installer._find_custom_command = lambda _: "UnitTestCommand"
|
||||
self.assertTrue(self.installer._macro_button_exists())
|
||||
|
||||
|
||||
@@ -62,12 +62,8 @@ class TestUninstallerGUI(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Yes,
|
||||
)
|
||||
answer = self.uninstaller_gui._confirm_uninstallation()
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
self.assertTrue(answer, "Expected a 'Yes' click to return True, but got False")
|
||||
|
||||
def test_confirmation_dialog_cancel(self):
|
||||
@@ -76,15 +72,9 @@ class TestUninstallerGUI(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Cancel,
|
||||
)
|
||||
answer = self.uninstaller_gui._confirm_uninstallation()
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertFalse(
|
||||
answer, "Expected a 'Cancel' click to return False, but got True"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
self.assertFalse(answer, "Expected a 'Cancel' click to return False, but got True")
|
||||
|
||||
def test_progress_dialog(self):
|
||||
dialog_watcher = DialogWatcher(
|
||||
@@ -95,12 +85,8 @@ class TestUninstallerGUI(unittest.TestCase):
|
||||
# That call isn't modal, so spin our own event loop:
|
||||
while self.uninstaller_gui.progress_dialog.isVisible():
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 100)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_timer_launches_progress_dialog(self):
|
||||
worker = FakeWorker()
|
||||
@@ -108,22 +94,14 @@ class TestUninstallerGUI(unittest.TestCase):
|
||||
translate("AddonsInstaller", "Removing Addon"),
|
||||
QtWidgets.QDialogButtonBox.Cancel,
|
||||
)
|
||||
QtCore.QTimer.singleShot(
|
||||
1000, worker.stop
|
||||
) # If the test fails, this kills the "worker"
|
||||
QtCore.QTimer.singleShot(1000, worker.stop) # If the test fails, this kills the "worker"
|
||||
self.uninstaller_gui._confirm_uninstallation = lambda: True
|
||||
self.uninstaller_gui._run_uninstaller = worker.work
|
||||
self.uninstaller_gui._finalize = lambda: None
|
||||
self.uninstaller_gui.dialog_timer.setInterval(
|
||||
1
|
||||
) # To speed up the test, only wait 1ms
|
||||
self.uninstaller_gui.dialog_timer.setInterval(1) # To speed up the test, only wait 1ms
|
||||
self.uninstaller_gui.run() # Blocks once it hits the fake worker
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
worker.stop()
|
||||
|
||||
def test_success_dialog(self):
|
||||
@@ -132,12 +110,8 @@ class TestUninstallerGUI(unittest.TestCase):
|
||||
QtWidgets.QDialogButtonBox.Ok,
|
||||
)
|
||||
self.uninstaller_gui._succeeded(self.addon_to_remove)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_failure_dialog(self):
|
||||
dialog_watcher = DialogWatcher(
|
||||
@@ -147,17 +121,11 @@ class TestUninstallerGUI(unittest.TestCase):
|
||||
self.uninstaller_gui._failed(
|
||||
self.addon_to_remove, "Some failure message\nAnother failure message"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.dialog_found, "Failed to find the expected dialog box"
|
||||
)
|
||||
self.assertTrue(
|
||||
dialog_watcher.button_found, "Failed to find the expected button"
|
||||
)
|
||||
self.assertTrue(dialog_watcher.dialog_found, "Failed to find the expected dialog box")
|
||||
self.assertTrue(dialog_watcher.button_found, "Failed to find the expected button")
|
||||
|
||||
def test_finalize(self):
|
||||
self.uninstaller_gui.finished.connect(
|
||||
functools.partial(self.catch_signal, "finished")
|
||||
)
|
||||
self.uninstaller_gui.finished.connect(functools.partial(self.catch_signal, "finished"))
|
||||
self.uninstaller_gui.worker_thread = MockThread()
|
||||
self.uninstaller_gui._finalize()
|
||||
self.assertIn("finished", self.signals_caught)
|
||||
|
||||
@@ -43,9 +43,7 @@ class MockUpdater(QtCore.QObject):
|
||||
self.addons = addons
|
||||
self.has_run = False
|
||||
self.emit_success = True
|
||||
self.work_function = (
|
||||
None # Set to some kind of callable to make this function take time
|
||||
)
|
||||
self.work_function = None # Set to some kind of callable to make this function take time
|
||||
|
||||
def run(self):
|
||||
self.has_run = True
|
||||
@@ -136,9 +134,7 @@ class TestUpdateAllGui(unittest.TestCase):
|
||||
self.test_object.run()
|
||||
cancel_timer = QtCore.QTimer()
|
||||
cancel_timer.timeout.connect(
|
||||
self.test_object.dialog.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.Cancel
|
||||
).click
|
||||
self.test_object.dialog.buttonBox.button(QtWidgets.QDialogButtonBox.Cancel).click
|
||||
)
|
||||
cancel_timer.start(90)
|
||||
while self.test_object.is_running():
|
||||
|
||||
@@ -45,9 +45,7 @@ class TestWorkersStartup(unittest.TestCase):
|
||||
|
||||
MODULE = "test_workers_startup" # file name without extension
|
||||
|
||||
@unittest.skipUnless(
|
||||
run_slow_tests, "This integration test is slow and uses the network"
|
||||
)
|
||||
@unittest.skipUnless(run_slow_tests, "This integration test is slow and uses the network")
|
||||
def setUp(self):
|
||||
"""Set up the test"""
|
||||
self.test_dir = os.path.join(
|
||||
@@ -56,12 +54,8 @@ class TestWorkersStartup(unittest.TestCase):
|
||||
|
||||
self.saved_mod_directory = Addon.mod_directory
|
||||
self.saved_cache_directory = Addon.cache_directory
|
||||
Addon.mod_directory = os.path.join(
|
||||
tempfile.gettempdir(), "FreeCADTesting", "Mod"
|
||||
)
|
||||
Addon.cache_directory = os.path.join(
|
||||
tempfile.gettempdir(), "FreeCADTesting", "Cache"
|
||||
)
|
||||
Addon.mod_directory = os.path.join(tempfile.gettempdir(), "FreeCADTesting", "Mod")
|
||||
Addon.cache_directory = os.path.join(tempfile.gettempdir(), "FreeCADTesting", "Cache")
|
||||
|
||||
os.makedirs(Addon.mod_directory, mode=0o777, exist_ok=True)
|
||||
os.makedirs(Addon.cache_directory, mode=0o777, exist_ok=True)
|
||||
@@ -82,9 +76,7 @@ class TestWorkersStartup(unittest.TestCase):
|
||||
self.package_cache = {}
|
||||
self.macro_cache = []
|
||||
|
||||
self.package_cache_filename = os.path.join(
|
||||
Addon.cache_directory, "packages.json"
|
||||
)
|
||||
self.package_cache_filename = os.path.join(Addon.cache_directory, "packages.json")
|
||||
self.macro_cache_filename = os.path.join(Addon.cache_directory, "macros.json")
|
||||
|
||||
# Store the user's preference for whether git is enabled or disabled
|
||||
@@ -135,9 +127,7 @@ class TestWorkersStartup(unittest.TestCase):
|
||||
|
||||
# Now try loading the same data from the cache we just created
|
||||
worker = LoadPackagesFromCacheWorker(self.package_cache_filename)
|
||||
worker.override_metadata_cache_path(
|
||||
os.path.join(Addon.cache_directory, "PackageMetadata")
|
||||
)
|
||||
worker.override_metadata_cache_path(os.path.join(Addon.cache_directory, "PackageMetadata"))
|
||||
worker.addon_repo.connect(self._addon_added)
|
||||
|
||||
worker.start()
|
||||
|
||||
@@ -69,9 +69,7 @@ class TestWorkersUtility(unittest.TestCase):
|
||||
while worker.isRunning():
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 50)
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
|
||||
self.assertIsNone(
|
||||
self.last_result, "Requesting interruption of thread failed to interrupt"
|
||||
)
|
||||
self.assertIsNone(self.last_result, "Requesting interruption of thread failed to interrupt")
|
||||
|
||||
def connection_succeeded(self):
|
||||
self.last_result = "SUCCESS"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
## Unit tests for the Addon Manager
|
||||
|
||||
Data files are located in the `data/` subdirectory.
|
||||
Data files are located in the `data/` subdirectory.
|
||||
|
||||
Reference in New Issue
Block a user