Skip to content

Commit 2a52cc2

Browse files
authored
Merge pull request #87 from chennes/cleanupImportFrom
Clean up import and import from conflicts
2 parents df7b62c + e6a89d9 commit 2a52cc2

File tree

5 files changed

+28
-50
lines changed

5 files changed

+28
-50
lines changed

Addon.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import addonmanager_freecad_interface as fci
3535
from addonmanager_macro import Macro
3636
import addonmanager_utilities as utils
37-
from addonmanager_utilities import construct_git_url, process_date_string_to_python_datetime
3837
from addonmanager_metadata import (
3938
Metadata,
4039
MetadataReader,
@@ -189,7 +188,7 @@ def __init__(
189188
self._clean_url()
190189

191190
if utils.recognized_git_location(self):
192-
self.metadata_url = construct_git_url(self, "package.xml")
191+
self.metadata_url = utils.construct_git_url(self, "package.xml")
193192
else:
194193
self.metadata_url = None
195194
self.metadata: Optional[Metadata] = None
@@ -258,7 +257,7 @@ def update_date(self):
258257
elif self.macro and self.macro.date:
259258
# Try to parse the date:
260259
try:
261-
self._cached_update_date = process_date_string_to_python_datetime(
260+
self._cached_update_date = utils.process_date_string_to_python_datetime(
262261
self.macro.date
263262
)
264263
except ValueError as e:

AddonManagerTest/app/test_addoncatalog.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
22

3-
# pylint: disable=global-at-module-level,global-statement,import-outside-toplevel,
3+
# pylint: import-outside-toplevel,
44

55
"""Tests for the AddonCatalog and AddonCatalogEntry classes."""
66

7-
import unittest
8-
from unittest import mock
7+
from unittest import mock, main, TestCase
98
from unittest.mock import patch
109

1110
AddonCatalogEntry = None
1211
AddonCatalog = None
1312
Version = None
1413

1514

16-
class TestAddonCatalogEntry(unittest.TestCase):
15+
class TestAddonCatalogEntry(TestCase):
1716
"""Tests for the AddonCatalogEntry class."""
1817

1918
def setUp(self):
@@ -89,7 +88,7 @@ def test_version_match_with_min_and_max_bad_match_low(self):
8988
self.assertFalse(ac.is_compatible())
9089

9190

92-
class TestAddonCatalog(unittest.TestCase):
91+
class TestAddonCatalog(TestCase):
9392
"""Tests for the AddonCatalog class."""
9493

9594
def setUp(self):
@@ -226,3 +225,7 @@ def test_documentation_not_added(self):
226225
self.assertNotIn("_meta", ids)
227226
self.assertNotIn("$schema", ids)
228227
self.assertIn("AnAddon", ids)
228+
229+
230+
if __name__ == "__main__":
231+
main()

AddonManagerTest/app/test_cache.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
# * <https://www.gnu.org/licenses/>. *
2121
# * *
2222
# ***************************************************************************
23-
import datetime
24-
import unittest
25-
from datetime import date
26-
from unittest import TestCase
23+
from datetime import date, timedelta
24+
from unittest import TestCase, main
2725
from unittest.mock import MagicMock, patch
2826

2927
import addonmanager_cache as cache
@@ -45,7 +43,7 @@ def test_local_cache_needs_update(self, param_mock: MagicMock, cache_mock: Magic
4543
"CustomRepositories": "",
4644
}
4745
today = date.today().isoformat()
48-
yesterday = (date.today() - datetime.timedelta(1)).isoformat()
46+
yesterday = (date.today() - timedelta(1)).isoformat()
4947

5048
# Organize these as subtests because of all the patching that has to be done: once we are in this function,
5149
# the patch is complete, and we can just modify the return values of the fakes one by one
@@ -120,4 +118,4 @@ def test_local_cache_needs_update(self, param_mock: MagicMock, cache_mock: Magic
120118

121119

122120
if __name__ == "__main__":
123-
unittest.main()
121+
main()

AddonManagerTest/gui/test_python_deps_gui.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_show(self, patched_create_list_from_pip):
3636

3737
class TestPythonDepsStandaloneFunctions(unittest.TestCase):
3838

39-
@patch("addonmanager_python_deps_gui.utils.run_interruptable_subprocess")
39+
@patch("addonmanager_python_deps_gui.run_interruptable_subprocess")
4040
def test_call_pip(self, mock_run_subprocess: MagicMock):
4141
mock_run_subprocess.return_value = MagicMock()
4242
mock_run_subprocess.return_value.returncode = 0
@@ -45,21 +45,21 @@ def test_call_pip(self, mock_run_subprocess: MagicMock):
4545
args = mock_run_subprocess.call_args[0][0]
4646
self.assertIn("pip", args)
4747

48-
@patch("addonmanager_python_deps_gui.utils.fci.get_python_exe")
48+
@patch("addonmanager_python_deps_gui.fci.get_python_exe")
4949
def test_call_pip_no_python(self, mock_get_python_exe: MagicMock):
5050
mock_get_python_exe.return_value = None
5151
with self.assertRaises(PipFailed):
5252
call_pip(["arg1", "arg2", "arg3"])
5353

54-
@patch("addonmanager_python_deps_gui.utils.run_interruptable_subprocess")
54+
@patch("addonmanager_python_deps_gui.run_interruptable_subprocess")
5555
def test_call_pip_exception_raised(self, mock_run_subprocess: MagicMock):
5656
mock_run_subprocess.side_effect = subprocess.CalledProcessError(
5757
-1, "dummy_command", "Fake contents of stdout", "Fake contents of stderr"
5858
)
5959
with self.assertRaises(PipFailed):
6060
call_pip(["arg1", "arg2", "arg3"])
6161

62-
@patch("addonmanager_python_deps_gui.utils.run_interruptable_subprocess")
62+
@patch("addonmanager_python_deps_gui.run_interruptable_subprocess")
6363
def test_call_pip_splits_results(self, mock_run_subprocess: MagicMock):
6464
result_mock = MagicMock()
6565
result_mock.stdout = "\n".join(["Value 1", "Value 2", "Value 3"])

addonmanager_python_deps_gui.py

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,16 @@
3333
import sys
3434
from functools import partial
3535
from typing import Dict, Iterable, List, Tuple, TypedDict
36-
from addonmanager_utilities import create_pip_call
36+
from addonmanager_utilities import (
37+
create_pip_call,
38+
run_interruptable_subprocess,
39+
get_pip_target_directory,
40+
)
3741

3842
import addonmanager_freecad_interface as fci
3943

40-
try:
41-
from PySide import QtCore, QtGui, QtWidgets
42-
except ImportError:
43-
try:
44-
from PySide6 import QtCore, QtGui, QtWidgets
45-
except ImportError:
46-
from PySide2 import QtCore, QtGui, QtWidgets
47-
48-
# Make sure this can run inside and outside FreeCAD, and don't require that (when run inside FreeCAD) the user has the
49-
# python QtUiTools installed, because FreeCAD wraps it for us.
50-
try:
51-
import FreeCADGui
52-
53-
loadUi = FreeCADGui.PySideUic.loadUi
54-
except ImportError:
55-
try:
56-
from PySide6.QtUiTools import QUiLoader
57-
except ImportError:
58-
from PySide2.QtUiTools import QUiLoader
59-
60-
def loadUi(ui_file: str) -> QtWidgets.QWidget:
61-
q_ui_file = QtCore.QFile(ui_file)
62-
q_ui_file.open(QtCore.QFile.OpenModeFlag.ReadOnly)
63-
loader = QUiLoader()
64-
return loader.load(ui_file)
65-
44+
from PySideWrapper import QtCore, QtGui, QtWidgets
6645

67-
import addonmanager_utilities as utils
6846

6947
translate = fci.translate
7048

@@ -123,7 +101,7 @@ def call_pip(args: List[str]) -> List[str]:
123101
raise PipFailed() from exception
124102

125103
try:
126-
proc = utils.run_interruptable_subprocess(call_args)
104+
proc = run_interruptable_subprocess(call_args)
127105
except subprocess.CalledProcessError as exception:
128106
raise PipFailed("pip timed out") from exception
129107

@@ -215,12 +193,12 @@ class DependentAddon(TypedDict):
215193
optional: bool
216194

217195
def __init__(self, addons):
218-
self.dlg = loadUi(
196+
self.dlg = fci.loadUi(
219197
os.path.join(os.path.dirname(__file__), "PythonDependencyUpdateDialog.ui")
220198
)
221199

222200
self.addons = addons
223-
self.vendor_path = utils.get_pip_target_directory()
201+
self.vendor_path = get_pip_target_directory()
224202
self.worker_thread = None
225203
self.worker_object = None
226204
self.package_list = []
@@ -405,7 +383,7 @@ def migrate_old_am_installations(cls) -> bool:
405383

406384
old_directory = os.path.join(fci.DataPaths().data_dir, "AdditionalPythonPackages")
407385

408-
new_directory = utils.get_pip_target_directory()
386+
new_directory = get_pip_target_directory()
409387
new_directory_name = new_directory.rsplit(os.path.sep, 1)[1]
410388

411389
if not os.path.exists(old_directory) or os.path.exists(

0 commit comments

Comments
 (0)