diff --git a/.gitignore b/.gitignore index 3ae30e4248803959b59b231d8f6fa8a4c0e73025..eb86c7600d2b5064ec81b6c459d96e00698dcdb3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,6 @@ .*.sw* .*.pyc* .*.log* -/cover/ -/.coverage autosubmit/miniTest.py autosubmit/simple_test.py .vscode/ @@ -15,3 +13,9 @@ docs/build/ dist/ build/ .cache + +# Coverage files +coverage/ +/.coverage +test/coverage.xml + diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cae12089190b8e415364b33f10a69c4ee792638f..c06571926c020bf8ade109226354e90b57e6ae3e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,15 +25,16 @@ test_python3: - git submodule update --init --recursive - conda env update -f environment.yml -n autosubmit3 python=3.7.3 - source activate autosubmit3 - - python3 -m 'nose' --exclude=regression --verbosity=3 test/unit - -#--with-coverage --cover-package=autosubmit --cover-inclusive --cover-xml --cover-xml-file=test/coverage.xml -# report_codacy: -# stage: report -# script: -# - source activate autosubmit2 -# - pip install codacy-coverage --upgrade -# - python-codacy-coverage -r test/coverage.xml + - python3 -m 'nose' --exclude=regression --verbosity=3 test/unit --with-coverage --cover-package=autosubmit --cover-inclusive --cover-xml --cover-xml-file=test/coverage.xml + coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/' + # These artifacts are saved with every build in GitLab and can be reviewed later. If + # we have a folder with HTML files, as in this example, users can navigate with their + # browser. + artifacts: + reports: + coverage_report: + coverage_format: cobertura + path: test/coverage.xml clean: stage: clean diff --git a/test/unit/test_db_manager.py b/test/unit/test_db_manager.py index afcad6061e7a18e5af7c71ed709d813c8a5798f6..a46133c9f76b78f6184dd3c899d341d1b04bc8a7 100644 --- a/test/unit/test_db_manager.py +++ b/test/unit/test_db_manager.py @@ -2,7 +2,7 @@ from unittest import TestCase import os import sys -from mock import Mock +from mock import MagicMock from mock import patch from autosubmit.database.db_manager import DbManager @@ -50,11 +50,13 @@ class TestDbManager(TestCase): self.assertEqual(expected_command, command) def test_when_database_already_exists_then_is_not_initialized_again(self): - sys.modules['os'].path.exists = Mock(return_value=True) - connection_mock = Mock() - cursor_mock = Mock() - cursor_mock.side_effect = Exception('This method shoudn\'t be called') - connection_mock.cursor = Mock(return_value=cursor_mock) - sys.modules['sqlite3'].connect = Mock(return_value=connection_mock) + sys.modules['os'].path.exists = MagicMock(return_value=True) + connection_mock = MagicMock() + cursor_mock = MagicMock() + cursor_mock.side_effect = Exception('This method should not be called') + connection_mock.cursor = MagicMock(return_value=cursor_mock) + original_connect = sys.modules['sqlite3'].connect + sys.modules['sqlite3'].connect = MagicMock(return_value=connection_mock) DbManager('dummy-path', 'dummy-name', 999) connection_mock.cursor.assert_not_called() + sys.modules['sqlite3'].connect = original_connect