Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 24, 2023
1 parent cd8a39b commit 192a7c6
Show file tree
Hide file tree
Showing 114 changed files with 1,094 additions and 1,657 deletions.
28 changes: 7 additions & 21 deletions src/Mod/AddonManager/AddonManagerOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,17 @@ def __init__(self, _=None):
QIcon.fromTheme("remove", QIcon(":/icons/list-remove.svg"))
)

self.form.customRepositoriesTableView.horizontalHeader().setStretchLastSection(
False
)
self.form.customRepositoriesTableView.horizontalHeader().setStretchLastSection(False)
self.form.customRepositoriesTableView.horizontalHeader().setSectionResizeMode(
0, QHeaderView.Stretch
)
self.form.customRepositoriesTableView.horizontalHeader().setSectionResizeMode(
1, QHeaderView.ResizeToContents
)

self.form.addCustomRepositoryButton.clicked.connect(
self._add_custom_repo_clicked
)
self.form.removeCustomRepositoryButton.clicked.connect(
self._remove_custom_repo_clicked
)
self.form.customRepositoriesTableView.doubleClicked.connect(
self._row_double_clicked
)
self.form.addCustomRepositoryButton.clicked.connect(self._add_custom_repo_clicked)
self.form.removeCustomRepositoryButton.clicked.connect(self._remove_custom_repo_clicked)
self.form.customRepositoriesTableView.doubleClicked.connect(self._row_double_clicked)

def saveSettings(self):
"""Required function: called by the preferences dialog when Apply or Save is clicked,
Expand All @@ -99,9 +91,7 @@ def recursive_widget_saver(self, widget):
if pref_path and pref_entry:
pref_path = pref_path.data()
pref_entry = pref_entry.data()
pref_access_string = (
f"User parameter:BaseApp/Preferences/{str(pref_path,'utf-8')}"
)
pref_access_string = f"User parameter:BaseApp/Preferences/{str(pref_path,'utf-8')}"
pref = FreeCAD.ParamGet(pref_access_string)
if isinstance(widget, QCheckBox):
checked = widget.isChecked()
Expand Down Expand Up @@ -143,9 +133,7 @@ def recursive_widget_loader(self, widget):
if pref_path and pref_entry:
pref_path = pref_path.data()
pref_entry = pref_entry.data()
pref_access_string = (
f"User parameter:BaseApp/Preferences/{str(pref_path,'utf-8')}"
)
pref_access_string = f"User parameter:BaseApp/Preferences/{str(pref_path,'utf-8')}"
pref = FreeCAD.ParamGet(pref_access_string)
if isinstance(widget, QCheckBox):
widget.setChecked(pref.GetBool(str(pref_entry, "utf-8")))
Expand Down Expand Up @@ -313,9 +301,7 @@ class CustomRepositoryDialog:

def __init__(self):
self.dialog = FreeCADGui.PySideUic.loadUi(
os.path.join(
os.path.dirname(__file__), "AddonManagerOptions_AddCustomRepository.ui"
)
os.path.join(os.path.dirname(__file__), "AddonManagerOptions_AddCustomRepository.ui")
)

def exec(self):
Expand Down
16 changes: 4 additions & 12 deletions src/Mod/AddonManager/AddonManagerTest/app/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ def install(self, location: os.PathLike):
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:
Expand Down Expand Up @@ -233,12 +231,8 @@ def __init__(self):
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

Expand All @@ -252,9 +246,7 @@ def clone(self, _remote, _local_path, _args: List[str] = None):
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()

Expand Down
24 changes: 6 additions & 18 deletions src/Mod/AddonManager/AddonManagerTest/app/test_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def test_contains_functions(self):
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())
Expand All @@ -103,9 +101,7 @@ def test_contains_functions(self):
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())
Expand All @@ -117,9 +113,7 @@ def test_contains_functions(self):
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())
Expand All @@ -131,9 +125,7 @@ def test_contains_functions(self):
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())
Expand Down Expand Up @@ -263,9 +255,7 @@ def test_internal_workbench_list(self):
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))
Expand All @@ -277,9 +267,7 @@ def test_version_check(self):
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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def test_log_no_freecad(self):
"""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")
Expand All @@ -76,9 +74,7 @@ def test_log_no_freecad(self):
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")
Expand All @@ -87,9 +83,7 @@ def test_message_no_freecad(self):
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")
Expand All @@ -98,9 +92,7 @@ def test_warning_no_freecad(self):
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")
Expand Down
24 changes: 6 additions & 18 deletions src/Mod/AddonManager/AddonManagerTest/app/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def test_clone(self):
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"""
Expand All @@ -91,9 +89,7 @@ def test_checkout(self):
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"""
Expand All @@ -103,9 +99,7 @@ def test_update(self):
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"""
Expand All @@ -129,19 +123,15 @@ def test_tag_and_branch(self):
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"""
checkout_dir = self._clone_test_repo()
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)"""
Expand All @@ -158,9 +148,7 @@ def test_repair(self):
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:
Expand Down
Loading

0 comments on commit 192a7c6

Please sign in to comment.