diff --git a/py_dbcn/connectors/core/display.py b/py_dbcn/connectors/core/display.py index ba34dc534763fdbfcbc7059d443e8efd21ea0be4..d2f8080ba40d919417b41a88930bf99144b6bb3e 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 517f7874255a6724c2ab70b3a246a09fab8c1368..c824981d99a63da12185a84355527021cf8eb2cf 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 77c4b1d0c1540efd9b1a5477b70804624b4fe3b7..459447b9cec2b615358dd6600e2db72af6c1378f 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 bf88b384c54f2f59a7284770d04bc83843c846d3..19377a4655bb4211618784d43ef3b29fc897d060 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 d6c632a5c1b9e32e23028214c8a815649d23d242..f913138f6732593bf8aa371643d5ef3a7d33dbc3 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()