diff options
author | Georgy Frolov <gosha@fro.lv> | 2021-02-23 01:55:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 14:55:55 -0800 |
commit | c9fd72449e878b326b9335cb46fe6da716dc27c7 (patch) | |
tree | 5944a95fc870cb1425403a5c98379e6cb9f7a9f3 /tests | |
parent | 30212c6fc68ccf19d794530819cda8e6d4edf74c (diff) |
skip initial comment in pg_session file (#1245)
* skip initial comment in pg_session file
* add test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_config.py | 15 | ||||
-rw-r--r-- | tests/test_main.py | 7 |
2 files changed, 20 insertions, 2 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index 48408141..08fe74e6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,9 +1,10 @@ +import io import os import stat import pytest -from pgcli.config import ensure_dir_exists +from pgcli.config import ensure_dir_exists, skip_initial_comment def test_ensure_file_parent(tmpdir): @@ -28,3 +29,15 @@ def test_ensure_other_create_error(tmpdir): with pytest.raises(OSError): ensure_dir_exists(str(rcfile)) + + +@pytest.mark.parametrize( + "text, skipped_lines", + ( + ("abc\n", 1), + ("#[section]\ndef\n[section]", 2), + ("[section]", 0), + ), +) +def test_skip_initial_comment(text, skipped_lines): + assert skip_initial_comment(io.StringIO(text)) == skipped_lines diff --git a/tests/test_main.py b/tests/test_main.py index 965ff8fa..c48accbe 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -288,7 +288,12 @@ def test_pg_service_file(tmpdir): cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) with open(tmpdir.join(".pg_service.conf").strpath, "w") as service_conf: service_conf.write( - """[myservice] + """File begins with a comment + that is not a comment + # or maybe a comment after all + because psql is crazy + + [myservice] host=a_host user=a_user port=5433 |