Skip to content

Commit

Permalink
Added a test to catch broken output and to ensure smart columns appear.
Browse files Browse the repository at this point in the history
Resolved defect introduced by 280367a
  • Loading branch information
ets committed Mar 8, 2021
1 parent 9ac6f48 commit 84f6b8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tap_spreadsheets_anywhere/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def write_file(target_filename, table_spec, schema, max_records=-1):
}

try:
record_with_meta = [{**conversion.convert_row(row, schema), **metadata}]
record_with_meta = {**conversion.convert_row(row, schema), **metadata}
singer.write_record(table_spec['name'], record_with_meta)
except BrokenPipeError as bpe:
LOGGER.error(
Expand Down
17 changes: 14 additions & 3 deletions tap_spreadsheets_anywhere/test/test_format.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import codecs
import json
import logging
import unittest
from unittest.mock import patch

Expand All @@ -9,6 +11,9 @@
from tap_spreadsheets_anywhere import configuration, file_utils, csv_handler, json_handler, generate_schema
from tap_spreadsheets_anywhere.format_handler import monkey_patch_streamreader, get_row_iterator


LOGGER = logging.getLogger(__name__)

TEST_TABLE_SPEC = {
"tables": [
{
Expand Down Expand Up @@ -137,7 +142,7 @@ def test_strip_newlines_monkey_patch_locally(self):
self.assertTrue(row['id'].isnumeric(), "Parsed ID is not a number for: {}".format(row['id']))

def test_smart_columns(self):
with patch('sys.stdout', new=StringIO()) as fake_out:
with patch('sys.stdout', new_callable=StringIO) as fake_out:
records_streamed = 0
table_spec = TEST_TABLE_SPEC['tables'][7]
modified_since = dateutil.parser.parse(table_spec['start_date'])
Expand All @@ -147,8 +152,14 @@ def test_smart_columns(self):
for t_file in target_files:
records_streamed += file_utils.write_file(t_file['key'], table_spec, schema.to_dict())

self.assertEqual(records_streamed, 6)
#TODO: verify that stdout received record data including smart columns
raw_records = fake_out.getvalue().split('\n')
records = [json.loads(raw) for raw in raw_records if raw]
self.assertEqual(records_streamed, len(records),"Number records written to the pipe differed from records read from the pipe.")
self.assertTrue(records[0]['type'] == "RECORD")
self.assertTrue(len(records[0]) == 3)
self.assertTrue(len(records[0]['record']) == 7)
self.assertTrue( "_smart_source_bucket" in records[0]['record'] )
self.assertTrue("_smart_source_lineno" in records[0]['record'])


def test_local_bucket(self):
Expand Down

0 comments on commit 84f6b8e

Please sign in to comment.