From c093ee7ec50233feb3ff0444c91e394abee4c52a Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Fri, 26 Mar 2021 15:42:58 +0000 Subject: Tests: added test for Ruby default encoding. --- test/test_ruby_application.py | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'test/test_ruby_application.py') diff --git a/test/test_ruby_application.py b/test/test_ruby_application.py index b18a6cee..12a078b7 100644 --- a/test/test_ruby_application.py +++ b/test/test_ruby_application.py @@ -1,4 +1,5 @@ import re +import subprocess import pytest from unit.applications.lang.ruby import TestApplicationRuby @@ -223,6 +224,52 @@ class TestRubyApplication(TestApplicationRuby): self.wait_for_record(r'\[error\].+At exit called\.') is not None ), 'at exit' + def test_ruby_application_encoding(self): + self.load('encoding') + + try: + locales = subprocess.check_output( + ['locale', '-a'], stderr=subprocess.STDOUT, + ).decode().split('\n') + + except (FileNotFoundError, subprocess.CalledProcessError): + pytest.skip('require locale') + + def get_locale(pattern): + return next( + ( + l + for l in locales + if re.match(pattern, l.upper()) is not None + ), + None, + ) + + utf8 = get_locale(r'.*UTF[-_]?8') + iso88591 = get_locale(r'.*ISO[-_]?8859[-_]?1') + + def check_locale(enc): + assert 'success' in self.conf( + {"LC_CTYPE": enc}, '/config/applications/encoding/environment', + ) + + resp = self.get() + assert resp['status'] == 200, 'status' + + enc_default = re.sub(r'[-_]', '', resp['headers']['X-Enc']).upper() + assert ( + enc_default == re.sub(r'[-_]', '', enc.split('.')[-1]).upper() + ) + + if utf8: + check_locale(utf8) + + if iso88591: + check_locale(iso88591) + + if not utf8 and not iso88591: + pytest.skip('no available locales') + def test_ruby_application_header_custom(self): self.load('header_custom') -- cgit From 46d8567dd7c2a9af025f1de13084a9efd7118e20 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 1 Apr 2021 00:05:44 +0100 Subject: Tests: unset LC_ALL variable in Ruby encoding test. This change is necessary to set Encoding.default_external value correctly. --- test/test_ruby_application.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/test_ruby_application.py') diff --git a/test/test_ruby_application.py b/test/test_ruby_application.py index 12a078b7..17491619 100644 --- a/test/test_ruby_application.py +++ b/test/test_ruby_application.py @@ -250,7 +250,8 @@ class TestRubyApplication(TestApplicationRuby): def check_locale(enc): assert 'success' in self.conf( - {"LC_CTYPE": enc}, '/config/applications/encoding/environment', + {"LC_CTYPE": enc, "LC_ALL": ""}, + '/config/applications/encoding/environment', ) resp = self.get() -- cgit From 6c97a1a069f0ae8cf683c8364fb7f9dabc5e89cb Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 5 Apr 2021 14:03:05 +0100 Subject: Tests: style. --- test/test_ruby_application.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test/test_ruby_application.py') diff --git a/test/test_ruby_application.py b/test/test_ruby_application.py index 17491619..ddd31f59 100644 --- a/test/test_ruby_application.py +++ b/test/test_ruby_application.py @@ -2,6 +2,7 @@ import re import subprocess import pytest + from unit.applications.lang.ruby import TestApplicationRuby @@ -208,7 +209,6 @@ class TestRubyApplication(TestApplicationRuby): self.get() - assert ( self.wait_for_record(r'\[error\].+1234567890') is not None ), 'errors write int' @@ -228,9 +228,13 @@ class TestRubyApplication(TestApplicationRuby): self.load('encoding') try: - locales = subprocess.check_output( - ['locale', '-a'], stderr=subprocess.STDOUT, - ).decode().split('\n') + locales = ( + subprocess.check_output( + ['locale', '-a'], stderr=subprocess.STDOUT, + ) + .decode() + .split('\n') + ) except (FileNotFoundError, subprocess.CalledProcessError): pytest.skip('require locale') -- cgit