Skip to content

Commit

Permalink
Surpress locales warning for test runs
Browse files Browse the repository at this point in the history
  • Loading branch information
humenda committed Sep 26, 2019
1 parent a00bf46 commit 37b23de
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion MAGSBS/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
2 changes: 1 addition & 1 deletion runtests
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ then
PYTHON=python3
fi

$PYTHON -m unittest discover tests
$PYTHON tests
5 changes: 2 additions & 3 deletions runtests.bat
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions tests/__main__.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 5 additions & 5 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37b23de

Please sign in to comment.