Skip to content

Commit

Permalink
Replace imp with importlib for python3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasjaster committed Jun 10, 2024
1 parent 131cec6 commit 3d52549
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/mbed-greentea/mbed_greentea/mbed_greentea_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import sys
import random
import optparse
import imp
import importlib
import io
from time import time
try:
Expand Down Expand Up @@ -187,7 +187,7 @@ def main():

# Show --fm option only if "fm_agent" module installed
try:
imp.find_module('fm_agent')
importlib.util.find_spec('fm_agent')
except ImportError:
fm_help=optparse.SUPPRESS_HELP
else:
Expand Down
6 changes: 4 additions & 2 deletions packages/mbed-greentea/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
mbed-os-tools>=0.0.9
mbed-host-tests>=1.5.0,<2
mbed-os-tools>=0.0.9; python_version <= '3.7'
mbed-os-tools; python_version > '3.7'
mbed-host-tests>=1.5.0,<2; python_version <= '3.7'
mbed-host-tests; python_version > '3.7'
3 changes: 2 additions & 1 deletion packages/mbed-greentea/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mock>=2
mock>=2; python_version <= '3.7'
mock; python_version > '3.7'
coverage
coveralls
3 changes: 2 additions & 1 deletion packages/mbed-host-tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mbed-os-tools>=0.0.9
mbed-os-tools>=0.0.9; python_version <= '3.7'
mbed-os-tools; python_version > '3.7'
3 changes: 2 additions & 1 deletion packages/mbed-host-tests/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mock>=2
mock>=2; python_version <= '3.7'
mock; python_version > '3.7'
coverage
coveralls
6 changes: 4 additions & 2 deletions packages/mbed-ls/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PrettyTable<=1.0.1; python_version < '3.6'
prettytable>=2.0,<3.0; python_version >= '3.6'
mbed-os-tools>=0.0.9
prettytable>=2.0,<3.0; python_version == '3.7'
prettytable; python_version > '3.7'
mbed-os-tools>=0.0.9; python_version <= '3.7'
mbed-os-tools; python_version > '3.7'
6 changes: 4 additions & 2 deletions packages/mbed-ls/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mock>=2
pytest>=3
mock>=2; python_version <= '3.7'
mock; python_version > '3.7'
pytest>=3; python_version <= '3.7'
pytest; python_version > '3.7'
coverage
coveralls
8 changes: 6 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requests; python_version > '3.7'
intelhex>=2.0,<3.0; python_version <= '3.7'
intelhex; python_version > '3.7'
future
PrettyTable<=1.0.1; python_version < '3.6'
PrettyTable<=1.0.1; python_version <= '3.6'
prettytable>=2.0,<3.0; python_version == '3.7'
prettytable; python_version > '3.7'
fasteners
Expand All @@ -19,5 +19,9 @@ six; python_version > '3.7'
colorama>=0.3,<0.5; python_version <= '3.7'
colorama; python_version > '3.7'
# When using beautiful soup, the XML parser needs to be installed independently. It is only needed on macOs though.
beautifulsoup4
beautifulsoup4<4.13.0; python_version <= '3.6' #__future__ added
beautifulsoup4; python_version >= '3.7'
soupsieve<2.4; python_version <= '3.7' #__future__ added
soupsieve; python_version > '3.7'
lxml; sys_platform == 'darwin'
setuptools; python_version >= '3.12'
4 changes: 2 additions & 2 deletions src/mbed_os_tools/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

import imp
import importlib
import sys
from optparse import OptionParser
from optparse import SUPPRESS_HELP
Expand Down Expand Up @@ -245,7 +245,7 @@ def init_host_test_cli_params():

# Show --fm option only if "fm_agent" module installed
try:
imp.find_module("fm_agent")
importlib.util.find_spec("fm_agent")
except ImportError:
fm_help = SUPPRESS_HELP
else:
Expand Down
6 changes: 3 additions & 3 deletions test/test/conn_primitive_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def setUp(self):
def test_constructor(self):
self.importer.assert_called_once_with("RemoteModuleMock")

self.remote.client.get_resources.called_once()
self.remote.client.get_resources.assert_called_once()
self.assertEqual(self.remote.remote_module, RemoteModuleMock)
self.assertIsInstance(self.remote.client, RemoteModuleMock)
self.assertIsInstance(self.remote.selected_resource, RemoteResourceMock)
Expand All @@ -91,10 +91,10 @@ def test_constructor(self):
'tags': {"a": True, "b": True}})

# flash is called
self.remote.selected_resource.open_connection.called_once_with("test.bin")
## self.remote.selected_resource.open_connection.called_once_with("test.bin")

# open_connection is called
self.remote.selected_resource.open_connection.called_once()
self.remote.selected_resource.open_connection.assert_called_once()
connect = self.remote.selected_resource.open_connection.call_args[1]
self.assertEqual(connect["parameters"].baudrate, 9600)

Expand Down
18 changes: 12 additions & 6 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
coverage>=4,<5
coveralls>=1,<2
mock>=2,<4
pytest>=3,<5
wheel>=0.34
setuptools-scm>=4.1
coverage>=4,<5; python_version <= '3.7'
coverage; python_version > '3.7'
coveralls>=1,<2; python_version <= '3.7'
coveralls; python_version > '3.7'
mock>=2,<4; python_version <= '3.7'
mock; python_version > '3.7'
pytest>=3,<5; python_version <= '3.7'
pytest; python_version > '3.7'
wheel>=0.34; python_version <= '3.7'
wheel; python_version > '3.7'
setuptools-scm>=4.1; python_version <= '3.7'
setuptools-scm; python_version > '3.7'

0 comments on commit 3d52549

Please sign in to comment.