-
Notifications
You must be signed in to change notification settings - Fork 76
Fix parse to properly support multipleOf (to avoid validation error) #179
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from decimal import Decimal | ||
from copy import deepcopy | ||
|
||
import pytest | ||
|
||
from target_postgres import singer | ||
from target_postgres.singer_stream import BufferedSingerStream, SingerStreamError | ||
from target_postgres.singer_stream import BufferedSingerStream, SingerStreamError, RAW_LINE_SIZE | ||
|
||
from utils.fixtures import CatStream, InvalidCatStream, CATS_SCHEMA | ||
|
||
|
@@ -75,6 +76,73 @@ def test_add_record_message__invalid_record(): | |
assert [] == missing_sdc_properties(singer_stream) | ||
|
||
|
||
SIMPLE_MULTIPLE_OF_VALID_SCHEMA = { | ||
'properties': { | ||
'multipleOfKey': { | ||
'type': 'number', | ||
'multipleOf': Decimal('1e-15') | ||
} | ||
} | ||
} | ||
|
||
SIMPLE_MULTIPLE_OF_INVALID_SCHEMA = { | ||
'properties': { | ||
'multipleOfKey': { | ||
'type': 'number', | ||
'multipleOf': 1e-15 | ||
} | ||
} | ||
} | ||
|
||
def test_add_record_message__multipleOf(): | ||
stream_name = 'test' | ||
singer_stream = BufferedSingerStream(stream_name, | ||
deepcopy(SIMPLE_MULTIPLE_OF_VALID_SCHEMA), | ||
[]) | ||
|
||
multiple_of_values = ['1', '2', '3', '4', '5', '1.1', '2.3', '1.23456789', '20', '100.1'] | ||
|
||
for value in multiple_of_values: | ||
singer_stream.add_record_message( | ||
{ | ||
'type': 'RECORD', | ||
'stream': stream_name, | ||
'record': {'multipleOfKey': Decimal(value)}, | ||
'sequence': 0, | ||
RAW_LINE_SIZE: 100 | ||
AlexanderMann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
) | ||
|
||
assert not singer_stream.peek_invalid_records() | ||
assert singer_stream.count == len(multiple_of_values) | ||
assert [] == missing_sdc_properties(singer_stream) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davicorreiajr it's this line, we can remove it same as the other, sorry for the confusion and appreciate your patience! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no worries, fixing now |
||
|
||
|
||
def test_add_record_message__multipleOf_invalid_record(): | ||
stream_name = 'test' | ||
singer_stream = BufferedSingerStream(stream_name, | ||
deepcopy(SIMPLE_MULTIPLE_OF_INVALID_SCHEMA), | ||
[]) | ||
|
||
multiple_of_values = [1, 2] | ||
|
||
for value in multiple_of_values: | ||
with pytest.raises(SingerStreamError): | ||
singer_stream.add_record_message( | ||
{ | ||
'type': 'RECORD', | ||
'stream': stream_name, | ||
'record': {'multipleOfKey': value}, | ||
'sequence': 0, | ||
RAW_LINE_SIZE: 100 | ||
} | ||
) | ||
|
||
assert singer_stream.peek_invalid_records() | ||
assert singer_stream.count == 0 | ||
assert [] == missing_sdc_properties(singer_stream) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can drop this. It's not really adding value to the test overall. |
||
|
||
|
||
SIMPLE_ALLOF_SCHEMA = { | ||
'type': 'object', | ||
'properties': { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import re | ||
import decimal | ||
|
||
import pytest | ||
|
||
|
@@ -31,6 +32,8 @@ def test_python_type(): | |
== json_schema.STRING | ||
assert json_schema.python_type('world') \ | ||
== json_schema.STRING | ||
assert json_schema.python_type(decimal.Decimal(1)) \ | ||
== json_schema.NUMBER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent |
||
|
||
|
||
def test_is_object(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't documented anywhere, so I wouldn't expect you to know this one, but we try to alphabetize our
import
s. The breakdown is: