From c9fd72449e878b326b9335cb46fe6da716dc27c7 Mon Sep 17 00:00:00 2001 From: Georgy Frolov Date: Tue, 23 Feb 2021 01:55:55 +0300 Subject: skip initial comment in pg_session file (#1245) * skip initial comment in pg_session file * add test --- tests/test_config.py | 15 ++++++++++++++- tests/test_main.py | 7 ++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'tests') 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 -- cgit v1.2.3