1
1
import os
2
- import unittest
3
- from parsons import Postgres , DBSync , Table , Redshift
4
- from parsons .databases .database_connector import DatabaseConnector
5
2
import tempfile
6
- from parsons . databases . sqlite import Sqlite
3
+ import unittest
7
4
from abc import ABC
8
5
from typing import Optional , Type
9
6
10
7
from parsons import DBSync , Postgres , Redshift , Table
11
8
from parsons .databases .database_connector import DatabaseConnector
9
+ from parsons .databases .sqlite import Sqlite
12
10
from test .test_databases .fakes import FakeDatabase
13
11
from test .utils import assert_matching_tables
14
12
@@ -46,9 +44,7 @@ def setUp(self):
46
44
f"{ self .temp_schema } .source_table" if self .temp_schema else "source_table"
47
45
)
48
46
self .destination_table = (
49
- f"{ self .temp_schema } .destination_table"
50
- if self .temp_schema
51
- else "destination_table"
47
+ f"{ self .temp_schema } .destination_table" if self .temp_schema else "destination_table"
52
48
)
53
49
54
50
# Create source table
@@ -71,9 +67,7 @@ def tearDown(self):
71
67
72
68
def assert_matching_tables (self ) -> None :
73
69
source = self .source_db .query (f"SELECT * FROM { self .source_table } " )
74
- destination = self .destination_db .query (
75
- f"SELECT * FROM { self .destination_table } "
76
- )
70
+ destination = self .destination_db .query (f"SELECT * FROM { self .destination_table } " )
77
71
assert_matching_tables (source , destination )
78
72
79
73
def table_sync_full (self , if_exists : str , ** kwargs ):
@@ -109,19 +103,15 @@ def test_table_sync_full_empty_table(self):
109
103
def test_table_sync_full_chunk (self ):
110
104
# Test chunking in full sync.
111
105
self .db_sync .chunk_size = 10
112
- self .db_sync .table_sync_full (
113
- self .source_table , self .destination_table , if_exists = "drop"
114
- )
106
+ self .db_sync .table_sync_full (self .source_table , self .destination_table , if_exists = "drop" )
115
107
self .assert_matching_tables ()
116
108
117
109
def test_table_sync_incremental (self ):
118
110
# Test that incremental sync
119
111
120
112
self .destination_db .copy (self .table1 , self .destination_table )
121
113
self .source_db .copy (self .table2 , self .source_table , if_exists = "append" )
122
- self .db_sync .table_sync_incremental (
123
- self .source_table , self .destination_table , "pk"
124
- )
114
+ self .db_sync .table_sync_incremental (self .source_table , self .destination_table , "pk" )
125
115
self .assert_matching_tables ()
126
116
127
117
def test_table_sync_incremental_chunk (self ):
@@ -130,17 +120,13 @@ def test_table_sync_incremental_chunk(self):
130
120
self .db_sync .chunk_size = 10
131
121
self .destination_db .copy (self .table1 , self .destination_table )
132
122
self .source_db .copy (self .table2 , self .source_table , if_exists = "append" )
133
- self .db_sync .table_sync_incremental (
134
- self .source_table , self .destination_table , "pk"
135
- )
123
+ self .db_sync .table_sync_incremental (self .source_table , self .destination_table , "pk" )
136
124
137
125
self .assert_matching_tables ()
138
126
139
127
def test_table_sync_incremental_create_destination_table (self ):
140
128
# Test that an incremental sync works if the destination table does not exist.
141
- self .db_sync .table_sync_incremental (
142
- self .source_table , self .destination_table , "pk"
143
- )
129
+ self .db_sync .table_sync_incremental (self .source_table , self .destination_table , "pk" )
144
130
self .assert_matching_tables ()
145
131
146
132
def test_table_sync_incremental_empty_table (self ):
@@ -210,9 +196,7 @@ def initialize_db_connections(self) -> None:
210
196
211
197
# These tests interact directly with the Postgres database. In order to run, set the
212
198
# env to LIVE_TEST='TRUE'.
213
- @unittest .skipIf (
214
- not os .environ .get ("LIVE_TEST" ), "Skipping because not running live test"
215
- )
199
+ @unittest .skipIf (not os .environ .get ("LIVE_TEST" ), "Skipping because not running live test" )
216
200
class TestPostgresDBSync (TestDBSync ):
217
201
db = Postgres
218
202
setup_sql = f"""
@@ -226,8 +210,6 @@ class TestPostgresDBSync(TestDBSync):
226
210
227
211
# These tests interact directly with the Postgres database. In order to run, set the
228
212
# env to LIVE_TEST='TRUE'.
229
- @unittest .skipIf (
230
- not os .environ .get ("LIVE_TEST" ), "Skipping because not running live test"
231
- )
213
+ @unittest .skipIf (not os .environ .get ("LIVE_TEST" ), "Skipping because not running live test" )
232
214
class TestRedshiftDBSync (TestPostgresDBSync ):
233
215
db = Redshift
0 commit comments