Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDL-14448 Numbertype falls to string for boolean values #73

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tap_google_sheets/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ def transform_sheet_decimal_data(value, sheet_title, col_name, col_letter, row_n

# transform number values in the sheet
def transform_sheet_number_data(value, sheet_title, col_name, col_letter, row_num, col_type):
if isinstance(value, int):
if type(value) == int:
return int(value)
elif isinstance(value, float):
elif type(value) == float:
return transform_sheet_decimal_data(value, sheet_title, col_name, col_letter, row_num, col_type)
else:
LOGGER.info('WARNING: POSSIBLE DATA TYPE ERROR: SHEET: {}, COL: {}, CELL: {}{}, TYPE: {}'.format(
LOGGER.info('WARNING: POSSIBLE DATA TYPE ERROR: SHEET: {}, COL: {}, CELL: {}{}, TYPE: {} '.format(
sheet_title, col_name, col_letter, row_num, col_type))
return str(value)

Expand Down
9 changes: 2 additions & 7 deletions tests/test_google_sheets_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_run(self):

test_sheet = 'sad-sheet-effective-format'
data_type_map = {
"Currency": "numberType",
"Currency": "stringValue",
"Datetime": "numberType.DATE_TIME",
"Time": "numberType.TIME",
"Date": "numberType.DATE",
Expand Down Expand Up @@ -275,13 +275,8 @@ def test_run(self):
# As "'0" returns false which does not satisfy th below test case for boolean column
elif value is not None or value != "":

# BUG_TDL-14448 | https://jira.talendforge.org/browse/TDL-14448
# Skipping Number and Currency columns with boolean values because they do not fallback to string
if test_case == 'boolean' and column in {'Currency', 'Number'}: # BUG_TDL-14448
continue # skip

# BUG_TDL-14449 | https://jira.talendforge.org/browse/TDL-14449
elif test_case in {'date', 'time', 'datetime'} and column in {'Currency', 'Number'}: # BUG_TDL-14449
if test_case in {'date', 'time', 'datetime'} and column in {'Currency', 'Number'}: # BUG_TDL-14449
continue # skip

if column == 'Boolean' and value in (-1, 1, 0): # special integer values falls back to boolean
Expand Down
25 changes: 25 additions & 0 deletions tests/unittests/test_number_transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
from tap_google_sheets.transform import transform_sheet_number_data

class TestNumberTransform(unittest.TestCase):
"""Verify that boolean values falls back as string"""
def test_number_transform_boolean_as_string(self):
"""Verify that boolean values falls back as string"""
value = True
transformed_data = transform_sheet_number_data(value, sheet_title='test-sheet', col_name='test-column', col_letter='col', row_num=1, col_type='numberType')
self.assertIsInstance(transformed_data, str)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add an assertion for the value of transformed_data in all unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the assertion

self.assertEqual(transformed_data, "True")

def test_number_transform_int_value_as_int(self):
"""Verify that int values falls back as type int"""
value = 1
transformed_data = transform_sheet_number_data(value, sheet_title='test-sheet', col_name='test-column', col_letter='col', row_num=1, col_type='numberType')
self.assertIsInstance(transformed_data, int)
self.assertEqual(transformed_data, 1)

def test_number_transform_float_value_as_float(self):
"""Verify that float values falls back as type float"""
value = 1.0
transformed_data = transform_sheet_number_data(value, sheet_title='test-sheet', col_name='test-column', col_letter='col', row_num=1, col_type='numberType')
self.assertIsInstance(transformed_data, float)
self.assertEqual(transformed_data, 1.0)