From 4a10f2cb379cb127806ab2e63c173d59694f039c Mon Sep 17 00:00:00 2001 From: Matt Ball Date: Thu, 27 Jun 2019 08:28:02 -0600 Subject: [PATCH 1/3] update test_context.py to use a local import of mock_adapter This is consistent with the way that unit tests import utils.py and also fixes an import issue with our test environment. --- test/unit/test_context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test_context.py b/test/unit/test_context.py index e7416f6e5eb..4fd25b8f908 100644 --- a/test/unit/test_context.py +++ b/test/unit/test_context.py @@ -4,7 +4,7 @@ from dbt.contracts.graph.parsed import ParsedNode from dbt.context import parser, runtime import dbt.exceptions -from test.unit.mock_adapter import adapter_factory +from .mock_adapter import adapter_factory From 3ad30217c4f9130a768b383f76b780901006e129 Mon Sep 17 00:00:00 2001 From: Matt Ball Date: Thu, 27 Jun 2019 08:36:11 -0600 Subject: [PATCH 2/3] remove DeprecationWarnings from test/unit files We're getting a bunch of deprecation warnings when running the unit tests due to using statements like assertEquals instead of assertEqual. This change removes these warnings. Change completed via these Linux commands: $ cd test/unit $ sed -i 's/self.assertEquals/self.assertEqual/g' test_*.py $ sed -i 's/self.assertNotEquals/self.assertNotEqual/g' test_*.py --- test/unit/test_bigquery_adapter.py | 4 ++-- test/unit/test_graph_selection.py | 4 ++-- test/unit/test_postgres_adapter.py | 6 +++--- test/unit/test_redshift_adapter.py | 6 +++--- test/unit/test_utils.py | 16 ++++++++-------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/unit/test_bigquery_adapter.py b/test/unit/test_bigquery_adapter.py index 2891a2ce4c6..23ba7c78f83 100644 --- a/test/unit/test_bigquery_adapter.py +++ b/test/unit/test_bigquery_adapter.py @@ -79,7 +79,7 @@ def test_acquire_connection_oauth_validations(self, mock_open_connection): adapter = self.get_adapter('oauth') try: connection = adapter.acquire_connection('dummy') - self.assertEquals(connection.get('type'), 'bigquery') + self.assertEqual(connection.get('type'), 'bigquery') except dbt.exceptions.ValidationException as e: self.fail('got ValidationException: {}'.format(str(e))) @@ -94,7 +94,7 @@ def test_acquire_connection_service_account_validations(self, mock_open_connecti adapter = self.get_adapter('service_account') try: connection = adapter.acquire_connection('dummy') - self.assertEquals(connection.get('type'), 'bigquery') + self.assertEqual(connection.get('type'), 'bigquery') except dbt.exceptions.ValidationException as e: self.fail('got ValidationException: {}'.format(str(e))) diff --git a/test/unit/test_graph_selection.py b/test/unit/test_graph_selection.py index 8213ed1e1dd..f82c734b49a 100644 --- a/test/unit/test_graph_selection.py +++ b/test/unit/test_graph_selection.py @@ -55,7 +55,7 @@ def run_specs_and_assert(self, graph, include, exclude, expected): exclude ) - self.assertEquals(selected, expected) + self.assertEqual(selected, expected) def test__single_node_selection_in_package(self): @@ -177,7 +177,7 @@ def test__package_name_getter(self): found = graph_selector.get_package_names(self.package_graph) expected = set(['X', 'Y']) - self.assertEquals(found, expected) + self.assertEqual(found, expected) def assert_is_selected_node(self, node, spec, should_work): self.assertEqual( diff --git a/test/unit/test_postgres_adapter.py b/test/unit/test_postgres_adapter.py index 94afdc9c317..a87e12bcccc 100644 --- a/test/unit/test_postgres_adapter.py +++ b/test/unit/test_postgres_adapter.py @@ -58,15 +58,15 @@ def test_acquire_connection_validations(self, psycopg2): except BaseException as e: self.fail('acquiring connection failed with unknown exception: {}' .format(str(e))) - self.assertEquals(connection.type, 'postgres') + self.assertEqual(connection.type, 'postgres') psycopg2.connect.assert_called_once() @mock.patch('dbt.adapters.postgres.connections.psycopg2') def test_acquire_connection(self, psycopg2): connection = self.adapter.acquire_connection('dummy') - self.assertEquals(connection.state, 'open') - self.assertNotEquals(connection.handle, None) + self.assertEqual(connection.state, 'open') + self.assertNotEqual(connection.handle, None) psycopg2.connect.assert_called_once() def test_cancel_open_connections_empty(self): diff --git a/test/unit/test_redshift_adapter.py b/test/unit/test_redshift_adapter.py index 9776a9c44bd..d03dd250efe 100644 --- a/test/unit/test_redshift_adapter.py +++ b/test/unit/test_redshift_adapter.py @@ -61,13 +61,13 @@ def adapter(self): def test_implicit_database_conn(self): creds = RedshiftAdapter.ConnectionManager.get_credentials(self.config.credentials) - self.assertEquals(creds, self.config.credentials) + self.assertEqual(creds, self.config.credentials) def test_explicit_database_conn(self): self.config.method = 'database' creds = RedshiftAdapter.ConnectionManager.get_credentials(self.config.credentials) - self.assertEquals(creds, self.config.credentials) + self.assertEqual(creds, self.config.credentials) def test_explicit_iam_conn(self): self.config.credentials = self.config.credentials.incorporate( @@ -80,7 +80,7 @@ def test_explicit_iam_conn(self): creds = RedshiftAdapter.ConnectionManager.get_credentials(self.config.credentials) expected_creds = self.config.credentials.incorporate(password='tmp_password') - self.assertEquals(creds, expected_creds) + self.assertEqual(creds, expected_creds) def test_invalid_auth_method(self): # we have to set method this way, otherwise it won't validate diff --git a/test/unit/test_utils.py b/test/unit/test_utils.py index 29ae515d641..a66b2f5a72d 100644 --- a/test/unit/test_utils.py +++ b/test/unit/test_utils.py @@ -18,7 +18,7 @@ def test__simple_cases(self): for case in cases: actual = dbt.utils.deep_merge(*case['args']) - self.assertEquals( + self.assertEqual( case['expected'], actual, 'failed on {} (actual {}, expected {})'.format( case['description'], actual, case['expected'])) @@ -38,7 +38,7 @@ def test__simple_cases(self): for case in cases: actual = dbt.utils.deep_merge(*case['args']) - self.assertEquals( + self.assertEqual( case['expected'], actual, 'failed on {} (actual {}, expected {})'.format( case['description'], actual, case['expected'])) @@ -88,10 +88,10 @@ def test__simple_cases(self): ], } actual = dbt.utils.deep_map(self.intify_all, self.input_value) - self.assertEquals(actual, expected) + self.assertEqual(actual, expected) actual = dbt.utils.deep_map(self.intify_all, expected) - self.assertEquals(actual, expected) + self.assertEqual(actual, expected) @staticmethod @@ -121,20 +121,20 @@ def test__keypath(self): ], } actual = dbt.utils.deep_map(self.special_keypath, self.input_value) - self.assertEquals(actual, expected) + self.assertEqual(actual, expected) actual = dbt.utils.deep_map(self.special_keypath, expected) - self.assertEquals(actual, expected) + self.assertEqual(actual, expected) def test__noop(self): actual = dbt.utils.deep_map(lambda x, _: x, self.input_value) - self.assertEquals(actual, self.input_value) + self.assertEqual(actual, self.input_value) def test_trivial(self): cases = [[], {}, 1, 'abc', None, True] for case in cases: result = dbt.utils.deep_map(lambda x, _: x, case) - self.assertEquals(result, case) + self.assertEqual(result, case) with self.assertRaises(dbt.exceptions.DbtConfigError): dbt.utils.deep_map(lambda x, _: x, {'foo': object()}) From 2f1dbc2daef8103c3d5a6aa63c2d3c712cb8c13e Mon Sep 17 00:00:00 2001 From: Matt Ball Date: Thu, 27 Jun 2019 09:10:57 -0600 Subject: [PATCH 3/3] change assert{Not}Equals to assert{Not}Equal in integration tests This is to remove deprecation warnings during testing. Linux commands (with globstar shell option enable): $ cd test $ sed -i 's/self.assertEquals/self.assertEqual/g' **/*.py $ sed -i 's/self.assertNotEquals/self.assertNotEqual/g' **/*.py --- .../test_changing_relation_type.py | 26 +++++++++---------- .../test_external_reference.py | 8 +++--- test/integration/base.py | 4 +-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/integration/035_changing_relation_type_test/test_changing_relation_type.py b/test/integration/035_changing_relation_type_test/test_changing_relation_type.py index 1ba5df7ebbc..e4360112428 100644 --- a/test/integration/035_changing_relation_type_test/test_changing_relation_type.py +++ b/test/integration/035_changing_relation_type_test/test_changing_relation_type.py @@ -20,23 +20,23 @@ def swap_types_and_test(self): # between materializations that create tables and views. results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEquals(results[0].node['config']['materialized'], 'view') + self.assertEqual(results[0].node['config']['materialized'], 'view') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: table']) - self.assertEquals(results[0].node['config']['materialized'], 'table') + self.assertEqual(results[0].node['config']['materialized'], 'table') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEquals(results[0].node['config']['materialized'], 'view') + self.assertEqual(results[0].node['config']['materialized'], 'view') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: incremental']) - self.assertEquals(results[0].node['config']['materialized'], 'incremental') + self.assertEqual(results[0].node['config']['materialized'], 'incremental') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEquals(results[0].node['config']['materialized'], 'view') + self.assertEqual(results[0].node['config']['materialized'], 'view') self.assertEqual(len(results), 1) @use_profile("postgres") @@ -59,23 +59,23 @@ def test__bigquery__switch_materialization(self): # and then remove these bq-specific tests results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEquals(results[0].node['config']['materialized'], 'view') + self.assertEqual(results[0].node['config']['materialized'], 'view') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: table']) - self.assertEquals(results[0].node['config']['materialized'], 'table') + self.assertEqual(results[0].node['config']['materialized'], 'table') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: view', "--full-refresh"]) - self.assertEquals(results[0].node['config']['materialized'], 'view') + self.assertEqual(results[0].node['config']['materialized'], 'view') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: incremental']) - self.assertEquals(results[0].node['config']['materialized'], 'incremental') + self.assertEqual(results[0].node['config']['materialized'], 'incremental') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: view', "--full-refresh"]) - self.assertEquals(results[0].node['config']['materialized'], 'view') + self.assertEqual(results[0].node['config']['materialized'], 'view') self.assertEqual(len(results), 1) @use_profile('presto') @@ -83,13 +83,13 @@ def test__presto__switch_materialization(self): # presto can't do incremental materializations so there's less to this results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEquals(results[0].node['config']['materialized'], 'view') + self.assertEqual(results[0].node['config']['materialized'], 'view') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: table']) - self.assertEquals(results[0].node['config']['materialized'], 'table') + self.assertEqual(results[0].node['config']['materialized'], 'table') self.assertEqual(len(results), 1) results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEquals(results[0].node['config']['materialized'], 'view') + self.assertEqual(results[0].node['config']['materialized'], 'view') self.assertEqual(len(results), 1) diff --git a/test/integration/037_external_reference_test/test_external_reference.py b/test/integration/037_external_reference_test/test_external_reference.py index c7be5cdb4aa..22ff8424dcd 100644 --- a/test/integration/037_external_reference_test/test_external_reference.py +++ b/test/integration/037_external_reference_test/test_external_reference.py @@ -35,9 +35,9 @@ def tearDown(self): @use_profile('postgres') def test__postgres__external_reference(self): - self.assertEquals(len(self.run_dbt()), 1) + self.assertEqual(len(self.run_dbt()), 1) # running it again should succeed - self.assertEquals(len(self.run_dbt()), 1) + self.assertEqual(len(self.run_dbt()), 1) # The opposite of the test above -- check that external relations that @@ -61,7 +61,7 @@ def tearDown(self): @use_profile('postgres') def test__postgres__external_reference(self): - self.assertEquals(len(self.run_dbt()), 1) + self.assertEqual(len(self.run_dbt()), 1) # create a view outside of the dbt schema that depends on this model self.external_schema = self.unique_schema()+'zz' @@ -74,5 +74,5 @@ def test__postgres__external_reference(self): ) # running it again should succeed - self.assertEquals(len(self.run_dbt()), 1) + self.assertEqual(len(self.run_dbt()), 1) diff --git a/test/integration/base.py b/test/integration/base.py index 0ddd045136f..81bc2ba8ddb 100644 --- a/test/integration/base.py +++ b/test/integration/base.py @@ -1035,7 +1035,7 @@ def _assertTableRowCountsEqual(self, relation_a, relation_b): res = self.run_sql(cmp_query, fetch='one') - self.assertEquals(int(res[0]), 0, "Row count of table {} doesn't match row count of table {}. ({} rows different)".format( + self.assertEqual(int(res[0]), 0, "Row count of table {} doesn't match row count of table {}. ({} rows different)".format( relation_a.identifier, relation_b.identifier, res[0] @@ -1045,7 +1045,7 @@ def _assertTableRowCountsEqual(self, relation_a, relation_b): def assertTableDoesNotExist(self, table, schema=None): columns = self.get_table_columns(table, schema) - self.assertEquals( + self.assertEqual( len(columns), 0 )