Skip to content

Commit ee94b98

Browse files
authored
Fix test_slash_l* to support non-en_US locales (#141)
* Fix test_slash_l* to support non-en_US locales Update the tests to expect the current locale rather than `en_US`. While technically this isn't 100% guaranteed to be the same locale as the database is running on, I think we can reasonably assume that for the purpose of testing they are the same. Non-UTF-8 locales still are not supported but the other tests seem to be unable to handle them well anyway. Fixes #140 * GHA: set locale matching the postgres locale
1 parent 24e5027 commit ee94b98

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
pip install -r requirements-dev.txt
5555
5656
- name: Run unit tests
57+
env:
58+
LANG: en_US.UTF-8
5759
run: coverage run --source pgspecial -m pytest
5860

5961
- name: Run Black

changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Upcoming
22
========
33

44
* Added `build-system` section to `pyproject.toml` to use the modern setuptools backend.
5+
* Fixed test failures when locale other than `en_US` is used.
56

67
2.1.0 (2023-03-31)
78
=========

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import pytest
22
from dbutils import create_db, db_connection, setup_db, teardown_db, TEST_DB_NAME
3+
import locale
34
from pgspecial.main import PGSpecial
45

56

7+
locale.setlocale(locale.LC_ALL, "")
8+
9+
610
@pytest.fixture(scope="module")
711
def connection():
812
create_db(TEST_DB_NAME)

tests/test_specials.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@
44
import pytest
55
from dbutils import dbtest, POSTGRES_USER, SERVER_VERSION, foreign_db_environ, fdw_test
66
import itertools
7+
import locale
78

89
objects_listing_headers = ["Schema", "Name", "Type", "Owner", "Size", "Description"]
910

11+
# note: technically, this is the database encoding, not the client
12+
# locale but for the purpose of testing we can assume the server
13+
# and the client are using the same locale
14+
# note 2: locale.getlocale() does not return the raw values,
15+
# in particular it transforms C into en_US, so we use .setlocale()
16+
# instead as that matches the C library function
17+
LC_COLLATE = locale.setlocale(locale.LC_COLLATE, None)
18+
LC_CTYPE = locale.setlocale(locale.LC_CTYPE, None)
19+
1020

1121
@dbtest
1222
def test_slash_l(executor):
1323
results = executor(r"\l")
14-
row = ("_test_db", "postgres", "UTF8", "en_US.UTF-8", "en_US.UTF-8", None)
24+
row = ("_test_db", "postgres", "UTF8", LC_COLLATE, LC_CTYPE, None)
1525
headers = ["Name", "Owner", "Encoding", "Collate", "Ctype", "Access privileges"]
1626
assert row in results[1]
1727
assert headers == results[2]
@@ -20,7 +30,7 @@ def test_slash_l(executor):
2030
@dbtest
2131
def test_slash_l_pattern(executor):
2232
results = executor(r"\l _test*")
23-
row = [("_test_db", "postgres", "UTF8", "en_US.UTF-8", "en_US.UTF-8", None)]
33+
row = [("_test_db", "postgres", "UTF8", LC_COLLATE, LC_CTYPE, None)]
2434
headers = ["Name", "Owner", "Encoding", "Collate", "Ctype", "Access privileges"]
2535
assert row == results[1]
2636
assert headers == results[2]

0 commit comments

Comments
 (0)