From 739e9d05f79ce09fcad14e651bc81e0ab8f3ac18 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 14 2019 11:48:58 +0000 Subject: use LANG=C for running tests comparing human-readable output --- diff --git a/tests/test_builder/test_build_notification.py b/tests/test_builder/test_build_notification.py index 0d35f6e..24ee44c 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 cc53c12..a84a3e8 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 91ae9ab..b780dfa 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 ff78112..8af441b 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()