dbcli / pgspecial

Python implementation of postgres meta commands (backslash commands)
BSD 3-Clause "New" or "Revised" License
76 stars 53 forks source link

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

Closed mgorny closed 1 year ago

mgorny commented 1 year ago

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 commented 1 year ago

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

mgorny commented 1 year ago

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