From dfff885cfeaffe238d5cf276367ed99166b12635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihkel=20M=C3=A4nna?= Date: Sat, 6 Apr 2024 11:48:40 +0300 Subject: [PATCH 1/2] remove double quotes from filenames --- pgtricks/pg_split_schema_dump.py | 2 +- pgtricks/tests/test_pg_split_schema_dump.py | 34 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/pgtricks/pg_split_schema_dump.py b/pgtricks/pg_split_schema_dump.py index 1c998ff..a99b917 100755 --- a/pgtricks/pg_split_schema_dump.py +++ b/pgtricks/pg_split_schema_dump.py @@ -64,7 +64,7 @@ def split_sql_file(sqlpath: str, target_directory: str) -> None: ) print(part) continue - name = match.group(1).replace(" ", "_") + name = match.group(1).replace(" ", "_").replace('"', '') type_ = match.group(2).replace(" ", "_") schema = match.group(3) if schema == "-": diff --git a/pgtricks/tests/test_pg_split_schema_dump.py b/pgtricks/tests/test_pg_split_schema_dump.py index f90c5ec..231c2d5 100644 --- a/pgtricks/tests/test_pg_split_schema_dump.py +++ b/pgtricks/tests/test_pg_split_schema_dump.py @@ -151,3 +151,37 @@ def test_split_sql_file_unrecognized_content(tmpdir): (information for the unidentified content goes here) =============================================================================""" ) + +def test_split_sql_file_with_quotes_in_name(tmpdir): + target_directory = tmpdir / 'target' + sqlpath = tmpdir / 'test.sql' + sqlpath.write( + dedent( + ''' + + -- + -- Name: "user"; Type: TABLE; Schema: public; Owner: + -- + + (information for user table goes here) + ''' + ) + ) + + split_sql_file(str(sqlpath), str(target_directory)) + + assert {path.basename for path in target_directory.listdir()} == { + 'public.user.TABLE' + } + assert (target_directory / 'public.user.TABLE').readlines(cr=False) == [ + 'SET search_path = public;', + '', + '', + '', + '--', + '-- Name: "user"; Type: TABLE; Schema: public; Owner:', + '--', + '', + '(information for user table goes here)', + '', + ] From 43a1906bf6da0403c7ac959003850bf77c28cc73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihkel=20M=C3=A4nna?= Date: Sun, 14 Apr 2024 13:28:09 +0300 Subject: [PATCH 2/2] fix formatting to conform to Black --- pgtricks/pg_split_schema_dump.py | 2 +- pgtricks/tests/test_pg_split_schema_dump.py | 31 +++++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pgtricks/pg_split_schema_dump.py b/pgtricks/pg_split_schema_dump.py index a99b917..1f717a9 100755 --- a/pgtricks/pg_split_schema_dump.py +++ b/pgtricks/pg_split_schema_dump.py @@ -64,7 +64,7 @@ def split_sql_file(sqlpath: str, target_directory: str) -> None: ) print(part) continue - name = match.group(1).replace(" ", "_").replace('"', '') + name = match.group(1).replace(" ", "_").replace('"', "") type_ = match.group(2).replace(" ", "_") schema = match.group(3) if schema == "-": diff --git a/pgtricks/tests/test_pg_split_schema_dump.py b/pgtricks/tests/test_pg_split_schema_dump.py index 231c2d5..24174fe 100644 --- a/pgtricks/tests/test_pg_split_schema_dump.py +++ b/pgtricks/tests/test_pg_split_schema_dump.py @@ -152,36 +152,37 @@ def test_split_sql_file_unrecognized_content(tmpdir): =============================================================================""" ) + def test_split_sql_file_with_quotes_in_name(tmpdir): - target_directory = tmpdir / 'target' - sqlpath = tmpdir / 'test.sql' + target_directory = tmpdir / "target" + sqlpath = tmpdir / "test.sql" sqlpath.write( dedent( - ''' + """ -- -- Name: "user"; Type: TABLE; Schema: public; Owner: -- (information for user table goes here) - ''' + """ ) ) split_sql_file(str(sqlpath), str(target_directory)) assert {path.basename for path in target_directory.listdir()} == { - 'public.user.TABLE' + "public.user.TABLE" } - assert (target_directory / 'public.user.TABLE').readlines(cr=False) == [ - 'SET search_path = public;', - '', - '', - '', - '--', + assert (target_directory / "public.user.TABLE").readlines(cr=False) == [ + "SET search_path = public;", + "", + "", + "", + "--", '-- Name: "user"; Type: TABLE; Schema: public; Owner:', - '--', - '', - '(information for user table goes here)', - '', + "--", + "", + "(information for user table goes here)", + "", ]