From ddd29431e6e5872525ebf0cf01b0864385a89005 Mon Sep 17 00:00:00 2001 From: Sebastian Maj Date: Mon, 15 Nov 2021 17:34:57 -0500 Subject: [PATCH] fix: removed push from actions to allow builds to succeed * refactor: Added unit tests for exceptions - Added more unit tests for exceptions thrown by run_gateway_mfr_result - Added ResourceBusyError exception to run_gateway_mfr_result * fix: Remove push action from git CI workflow - Removed the push action causing the error from protected branch - Bumped version from 0.11.7 -> 0.11.8 * fix: linting lines too long * Removed the commented lines --- .bumpversion.cfg | 2 +- .github/workflows/publish-to-pypi-test.yml | 7 ----- hm_pyhelper/miner_param.py | 7 ++++- hm_pyhelper/tests/test_miner_param.py | 31 +++++++++++++++++++--- setup.py | 2 +- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index ca76d6c..6493ceb 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.11.7 +current_version = 0.11.8 commit = True tag = True diff --git a/.github/workflows/publish-to-pypi-test.yml b/.github/workflows/publish-to-pypi-test.yml index 76f3a9a..50e40f0 100644 --- a/.github/workflows/publish-to-pypi-test.yml +++ b/.github/workflows/publish-to-pypi-test.yml @@ -88,13 +88,6 @@ jobs: bump2version patch setup.py if: github.ref == 'refs/heads/master' - - name: Push Commit from Bump2Version - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} - if: github.ref == 'refs/heads/master' - - name: Build a binary wheel and a source tarball run: | python -m build --sdist --wheel --outdir dist/ . diff --git a/hm_pyhelper/miner_param.py b/hm_pyhelper/miner_param.py index 5bda136..b11ed53 100644 --- a/hm_pyhelper/miner_param.py +++ b/hm_pyhelper/miner_param.py @@ -2,7 +2,7 @@ import subprocess import json from retry import retry -from hm_pyhelper.lock_singleton import lock_ecc +from hm_pyhelper.lock_singleton import ResourceBusyError, lock_ecc from hm_pyhelper.logger import get_logger from hm_pyhelper.exceptions import MalformedRegionException, \ SPIUnavailableException, ECCMalfunctionException, \ @@ -50,6 +50,11 @@ def run_gateway_mfr(args): LOGGER.exception(err_str) raise GatewayMFRFileNotFoundException(err_str) \ .with_traceback(e.__traceback__) + except ResourceBusyError as e: + err_str = "resource busy error: %s" + LOGGER.exception(err_str % str(e)) + raise ResourceBusyError(e)\ + .with_traceback(e.__traceback__) except Exception as e: err_str = "Exception occured on running gateway_mfr %s" \ % str(e) diff --git a/hm_pyhelper/tests/test_miner_param.py b/hm_pyhelper/tests/test_miner_param.py index 5847786..901b413 100644 --- a/hm_pyhelper/tests/test_miner_param.py +++ b/hm_pyhelper/tests/test_miner_param.py @@ -1,6 +1,10 @@ -from hm_pyhelper.exceptions import MinerFailedToFetchMacAddress -from hm_pyhelper.miner_param import retry_get_region, await_spi_available, \ - provision_key, did_gateway_mfr_test_result_include_miner_key_pass, \ +from hm_pyhelper.exceptions import ECCMalfunctionException, \ + MinerFailedToFetchMacAddress +from hm_pyhelper.lock_singleton import ResourceBusyError +from hm_pyhelper.miner_param import get_gateway_mfr_test_result, \ + retry_get_region, await_spi_available, \ + provision_key, \ + did_gateway_mfr_test_result_include_miner_key_pass, \ get_mac_address import unittest from unittest.mock import mock_open, patch @@ -177,3 +181,24 @@ def test_is_spi_available(self, _): def test_error_mac_address(self): with pytest.raises(MinerFailedToFetchMacAddress): get_mac_address("test/path") + + @patch( + 'hm_pyhelper.miner_param.run_gateway_mfr', + side_effect=FileNotFoundError("File Not Found Error")) + def test_filenotfound_exception(self, mock): + with pytest.raises(FileNotFoundError): + get_gateway_mfr_test_result() + + @patch( + 'hm_pyhelper.miner_param.run_gateway_mfr', + side_effect=ECCMalfunctionException("File Not Found Error")) + def test_eccmalfunction_exception(self, mock): + with pytest.raises(ECCMalfunctionException): + get_gateway_mfr_test_result() + + @patch( + 'hm_pyhelper.miner_param.run_gateway_mfr', + side_effect=ResourceBusyError("Resource Busy Error")) + def test_resourcebusy_exception(self, mock): + with pytest.raises(ResourceBusyError): + get_gateway_mfr_test_result() diff --git a/setup.py b/setup.py index 70d67a4..cd7f3ca 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='hm_pyhelper', - version='0.11.7', + version='0.11.8', author="Nebra Ltd", author_email="support@nebra.com", description="Helium Python Helper",