From 4a84264fa82ed734e4f2c2856f52c5ba4bc46b0e Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Thu, 15 Feb 2024 10:31:22 +0100 Subject: [PATCH] Improve tests --- .github/workflows/main.yaml | 5 ++--- monitoring/probeim.py | 3 ++- test/functional/test_im.py | 3 ++- test/integration/QuickTestIM.py | 3 ++- test/integration/TestIM.py | 3 ++- test/integration/TestREST.py | 3 ++- test/integration/TestREST_JSON.py | 3 ++- test/unit/AppDBIS.py | 3 ++- test/unit/SSH.py | 3 ++- test/unit/Tosca.py | 3 ++- test/unit/connectors/CloudConn.py | 3 ++- test/unit/openid.py | 3 ++- test/unit/test_im_logic.py | 3 ++- 13 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e9dc16cfa..ca494ad1c 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -24,9 +24,8 @@ jobs: - name: Check code style run: pycodestyle --max-line-length=120 --ignore=E402,W504,W605,E722 . --exclude=doc - - name: Test with nose - #run: nosetests test/unit/connectors/*.py test/unit/*.py test/functional/*.py -v --stop --with-xunit --with-coverage --cover-erase --cover-xml --cover-package=IM,contextualization - run: python -m coverage run --source=. -m unittest discover -s test/unit -p '*.py' + - name: Unit tests + run: python -m coverage run --source=. -m unittest discover -v -s test/unit -p '*.py' - name: Generate XML coverage report run: python -m coverage xml diff --git a/monitoring/probeim.py b/monitoring/probeim.py index 8bee3c714..738b8164e 100644 --- a/monitoring/probeim.py +++ b/monitoring/probeim.py @@ -40,7 +40,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TimeOutExcetion(Exception): diff --git a/test/functional/test_im.py b/test/functional/test_im.py index 5cee2e3a8..7cc3d7817 100755 --- a/test/functional/test_im.py +++ b/test/functional/test_im.py @@ -44,7 +44,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestIM(unittest.TestCase): diff --git a/test/integration/QuickTestIM.py b/test/integration/QuickTestIM.py index 483a8b336..4ffd13907 100755 --- a/test/integration/QuickTestIM.py +++ b/test/integration/QuickTestIM.py @@ -44,7 +44,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class QuickTestIM(unittest.TestCase): diff --git a/test/integration/TestIM.py b/test/integration/TestIM.py index ca0b2d2cc..d82cbf048 100755 --- a/test/integration/TestIM.py +++ b/test/integration/TestIM.py @@ -47,7 +47,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestIM(unittest.TestCase): diff --git a/test/integration/TestREST.py b/test/integration/TestREST.py index de6f31816..96e1876fb 100755 --- a/test/integration/TestREST.py +++ b/test/integration/TestREST.py @@ -44,7 +44,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestIM(unittest.TestCase): diff --git a/test/integration/TestREST_JSON.py b/test/integration/TestREST_JSON.py index 42dbb784e..f8a056a55 100755 --- a/test/integration/TestREST_JSON.py +++ b/test/integration/TestREST_JSON.py @@ -43,7 +43,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestIM(unittest.TestCase): diff --git a/test/unit/AppDBIS.py b/test/unit/AppDBIS.py index 60d23d594..12c53995b 100644 --- a/test/unit/AppDBIS.py +++ b/test/unit/AppDBIS.py @@ -13,7 +13,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestAppDBIS(unittest.TestCase): diff --git a/test/unit/SSH.py b/test/unit/SSH.py index be742613a..bd4f975a7 100644 --- a/test/unit/SSH.py +++ b/test/unit/SSH.py @@ -26,7 +26,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestSSH(unittest.TestCase): diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index 8c982081b..7a8df35b4 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -37,7 +37,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestTosca(unittest.TestCase): diff --git a/test/unit/connectors/CloudConn.py b/test/unit/connectors/CloudConn.py index 80b0f71ff..b4683f3a6 100755 --- a/test/unit/connectors/CloudConn.py +++ b/test/unit/connectors/CloudConn.py @@ -58,4 +58,5 @@ def tearDown(self): def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() diff --git a/test/unit/openid.py b/test/unit/openid.py index 7822a7a32..65513ce75 100755 --- a/test/unit/openid.py +++ b/test/unit/openid.py @@ -27,7 +27,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestOpenIDClient(unittest.TestCase): diff --git a/test/unit/test_im_logic.py b/test/unit/test_im_logic.py index a984c568e..5f21929b8 100644 --- a/test/unit/test_im_logic.py +++ b/test/unit/test_im_logic.py @@ -50,7 +50,8 @@ def read_file_as_string(file_name): tests_path = os.path.dirname(os.path.abspath(__file__)) abs_file_path = os.path.join(tests_path, file_name) - return open(abs_file_path, 'r').read() + with open(abs_file_path, 'r') as f: + return f.read() class TestIM(unittest.TestCase):