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 = [
|
||||
|
||||
Reference in New Issue
Block a user