Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/test_specials.py::test_slash_l* fail with non-en_US locale #140

Closed
mgorny opened this issue Apr 1, 2023 · 2 comments · Fixed by #141
Closed

tests/test_specials.py::test_slash_l* fail with non-en_US locale #140

mgorny opened this issue Apr 1, 2023 · 2 comments · Fixed by #141
Labels

Comments

@mgorny
Copy link
Contributor

mgorny commented Apr 1, 2023

We're running the test suite with C.UTF-8 locale (because unlike en_US it's guaranteed to be available on all Gentoo systems), and this results in the following test failures:

============================================================== FAILURES ===============================================================
____________________________________________________________ test_slash_l _____________________________________________________________

executor = <function executor.<locals>.query_runner at 0x7f7cfb8154e0>

    @dbtest
    def test_slash_l(executor):
        results = executor(r"\l")
        row = ("_test_db", "postgres", "UTF8", "en_US.UTF-8", "en_US.UTF-8", None)
        headers = ["Name", "Owner", "Encoding", "Collate", "Ctype", "Access privileges"]
>       assert row in results[1]
E       AssertionError: assert ('_test_db', 'postgres', 'UTF8', 'en_US.UTF-8', 'en_US.UTF-8', None) in [('_test_db', 'postgres', 'UTF8', 'C', 'C.UTF8', None), ('postgres', 'postgres', 'UTF8', 'C', 'C.UTF8', None), ('template0', 'postgres', 'UTF8', 'C', 'C.UTF8', '=c/postgres\npostgres=CTc/postgres'), ('template1', 'postgres', 'UTF8', 'C', 'C.UTF8', '=c/postgres\npostgres=CTc/postgres')]

executor   = <function executor.<locals>.query_runner at 0x7f7cfb8154e0>
headers    = ['Name', 'Owner', 'Encoding', 'Collate', 'Ctype', 'Access privileges']
results    = [None,
 [('_test_db', 'postgres', 'UTF8', 'C', 'C.UTF8', None),
  ('postgres', 'postgres', 'UTF8', 'C', 'C.UTF8', None),
  ('template0',
   'postgres',
   'UTF8',
   'C',
   'C.UTF8',
   '=c/postgres\npostgres=CTc/postgres'),
  ('template1',
   'postgres',
   'UTF8',
   'C',
   'C.UTF8',
   '=c/postgres\npostgres=CTc/postgres')],
 ['Name', 'Owner', 'Encoding', 'Collate', 'Ctype', 'Access privileges'],
 'SELECT 4']
row        = ('_test_db', 'postgres', 'UTF8', 'en_US.UTF-8', 'en_US.UTF-8', None)

tests/test_specials.py:16: AssertionError
________________________________________________________ test_slash_l_pattern _________________________________________________________

executor = <function executor.<locals>.query_runner at 0x7f7cfb8163e0>

    @dbtest
    def test_slash_l_pattern(executor):
        results = executor(r"\l _test*")
        row = [("_test_db", "postgres", "UTF8", "en_US.UTF-8", "en_US.UTF-8", None)]
        headers = ["Name", "Owner", "Encoding", "Collate", "Ctype", "Access privileges"]
>       assert row == results[1]
E       AssertionError: assert [('_test_db', 'postgres', 'UTF8', 'en_US.UTF-8', 'en_US.UTF-8', None)] == [('_test_db', 'postgres', 'UTF8', 'C', 'C.UTF8', None)]
E         At index 0 diff: ('_test_db', 'postgres', 'UTF8', 'en_US.UTF-8', 'en_US.UTF-8', None) != ('_test_db', 'postgres', 'UTF8', 'C', 'C.UTF8', None)
E         Full diff:
E         - [('_test_db', 'postgres', 'UTF8', 'C', 'C.UTF8', None)]
E         ?                                    ^^^^^^
E         + [('_test_db', 'postgres', 'UTF8', 'en_US.UTF-8', 'en_US.UTF-8', None)]
E         ?                                    ^^^^^    +   +++++++++++++++

executor   = <function executor.<locals>.query_runner at 0x7f7cfb8163e0>
headers    = ['Name', 'Owner', 'Encoding', 'Collate', 'Ctype', 'Access privileges']
results    = [None,
 [('_test_db', 'postgres', 'UTF8', 'C', 'C.UTF8', None)],
 ['Name', 'Owner', 'Encoding', 'Collate', 'Ctype', 'Access privileges'],
 'SELECT 1']
row        = [('_test_db', 'postgres', 'UTF8', 'en_US.UTF-8', 'en_US.UTF-8', None)]

tests/test_specials.py:25: AssertionError

Could you perhaps use the values from LANG/LC_* variables rather than hardcoding en_US? Also, the canonical IANA encoding name is UTF-8, not UTF8 — using the latter could result in weird problems e.g. on BSD systems.

@j-bennet j-bennet added the bug label Apr 3, 2023
@j-bennet
Copy link
Contributor

j-bennet commented Apr 3, 2023

@mgorny Thank you for pointing out the problem. If you feel like submitting a PR, that would be welcome too!

@mgorny
Copy link
Contributor Author

mgorny commented Apr 3, 2023

I'll try but I'm not a postgres expert, so I'm not sure if I'll get it right.

mgorny added a commit to mgorny/pgspecial that referenced this issue Apr 3, 2023
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 dbcli#140
j-bennet pushed a commit that referenced this issue Oct 28, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants