|
2 | 2 | import os
|
3 | 3 | import pwd
|
4 | 4 | import re
|
| 5 | +import subprocess |
5 | 6 | import time
|
| 7 | +import venv |
6 | 8 |
|
7 | 9 | import pytest
|
| 10 | +from packaging import version |
8 | 11 | from unit.applications.lang.python import TestApplicationPython
|
9 | 12 |
|
10 | 13 |
|
@@ -526,6 +529,81 @@ def test_python_application_write(self):
|
526 | 529 |
|
527 | 530 | assert self.get()['body'] == '0123456789', 'write'
|
528 | 531 |
|
| 532 | + def test_python_application_encoding(self): |
| 533 | + self.load('encoding') |
| 534 | + |
| 535 | + try: |
| 536 | + locales = ( |
| 537 | + subprocess.check_output( |
| 538 | + ['locale', '-a'], |
| 539 | + stderr=subprocess.STDOUT, |
| 540 | + ) |
| 541 | + .decode() |
| 542 | + .splitlines() |
| 543 | + ) |
| 544 | + except ( |
| 545 | + FileNotFoundError, |
| 546 | + UnicodeDecodeError, |
| 547 | + subprocess.CalledProcessError, |
| 548 | + ): |
| 549 | + pytest.skip('require locale') |
| 550 | + |
| 551 | + to_check = [ |
| 552 | + re.compile(r'.*UTF[-_]?8'), |
| 553 | + re.compile(r'.*ISO[-_]?8859[-_]?1'), |
| 554 | + ] |
| 555 | + matches = [ |
| 556 | + loc |
| 557 | + for loc in locales |
| 558 | + if any(pattern.match(loc.upper()) for pattern in to_check) |
| 559 | + ] |
| 560 | + |
| 561 | + if not matches: |
| 562 | + pytest.skip('no available locales') |
| 563 | + |
| 564 | + def unify(str): |
| 565 | + str.upper().replace('-', '').replace('_', '') |
| 566 | + |
| 567 | + for loc in matches: |
| 568 | + assert 'success' in self.conf( |
| 569 | + {"LC_CTYPE": loc, "LC_ALL": ""}, |
| 570 | + '/config/applications/encoding/environment', |
| 571 | + ) |
| 572 | + resp = self.get() |
| 573 | + assert resp['status'] == 200, 'status' |
| 574 | + assert unify(resp['headers']['X-Encoding']) == unify( |
| 575 | + loc.split('.')[-1] |
| 576 | + ) |
| 577 | + |
| 578 | + def test_python_application_unicode(self, temp_dir): |
| 579 | + try: |
| 580 | + app_type = self.get_application_type() |
| 581 | + v = version.Version(app_type.split()[-1]) |
| 582 | + if v.major != 3: |
| 583 | + raise version.InvalidVersion |
| 584 | + |
| 585 | + except version.InvalidVersion: |
| 586 | + pytest.skip('require python module version 3') |
| 587 | + |
| 588 | + venv_path = temp_dir + '/venv' |
| 589 | + venv.create(venv_path) |
| 590 | + |
| 591 | + self.load('unicode') |
| 592 | + assert 'success' in self.conf( |
| 593 | + '"' + venv_path + '"', |
| 594 | + '/config/applications/unicode/home', |
| 595 | + ) |
| 596 | + assert ( |
| 597 | + self.get( |
| 598 | + headers={ |
| 599 | + 'Host': 'localhost', |
| 600 | + 'Temp-dir': temp_dir, |
| 601 | + 'Connection': 'close', |
| 602 | + } |
| 603 | + )['status'] |
| 604 | + == 200 |
| 605 | + ) |
| 606 | + |
529 | 607 | def test_python_application_threading(self):
|
530 | 608 | """wait_for_record() timeouts after 5s while every thread works at
|
531 | 609 | least 3s. So without releasing GIL test should fail.
|
|
0 commit comments