Skip to content

Commit

Permalink
adds test for _df2pg_schema
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-esch committed Aug 3, 2017
1 parent 3d8bd8f commit 869b25e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/test_context.py
Expand Up @@ -196,9 +196,27 @@ def test_query(self):
set(df.columns),
msg='Should have the columns requested')

def test_df2pg_schema(self):
"""cartoframes._df2pg_schema"""
from cartoframes.context import _df2pg_schema
data = [{'id': 'a', 'val': 1.1, 'truth': True, 'idnum': 1},
{'id': 'b', 'val': 2.2, 'truth': True, 'idnum': 2},
{'id': 'c', 'val': 3.3, 'truth': False, 'idnum': 3}]
df = pd.DataFrame(data).astype({'id': 'object',
'val': float,
'truth': bool,
'idnum': int})
# specify order of columns
df = df[['id', 'val', 'truth', 'idnum']]
ans = ('NULLIF("id", \'\')::text AS id, '
'NULLIF("val", \'\')::numeric AS val, '
'NULLIF("truth", \'\')::boolean AS truth, '
'NULLIF("idnum", \'\')::numeric AS idnum')

self.assertEqual(ans, _df2pg_schema(df))

def test_drop_tables_query(self):
"""cartoframes.CartoContext._drop_tables_query"""
"""cartoframes._drop_tables_query"""
from cartoframes.context import _drop_tables_query
tables = ['table1', 'table2', 'table3']
ans = ('DROP TABLE IF EXISTS table1;\n'
Expand Down

0 comments on commit 869b25e

Please sign in to comment.