From 1ef55ecfc56771a6d727f55feb1a1486bd8d8092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=94=9C=E2=95=95rn=20B=E2=94=9C=E2=95=95ni=20Hofstad?= Date: Mon, 22 Feb 2021 14:04:46 +0100 Subject: [PATCH 01/12] Use a safer, but more verbose form of file opening (Tests no longer complain) --- nordicsemi/utility/target_registry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nordicsemi/utility/target_registry.py b/nordicsemi/utility/target_registry.py index 44cb7b49..376acacb 100644 --- a/nordicsemi/utility/target_registry.py +++ b/nordicsemi/utility/target_registry.py @@ -102,7 +102,8 @@ def __init__(self, filename): def get_targets(self): if not self.targets: - self.targets = json.load(open(self.filename, "r"))["targets"] + with open(self.filename, "r") as f: + self.targets = json.load(f)["targets"] return self.targets From fb7154db3684c8d65f2478997b22d6e6d62ccf94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=94=9C=E2=95=95rn=20B=E2=94=9C=E2=95=95ni=20Hofstad?= Date: Mon, 22 Feb 2021 14:10:09 +0100 Subject: [PATCH 02/12] Add a comment and some stuff to the gitignore --- .gitignore | 4 ++++ tests/test_cli.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index 69ca7d61..f3f1ad86 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,7 @@ nrfutil.egg-info/ /tests/test.zip .eggs/ unittests.xml + + +# Ignore vscode settings and debug-options +.vscode/ \ No newline at end of file diff --git a/tests/test_cli.py b/tests/test_cli.py index 4cf143d2..ad8f5bf0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,3 +1,10 @@ +""" +The tests seems to work with `python -m unittest`, but not by being called directly from the CLI +The setUp is called twice, and crashes when being asked to do a `cd ./tests` for a second time +Look into a cleanup function + +The behavior is inconsistent between 3.9 and 3.7 (3.7 fails) +""" import os import unittest from click.testing import CliRunner From fb1643864e1c4568e9a59608cca44bf0846966fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Wed, 10 Mar 2021 13:12:58 +0100 Subject: [PATCH 03/12] Go back to the original directory acter a completed test --- tests/test_cli.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index ad8f5bf0..11241f01 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,12 +14,19 @@ class TestManifest(unittest.TestCase): runner = CliRunner() cli = __main__.cli + original_path = os.path.abspath(os.path.curdir) def setUp(self): script_abspath = os.path.abspath(__file__) script_dirname = os.path.dirname(script_abspath) + self.original_path = os.path.abspath(os.path.curdir) # Make it possible to go back os.chdir(script_dirname) + def tearDown(self) -> None: + """ + Go back to the old dir + """ + os.chdir(self.original_path) def test_pkg_gen(self): result = self.runner.invoke(self.cli, ['pkg', 'generate', From 7e4005fb3f2c317f241ee74afc6571d14cc44fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Mon, 15 Mar 2021 10:34:28 +0100 Subject: [PATCH 04/12] Update the setup file to 3.9 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 384f2770..6a8dc7d2 100644 --- a/setup.py +++ b/setup.py @@ -148,7 +148,7 @@ def run_tests(self): '../libusb/x86/libusb-1.0.dll', '../libusb/x64/libusb-1.0.dll', '../libusb/x64/libusb-1.0.dylib', '../libusb/LICENSE'] }, - python_requires='>=3.6, <3.9', + python_requires='>=3.6, <3.10', install_requires=reqs, zipfile=None, tests_require=[ From 5230af7d1e84bcc5ac47e94248aeec6c40495bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Fri, 13 Aug 2021 13:51:55 +0200 Subject: [PATCH 05/12] change requirements file for a new update instead --- requirements-frozen.txt | 24 +++++++++++------------- requirements.txt | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/requirements-frozen.txt b/requirements-frozen.txt index 8c989e74..e70a9448 100644 --- a/requirements-frozen.txt +++ b/requirements-frozen.txt @@ -1,15 +1,13 @@ -antlib==1.1b0.post0 ; sys_platform == 'win32' -Click==7.0 +PyYAML==5.4.1 +antlib==1.1b1 crcmod==1.7 -ecdsa==0.13.3 -intelhex==2.2.1 -ipaddress==1.0.22 -libusb1==1.7.1 -pc-ble-driver-py==0.14.2 +ecdsa==0.17.0 +intelhex==2.3.0 +libusb1==1.9.3 +pc-ble-driver-py==0.16.1 piccata==2.0.1 -protobuf==3.10.0 -pyserial==3.4 -pyspinel==1.0.0a3 -PyYAML==5.1.2 -tqdm==4.36.1 -wrapt==1.11.2 +protobuf==3.17.3 +pyserial==3.5 +pyspinel==1.0.3 +tqdm==4.61.2 +wrapt==1.12.1 diff --git a/requirements.txt b/requirements.txt index 600c83ee..c60ab9c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ crcmod ecdsa intelhex libusb1 -pc_ble_driver_py >= 0.14.2 +pc_ble_driver_py >= 0.16.1 piccata protobuf pyserial From 7459228bca4659755f14a16d9ec970a1dee8a010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Fri, 13 Aug 2021 14:42:41 +0200 Subject: [PATCH 06/12] add click and give proper versions --- requirements-frozen.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements-frozen.txt b/requirements-frozen.txt index e70a9448..294f6382 100644 --- a/requirements-frozen.txt +++ b/requirements-frozen.txt @@ -1,5 +1,5 @@ -PyYAML==5.4.1 antlib==1.1b1 +click==8.0.1 crcmod==1.7 ecdsa==0.17.0 intelhex==2.3.0 @@ -9,5 +9,5 @@ piccata==2.0.1 protobuf==3.17.3 pyserial==3.5 pyspinel==1.0.3 -tqdm==4.61.2 -wrapt==1.12.1 +PyYAML==5.4.1 +tqdm==4.62.0 From a03e002b898a5b53e54789886f09c9fee6aafdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Mon, 16 Aug 2021 12:52:52 +0200 Subject: [PATCH 07/12] Update python version --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 384f2770..1a8b09b5 100644 --- a/setup.py +++ b/setup.py @@ -148,7 +148,7 @@ def run_tests(self): '../libusb/x86/libusb-1.0.dll', '../libusb/x64/libusb-1.0.dll', '../libusb/x64/libusb-1.0.dylib', '../libusb/LICENSE'] }, - python_requires='>=3.6, <3.9', + python_requires='>=3.6, <3.10', install_requires=reqs, zipfile=None, tests_require=[ @@ -174,6 +174,7 @@ def run_tests(self): 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', ], keywords='nordic nrf51 nrf52 ble bluetooth dfu ota softdevice serialization nrfutil pc-nrfutil', cmdclass={ From d6c1af5cdd1c3702a4b57ab75a125c6ca02d02b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Thu, 19 Aug 2021 15:06:22 +0200 Subject: [PATCH 08/12] add nome marginally better error messages --- tests/bdd/steps/dfu_steps.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/bdd/steps/dfu_steps.py b/tests/bdd/steps/dfu_steps.py index 1a905390..9c37837c 100644 --- a/tests/bdd/steps/dfu_steps.py +++ b/tests/bdd/steps/dfu_steps.py @@ -55,7 +55,7 @@ all_boards = { 'PCA10056': DeviceLister().get_device(get_all=True, vendor_id='1366'), 'PCA10059': DeviceLister().get_device(get_all=True, vendor_id='1915') -} +} boards = {} @@ -239,7 +239,7 @@ def step_impl(context, image, image_type, board): snr = str(int(os.environ[board])) # Remove zeros to the left. else: snr = boards[board].serial_number.lower().lstrip('0') - + if image_type == "usb-serial": port = program_image_usb_serial(context, nrfjprog, full_image_path, snr) context.args.extend(['-p', port]) @@ -263,7 +263,7 @@ def step_impl(context, nrfutil): result = context.runner.invoke(nrfutil, context.args) logger.debug("exit_code: %s, output: \'%s\'", result.exit_code, result.output) - assert result.exit_code == 0 + assert result.exit_code == 0, "exit_code: {}, output: \'{}\'".format( result.exit_code, result.output) time.sleep(ENUMERATE_WAIT_TIME) # Waiting some time to ensure enumeration before next test. @@ -275,7 +275,7 @@ def step_impl(context): result = context.runner.invoke(cli, context.args) logger.debug("exit_code: %s, output: \'%s\'", result.exit_code, result.output) - assert result.exit_code == 0 + assert result.exit_code == 0, "exit_code: {}, output: \'{}\'".format( result.exit_code, result.output) time.sleep(ENUMERATE_WAIT_TIME) # Waiting for device to enumerate devices_after_programming = lister.get_device(get_all=True, vendor_id="1915", product_id="C00A") @@ -297,5 +297,5 @@ def step_impl(context): context.args[-1] = port result = context.runner.invoke(cli, context.args) logger.debug("exit_code: %s, output: \'%s\'", result.exit_code, result.output) - assert result.exit_code == 0 - time.sleep(ENUMERATE_WAIT_TIME) # Waiting some time to ensure enumeration before next test. \ No newline at end of file + assert result.exit_code == 0, "exit_code: {}, output: \'{}\'".format( result.exit_code, result.output) + time.sleep(ENUMERATE_WAIT_TIME) # Waiting some time to ensure enumeration before next test. From 578848a11404bdff59de8e078300a1810bb23181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Thu, 19 Aug 2021 15:29:59 +0200 Subject: [PATCH 09/12] update python versions used --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 384f2770..ffba217f 100644 --- a/setup.py +++ b/setup.py @@ -148,7 +148,7 @@ def run_tests(self): '../libusb/x86/libusb-1.0.dll', '../libusb/x64/libusb-1.0.dll', '../libusb/x64/libusb-1.0.dylib', '../libusb/LICENSE'] }, - python_requires='>=3.6, <3.9', + python_requires='>=3.7, <3.10', install_requires=reqs, zipfile=None, tests_require=[ @@ -171,9 +171,9 @@ def run_tests(self): 'License :: Other/Proprietary License', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', ], keywords='nordic nrf51 nrf52 ble bluetooth dfu ota softdevice serialization nrfutil pc-nrfutil', cmdclass={ From 7a87f42eb24a6738a9497d8c5531e87515f8a233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Thu, 19 Aug 2021 15:47:04 +0200 Subject: [PATCH 10/12] Add test improvements from other similair branch --- nordicsemi/utility/target_registry.py | 4 ++-- tests/test_cli.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/nordicsemi/utility/target_registry.py b/nordicsemi/utility/target_registry.py index 44cb7b49..29d0ca9d 100644 --- a/nordicsemi/utility/target_registry.py +++ b/nordicsemi/utility/target_registry.py @@ -102,8 +102,8 @@ def __init__(self, filename): def get_targets(self): if not self.targets: - self.targets = json.load(open(self.filename, "r"))["targets"] - + with open(self.filename, "r") as f: + self.targets = json.load(f)["targets"] return self.targets def get_target(self, target_id): diff --git a/tests/test_cli.py b/tests/test_cli.py index 4cf143d2..cdf6fd49 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,3 +1,10 @@ +""" +The tests seems to work with `python -m unittest`, but not by being called directly from the CLI +The setUp is called twice, and crashes when being asked to do a `cd ./tests` for a second time +Look into a cleanup function + +The behavior is inconsistent between 3.9 and 3.7 (3.7 fails) +""" import os import unittest from click.testing import CliRunner @@ -11,8 +18,15 @@ class TestManifest(unittest.TestCase): def setUp(self): script_abspath = os.path.abspath(__file__) script_dirname = os.path.dirname(script_abspath) + self.original_path = os.path.abspath(os.path.curdir) # Make it possible to go back os.chdir(script_dirname) + def tearDown(self) -> None: + """ + Go back to the old dir + """ + os.chdir(self.original_path) + def test_pkg_gen(self): result = self.runner.invoke(self.cli, ['pkg', 'generate', From 59722b1d0adb0a91e3471e80decd6bc8e89c3ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Thu, 19 Aug 2021 15:49:18 +0200 Subject: [PATCH 11/12] formating --- nordicsemi/utility/target_registry.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nordicsemi/utility/target_registry.py b/nordicsemi/utility/target_registry.py index 376acacb..5cf7784b 100644 --- a/nordicsemi/utility/target_registry.py +++ b/nordicsemi/utility/target_registry.py @@ -71,7 +71,9 @@ def get_targets(self): self.targets = [] for key, value in os.environ.items(): - match = re.match(r"NORDICSEMI_TARGET_(?P\d+)_(?P[a-zA-Z_]+)", key) + match = re.match( + r"NORDICSEMI_TARGET_(?P\d+)_(?P[a-zA-Z_]+)", key + ) if match: key_value = match.groupdict() @@ -102,7 +104,7 @@ def __init__(self, filename): def get_targets(self): if not self.targets: - with open(self.filename, "r") as f: + with open(self.filename, "r") as f: self.targets = json.load(f)["targets"] return self.targets From d9bb2df5165ee1e40144e2c98941fe3d7760980f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20B=C3=B8ni=20Hofstad?= Date: Fri, 20 Aug 2021 09:32:11 +0200 Subject: [PATCH 12/12] update the current version number --- nordicsemi/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nordicsemi/version.py b/nordicsemi/version.py index f35b9b8b..5594cebe 100644 --- a/nordicsemi/version.py +++ b/nordicsemi/version.py @@ -37,4 +37,4 @@ """ Version definition for nrfutil. """ -NRFUTIL_VERSION = "6.1.0" +NRFUTIL_VERSION = "6.1.1"