From fe56bdba1243cc5f6a652eb75d11ae1d1957ff7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 4 Mar 2024 08:18:54 +0100 Subject: [PATCH] tests: Skip some test when fr_FR locale isn't available Some test require that locale so skip those when it is unavailable. Closes: #392 --- src/test-mount-matrix.c | 8 ++++++-- tests/integration-test.py | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/test-mount-matrix.c b/src/test-mount-matrix.c index 0cf6c34..d0b608c 100644 --- a/src/test-mount-matrix.c +++ b/src/test-mount-matrix.c @@ -66,12 +66,16 @@ test_mount_matrix (void) static void test_comma_decimal_separator (void) { + const char *fr_locale = "fr_FR.UTF-8"; char *old_locale; AccelVec3 *vecs; - old_locale = setlocale (LC_ALL, "fr_FR.UTF-8"); + old_locale = setlocale (LC_ALL, fr_locale); /* French locale not available? */ - g_assert_nonnull (old_locale); + if (!old_locale) { + g_test_skip_printf ("Local %s not available", fr_locale); + return; + } /* Default matrix */ g_assert_true (parse_mount_matrix (DEFAULT_MATRIX, &vecs)); diff --git a/tests/integration-test.py b/tests/integration-test.py index 20c0e92..4ccabb3 100755 --- a/tests/integration-test.py +++ b/tests/integration-test.py @@ -27,6 +27,7 @@ import tempfile import psutil import subprocess import unittest +import locale import time try: @@ -50,6 +51,7 @@ SP_COMPASS = 'net.hadess.SensorProxy.Compass' SP_COMPASS_PATH = '/net/hadess/SensorProxy/Compass' class Tests(dbusmock.DBusTestCase): + @classmethod def setUpClass(cls): # run from local build tree if we are in one, otherwise use system instance @@ -92,6 +94,15 @@ class Tests(dbusmock.DBusTestCase): cls.dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) cls.dbus_con = cls.get_dbus(True) + # Some test outputs require the daemon to run under the fr locale: + # so check if that's available + try: + old_loc = locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') + cls.has_fr = True + locale.setlocale(locale.LC_ALL, old_loc) + except: + cls.has_fr = False + @classmethod def tearDownClass(cls): cls.test_bus.down() @@ -612,10 +623,9 @@ class Tests(dbusmock.DBusTestCase): mock_file.write(data) self.proxy.ClaimAccelerometer() self.assertEventually(lambda: self.have_text_in_log('Accel sent by driver')) - # If the 2nd test fails, it's likely that fr_FR.UTF-8 locale isn't supported self.assertEqual(self.have_text_in_log('scale: 0,000000,0,000000,0,000000'), False) - self.assertEqual(self.have_text_in_log('scale: 0,000010,0,000010,0,000010'), True) - + if self.has_fr: + self.assertEqual(self.have_text_in_log('scale: 0,000010,0,000010,0,000010'), True) self.stop_daemon() def test_iio_scale_decimal_separator_offset(self): @@ -715,9 +725,9 @@ class Tests(dbusmock.DBusTestCase): self.proxy.ClaimAccelerometer() self.assertEventually(lambda: self.have_text_in_log('Accel read from IIO on')) - # If the 2nd test fails, it's likely that fr_FR.UTF-8 locale isn't supported self.assertEqual(self.have_text_in_log('scale 1,000000,1,000000,1,000000'), False) - self.assertEqual(self.have_text_in_log('scale 0,000001,0,000001,0,000001'), True) + if self.has_fr: + self.assertEqual(self.have_text_in_log('scale 0,000001,0,000001,0,000001'), True) self.assertEventually(lambda: self.get_dbus_property('AccelerometerOrientation') == 'normal')