From 6fd33bfd1f7c8134f7127f5ed32096cc4d0802d0 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Fri, 14 Jun 2019 13:33:51 +0200 Subject: [PATCH] use LANG=C for running tests comparing human-readable output --- tests/test_builder/test_build_notification.py | 5 +++++ tests/test_cli/utils.py | 4 ++++ tests/test_lib/test_format_time.py | 6 ++++++ tests/test_lib/test_utils.py | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/tests/test_builder/test_build_notification.py b/tests/test_builder/test_build_notification.py index 0d35f6e6..24ee44c5 100644 --- a/tests/test_builder/test_build_notification.py +++ b/tests/test_builder/test_build_notification.py @@ -1,5 +1,6 @@ from __future__ import absolute_import import json +import locale import mock import os import tempfile @@ -72,6 +73,8 @@ class TestBuildNotification(unittest.TestCase): mock.patch.stopall() def test_build_notification(self): + # force locale to compare 'message' value + locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8')) # task_info['id'], method, params, self.session, self.options task_id = 999 fn = os.path.join(os.path.dirname(__file__), 'data/calls', 'build_notif_1', 'params.json') @@ -102,3 +105,5 @@ class TestBuildNotification(unittest.TestCase): with open(fn, 'rb') as fp: msg_expect = fp.read().decode() self.assertEqual(message, msg_expect) + + locale.resetlocale() diff --git a/tests/test_cli/utils.py b/tests/test_cli/utils.py index cc53c128..a84a3e87 100644 --- a/tests/test_cli/utils.py +++ b/tests/test_cli/utils.py @@ -1,5 +1,6 @@ from __future__ import print_function from __future__ import absolute_import +import locale import mock import os import six @@ -198,6 +199,9 @@ class CliTestCase(unittest.TestCase): @mock.patch('koji_cli.commands.activate_session') def assert_help(self, callableObj, message, activate_session_mock): + # optarse uses gettext directly and it is driven by LANGUAGE + # we need engligsh to get comparable strings + os.environ['LANGUAGE'] = 'en_GB' self.assert_system_exit( callableObj, mock.MagicMock(), diff --git a/tests/test_lib/test_format_time.py b/tests/test_lib/test_format_time.py index 91ae9ab6..b780dfa7 100644 --- a/tests/test_lib/test_format_time.py +++ b/tests/test_lib/test_format_time.py @@ -1,5 +1,6 @@ from __future__ import absolute_import import datetime +import locale try: import unittest2 as unittest except ImportError: @@ -30,6 +31,9 @@ class TestFormatTime(unittest.TestCase): self.assertEqual(formatTime(desired + '.123'), desired) def test_format_time_long(self): + # force locale to compare 'desired' value + locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8')) + self.assertEqual(formatTimeLong(None), '') self.assertEqual(formatTimeLong(''), '') @@ -57,3 +61,5 @@ class TestFormatTime(unittest.TestCase): r = formatTimeLong(d2 + '.123') r = r[:r.rfind(' ')] self.assertEqual(r, desired) + + locale.resetlocale() diff --git a/tests/test_lib/test_utils.py b/tests/test_lib/test_utils.py index ff781125..8af441b5 100644 --- a/tests/test_lib/test_utils.py +++ b/tests/test_lib/test_utils.py @@ -1,6 +1,7 @@ # coding=utf-8 from __future__ import absolute_import import calendar +import locale import mock import optparse import os @@ -551,6 +552,8 @@ class MavenUtilTestCase(unittest.TestCase): def test_formatChangelog(self): """Test formatChangelog function""" + # force locale to compare 'expect' value + locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8')) data = [ { 'author': 'Happy Koji User - 1.1-1', @@ -585,6 +588,8 @@ class MavenUtilTestCase(unittest.TestCase): result = koji.util.formatChangelog(data) self.assertMultiLineEqual(expect, result) + locale.resetlocale() + def test_parseTime(self): """Test parseTime function""" now = datetime.now()