From 11ffb42d891f656f585052585c83303822ef4fed Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Sat, 20 Aug 2022 20:11:23 -0400
Subject: [PATCH] Improve indentation of some display output values

---
 py_dbcn/connectors/core/display.py         | 11 +++++++-
 py_dbcn/connectors/postgresql/tables.py    | 21 ++++++++------
 tests/connectors/mysql/test_records.py     | 33 ++++++++++++++--------
 tests/connectors/mysql/test_tables.py      | 30 +++++++++++++-------
 tests/connectors/postgresql/test_tables.py | 25 ++++++++++------
 5 files changed, 81 insertions(+), 39 deletions(-)

diff --git a/py_dbcn/connectors/core/display.py b/py_dbcn/connectors/core/display.py
index ba34dc5..d2f8080 100644
--- a/py_dbcn/connectors/core/display.py
+++ b/py_dbcn/connectors/core/display.py
@@ -6,6 +6,7 @@ Should be inherited by language-specific connectors.
 """
 
 # System Imports.
+import textwrap
 from colorama import Fore, Style
 
 # User Imports.
@@ -59,10 +60,18 @@ class BaseDisplay:
 
     def query(self, query_str):
         """Formats query output for display."""
-        logger.results('{0}{1}{2}'.format(Fore.MAGENTA, query_str, Style.RESET_ALL))
+        # Remove any whitespace created from standard code indentations.
+        query_str = textwrap.dedent(query_str).strip()
+
+        # Log results.
+        logger.query('{0}{1}{2}'.format(Fore.MAGENTA, query_str, Style.RESET_ALL))
 
     def results(self, result_str):
         """Formats result output for display."""
+        # Remove any whitespace created from standard code indentations.
+        result_str = textwrap.dedent(result_str).strip()
+
+        # Log results.
         logger.results('{0}{1}{2}'.format(Fore.BLUE, result_str, Style.RESET_ALL))
 
 
diff --git a/py_dbcn/connectors/postgresql/tables.py b/py_dbcn/connectors/postgresql/tables.py
index 517f787..c824981 100644
--- a/py_dbcn/connectors/postgresql/tables.py
+++ b/py_dbcn/connectors/postgresql/tables.py
@@ -5,6 +5,7 @@ Contains database connection logic specific to PostgreSQL databases.
 """
 
 # System Imports.
+import textwrap
 
 # User Imports.
 from py_dbcn.connectors.core.tables import BaseTables
@@ -28,9 +29,11 @@ class PostgresqlTables(BaseTables):
         # Initialize variables.
         # StackOverflow suggested each of these in different answers.
         # Unsure of which one is better/worse, and what the differences mean.
-        self._show_tables_query = (
-            "SELECT table_name FROM information_schema.tables "
-            "WHERE table_schema = 'public';"
+        self._show_tables_query = textwrap.dedent(
+            """
+            SELECT table_name FROM information_schema.tables
+            WHERE table_schema = 'public';
+            """
 
             # "SELECT table_schema || '.' || table_name "
             # "FROM information_schema.tables "
@@ -39,8 +42,10 @@ class PostgresqlTables(BaseTables):
 
             # "SELECT * FROM pg_catalog.pg_tables "
             # "WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema';"
-        )
-        self._describe_table_query = (
-            "SELECT * FROM information_schema.columns "
-            "WHERE (table_schema = 'public' AND table_name = '{0}');"
-        )
+        ).strip()
+        self._describe_table_query = textwrap.dedent(
+            """
+            SELECT * FROM information_schema.columns
+            WHERE (table_schema = 'public' AND table_name = '{0}');
+            """
+        ).strip()
diff --git a/tests/connectors/mysql/test_records.py b/tests/connectors/mysql/test_records.py
index 77c4b1d..459447b 100644
--- a/tests/connectors/mysql/test_records.py
+++ b/tests/connectors/mysql/test_records.py
@@ -3,6 +3,7 @@ Tests for "records" logic of "MySQL" DB Connector class.
 """
 
 # System Imports.
+import textwrap
 
 # User Imports.
 from .test_core import TestMysqlDatabaseParent
@@ -35,15 +36,23 @@ class TestMysqlRecords(TestMysqlDatabaseParent, CoreRecordsTestMixin):
                 cls.connector.tables.drop(result)
 
         # Define default table columns.
-        cls._columns_query__basic = """(
-            id INT NOT NULL AUTO_INCREMENT,
-            name VARCHAR(100),
-            description VARCHAR(100),
-            PRIMARY KEY ( id )
-        )"""
-        cls._columns_query__datetime = """(
-            id INT NOT NULL AUTO_INCREMENT,
-            test_datetime DATETIME,
-            test_date DATE,
-            PRIMARY KEY ( id )
-        )"""
+        cls._columns_query__basic = textwrap.dedent(
+            """
+            (
+                id INT NOT NULL AUTO_INCREMENT,
+                name VARCHAR(100),
+                description VARCHAR(100),
+                PRIMARY KEY ( id )
+            )
+            """
+        ).strip()
+        cls._columns_query__datetime = textwrap.dedent(
+            """
+            (
+                id INT NOT NULL AUTO_INCREMENT,
+                test_datetime DATETIME,
+                test_date DATE,
+                PRIMARY KEY ( id )
+            )
+            """
+        ).strip()
diff --git a/tests/connectors/mysql/test_tables.py b/tests/connectors/mysql/test_tables.py
index bf88b38..19377a4 100644
--- a/tests/connectors/mysql/test_tables.py
+++ b/tests/connectors/mysql/test_tables.py
@@ -5,6 +5,8 @@ Tests for "tables" logic of "MySQL" DB Connector class.
 # System Imports.
 
 # User Imports.
+import textwrap
+
 from .test_core import TestMysqlDatabaseParent
 from tests.connectors.core.test_tables import CoreTablesTestMixin
 
@@ -35,13 +37,21 @@ class TestMysqlTables(TestMysqlDatabaseParent, CoreTablesTestMixin):
                 cls.connector.tables.drop(result)
 
         # Define database-specific query values.
-        cls._basic_table_columns = """
-            id INT(11) NOT NULL AUTO_INCREMENT,
-            PRIMARY KEY (id)
-        """
-        cls._columns_query = """(
-            id INT NOT NULL AUTO_INCREMENT,
-            name VARCHAR(100),
-            description VARCHAR(100),
-            PRIMARY KEY ( id )
-        )"""
+        cls._basic_table_columns = textwrap.dedent(
+            """
+            (
+                id INT(11) NOT NULL AUTO_INCREMENT,
+                PRIMARY KEY (id)
+            )
+            """
+        ).strip()
+        cls._columns_query = textwrap.dedent(
+            """
+            (
+                id INT NOT NULL AUTO_INCREMENT,
+                name VARCHAR(100),
+                description VARCHAR(100),
+                PRIMARY KEY ( id )
+            )
+            """
+        ).strip()
diff --git a/tests/connectors/postgresql/test_tables.py b/tests/connectors/postgresql/test_tables.py
index d6c632a..f913138 100644
--- a/tests/connectors/postgresql/test_tables.py
+++ b/tests/connectors/postgresql/test_tables.py
@@ -3,6 +3,7 @@ Tests for "tables" logic of "PostgreSQL" DB Connector class.
 """
 
 # System Imports.
+import textwrap
 
 # User Imports.
 from .test_core import TestPostgresqlDatabaseParent
@@ -35,11 +36,19 @@ class TestPostgresqlTables(TestPostgresqlDatabaseParent, CoreTablesTestMixin):
                 cls.connector.tables.drop(result)
 
         # Define database-specific query values.
-        cls._basic_table_columns = """
-            id serial PRIMARY KEY
-        """
-        cls._columns_query = """(
-            id serial PRIMARY KEY,
-            name VARCHAR(100),
-            description VARCHAR(100)
-        )"""
+        cls._basic_table_columns = textwrap.dedent(
+            """
+            (
+                id serial PRIMARY KEY
+            )
+            """
+        ).strip()
+        cls._columns_query = textwrap.dedent(
+            """
+            (
+                id serial PRIMARY KEY,
+                name VARCHAR(100),
+                description VARCHAR(100)
+            )
+            """
+        ).strip()
-- 
GitLab