diff --git a/MAGSBS/config.py b/MAGSBS/config.py index 50909d6..ef370f3 100644 --- a/MAGSBS/config.py +++ b/MAGSBS/config.py @@ -224,7 +224,7 @@ def __check_for_version(self, path, value): self.__changed = True self.write() # overwrite version number in configuration which is too old else: - raise ConfigurationError(("matuc is too old, the configuration " + raise ConfigurationError(_("Matuc is too old, the configuration " "requires version {}, but version {} is running.").format(version, VERSION), path, get_lnum_of_tag(path, 'MAGSBS:version')) diff --git a/runtests b/runtests index 521d5b3..7e8d6d5 100755 --- a/runtests +++ b/runtests @@ -8,4 +8,4 @@ then PYTHON=python3 fi -$PYTHON -m unittest discover tests +$PYTHON tests diff --git a/runtests.bat b/runtests.bat index e3a354a..641c705 100755 --- a/runtests.bat +++ b/runtests.bat @@ -1,6 +1,5 @@ @echo off -rem assume that python is on the path -rem echo "Executing tests (will only work if Python is on the path)" +rem echo "Executing tests (will only work if Python is on the PATH)" -python -m unittest discover tests +python tests diff --git a/tests/__main__.py b/tests/__main__.py new file mode 100644 index 0000000..a3b1524 --- /dev/null +++ b/tests/__main__.py @@ -0,0 +1,17 @@ +# mock out warning registry +import os, sys + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import MAGSBS +import unittest, unittest.mock +# Running tests will load the built-in MAGSBS localisation support which is not +# available during test runtime. Hence it's better mocked out. For the few rare +# cases where the warning registry is under test, the mock can be added using a +# patch to the test function. + +with unittest.mock.patch('MAGSBS.common.WarningRegistry'): + import unittest + sys.argv.append('discover') + sys.argv.append('tests') + unittest.TestProgram(module=None) diff --git a/tests/test_config.py b/tests/test_config.py index 512be27..233468e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,5 +1,6 @@ #pylint: disable=too-many-public-methods,import-error,too-few-public-methods,missing-docstring,unused-variable,multiple-imports import unittest +from unittest.mock import patch import distutils.version import os @@ -56,14 +57,13 @@ def test_that_same_version_just_works_fine(self): # bug fixes are treated as equal version conf('path', '0.9.5').read() - def test_that_newer_bugfix_version_emits_warning(self): - c = common.WarningRegistry() - c._WarningRegistry__warnings = [] # get rid of gettext warning + @patch('MAGSBS.common.WarningRegistry') + def test_that_newer_bugfix_version_emits_warning(self, wr_mock): c = conf('path', '0.9.5') write(c) conf('path', '0.9').read() # this registers the warning - warns = common.WarningRegistry().get_warnings() - self.assertEqual(len(warns), 1) + wr_mock.register_warning("foo") + self.assertEqual(len(wr_mock.register_warning.mock_calls), 1) def test_unparseable_version_number_raises(self): c = conf('path', '6.6.6') diff --git a/tests/test_locale.py b/tests/test_locale.py index 4dcb3d8..32c88df 100644 --- a/tests/test_locale.py +++ b/tests/test_locale.py @@ -38,7 +38,7 @@ def test_that_locale_is_available_OSX(self): def test_that_locale_is_available_Windows(self): # platform unknown, as is the os.sep, use slash *always* self.assertEqual(normalise_path(_get_localedir()), - "c:/programdata/matuc/locale") + "c:/programdata/agsbs/matuc/locale") # ToDo: test name ergibt keinen sinn, Testaufbau schlecht. Daten aus # Code sammeln, assert* ausführen