Skip to content

Commit 22540a7

Browse files
committed
Update tests
1 parent a83d1d6 commit 22540a7

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed
56.8 KB
Binary file not shown.

tests/processors/test_dump_to_s3.py

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,20 @@ def test_large_dump_s3():
298298
server = ThreadedMotoServer()
299299
server.start()
300300
os.environ["LAMINAR_S3_HOST"] = "http://localhost:5000"
301-
301+
302302
# Disable checksum validation to fix moto compatibility issues
303303
# Monkey patch the checksum validation to avoid moto checksum mismatch
304304
import botocore.httpchecksum
305+
305306
original_validate = botocore.httpchecksum.StreamingChecksumBody._validate_checksum
307+
306308
def mock_validate_checksum(self):
307309
pass # Skip checksum validation for moto
308-
botocore.httpchecksum.StreamingChecksumBody._validate_checksum = mock_validate_checksum
309-
310+
311+
botocore.httpchecksum.StreamingChecksumBody._validate_checksum = (
312+
mock_validate_checksum
313+
)
314+
310315
try:
311316
# create bucket and put objects
312317
conn = boto3.client("s3", endpoint_url="http://localhost:5000")
@@ -356,5 +361,70 @@ def mock_validate_checksum(self):
356361
assert datapackage.descriptor["count_of_rows"] == num_rows
357362
finally:
358363
# Restore original checksum validation
359-
botocore.httpchecksum.StreamingChecksumBody._validate_checksum = original_validate
364+
botocore.httpchecksum.StreamingChecksumBody._validate_checksum = (
365+
original_validate
366+
)
360367
server.stop()
368+
369+
370+
@mock_aws
371+
@pytest.mark.skipif(TEST_DEV, reason="test development")
372+
def test_dump_xlsx_rounding():
373+
server = ThreadedMotoServer()
374+
server.start()
375+
os.environ["LAMINAR_S3_HOST"] = "http://localhost:5000"
376+
# create bucket and put objects
377+
conn = boto3.client("s3", endpoint_url="http://localhost:5000")
378+
conn.create_bucket(Bucket="testing_bucket")
379+
conn.create_bucket(Bucket="testing_dump_bucket")
380+
conn.upload_file(
381+
"data/test_floating_point_error2.xlsx",
382+
"testing_bucket",
383+
"test_floating_point_error2.xlsx",
384+
)
385+
386+
flows = [
387+
load(
388+
{
389+
"from": "s3://testing_bucket/test_floating_point_error2.xlsx",
390+
"name": "res",
391+
"format": "xlsx",
392+
"sheet": 1,
393+
"preserve_formatting": True,
394+
"adjust_floating_point_error": True,
395+
"infer_strategy": "strings",
396+
"cast_strategy": "strings",
397+
}
398+
),
399+
dump_to_s3(
400+
{
401+
"prefix": "test",
402+
"force-format": True,
403+
"format": "csv",
404+
"save_pipeline_spec": True,
405+
"temporal_format_property": "outputFormat",
406+
"bucket_name": "testing_dump_bucket",
407+
"data_manager": "test",
408+
}
409+
),
410+
]
411+
412+
rows, datapackage, _ = Flow(*flows).results()
413+
body = (
414+
conn.get_object(Bucket="testing_dump_bucket", Key="test/res.csv")["Body"]
415+
.read()
416+
.decode("utf-8")
417+
)
418+
419+
assert len(body)
420+
assert len(datapackage.resources) == 1
421+
csv_file = io.StringIO(body)
422+
reader = csv.reader(csv_file)
423+
dumped_rows = []
424+
for row in reader:
425+
dumped_rows.append(row)
426+
427+
# print(dumped_rows)
428+
assert dumped_rows[34][15] == rows[0][33]["ChlaYSI"]
429+
assert dumped_rows[34][15] == "1.23"
430+
server.stop()

tests/processors/test_load.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ def test_load_csv_multiline_header():
692692
assert datapackage.resources[0].schema.fields[0].name == "1;5"
693693
assert datapackage.resources[0].schema.fields[2].name == "3;3"
694694

695+
695696
@pytest.mark.skipif(TEST_DEV, reason="test development")
696697
def test_floating_point_error():
697698
flows = [
@@ -701,6 +702,7 @@ def test_floating_point_error():
701702
"name": "res",
702703
"format": "xlsx",
703704
"sheet": 1,
705+
"adjust_floating_point_error": True,
704706
"preserve_formatting": True,
705707
"infer_strategy": "strings",
706708
"cast_strategy": "strings",
@@ -712,3 +714,24 @@ def test_floating_point_error():
712714
assert len(rows) == 1
713715
assert str(rows[0][6]["Temp"]) == "23.5"
714716

717+
718+
@pytest.mark.skipif(TEST_DEV, reason="test development")
719+
def test_floating_point_error_2():
720+
flows = [
721+
load(
722+
{
723+
"from": "data/test_floating_point_error2.xlsx",
724+
"name": "res",
725+
"format": "xlsx",
726+
"sheet": 1,
727+
"adjust_floating_point_error": True,
728+
"preserve_formatting": True,
729+
"infer_strategy": "strings",
730+
"cast_strategy": "strings",
731+
}
732+
)
733+
]
734+
rows, datapackage, _ = Flow(*flows).results()
735+
736+
assert len(rows) == 1
737+
assert str(rows[0][33]["ChlaYSI"]) == "1.23"

0 commit comments

Comments
 (0)