Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed May 10, 2022
1 parent 47e9806 commit 5570820
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 0 additions & 2 deletions test/Table_Tests/data/utf8_invalid.csv

This file was deleted.

31 changes: 17 additions & 14 deletions test/Table_Tests/src/Delimited_Read_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec =
(path name).write_text text Encoding.utf_8

test_file name =
table = (File_Format.Delimited "," headers=True).read (path name) Problem_Behavior.Report_Error
table = File.read (path name) (File_Format.Delimited "," headers=True) Problem_Behavior.Report_Error
table.columns.map .name . should_equal ['a', 'b', 'c']
table.at 'a' . to_vector . should_equal ['d', '1']
table.at 'b' . to_vector . should_equal ['e', '2']
Expand All @@ -78,25 +78,28 @@ spec =

# Currently mixed line endings are not supported.
(path 'mixed.csv').write_text 'a,b,c\nd,e,f\r1,2,3'
(File_Format.Delimited "," headers=True).read (path 'mixed.csv') Problem_Behavior.Report_Error . should_fail_with Invalid_Row
File.read (path 'mixed.csv') (File_Format.Delimited "," headers=True) Problem_Behavior.Report_Error . should_fail_with Invalid_Row

Test.specify "should work with Windows-1252 encoding" <|
table = (File_Format.Delimited "," headers=True encoding=Encoding.windows_1252).read (Enso_Project.data / "windows.csv") Problem_Behavior.Report_Error
table = File.read (Enso_Project.data / "windows.csv") (File_Format.Delimited "," headers=True encoding=Encoding.windows_1252) Problem_Behavior.Report_Error
table.columns.map .name . should_equal ['a', 'b', 'c']
table.at 'a' . to_vector . should_equal ['$¢']
table.at 'b' . to_vector . should_equal ['¤']
table.at 'c' . to_vector . should_equal ['¥']

Test.specify "should work with UTF-16 encoding" <|
table = (File_Format.Delimited "," headers=True encoding=Encoding.utf_16_be).read (Enso_Project.data / "utf16.csv") Problem_Behavior.Report_Error
table = File.read (Enso_Project.data / "utf16.csv") (File_Format.Delimited "," headers=True encoding=Encoding.utf_16_be) Problem_Behavior.Report_Error
table.columns.map .name . should_equal ['ą', '🚀b', 'ć😎']
table.at 'ą' . to_vector . should_equal ['ą']
table.at '🚀b' . to_vector . should_equal ['✨🚀🚧😍😃😍😎😙😉☺']
table.at 'ć😎' . to_vector . should_equal ['แมวมีสี่ขา']

Test.specify "should report errors when encountering malformed characters" <|
utf8_file = (Enso_Project.data / "transient" / "utf8_invalid.csv")
utf8_bytes = [97, 44, 98, 44, 99, 10, -60, -123, 44, -17, -65, -65, 44, -61, 40, -61, 40, 10]
utf8_file.write_bytes utf8_bytes
action_1 on_problems =
(File_Format.Delimited "," headers=True).read (Enso_Project.data / "utf8_invalid.csv") on_problems
utf8_file.read (File_Format.Delimited "," headers=True) on_problems
tester_1 table =
table.columns.map .name . should_equal ['a', 'b', 'c']
table.at 'a' . to_vector . should_equal ['ą']
Expand All @@ -106,7 +109,7 @@ spec =
Problems.test_problem_handling action_1 problems_1 tester_1

action_2 on_problems =
(File_Format.Delimited "," headers=True encoding=Encoding.utf_16_be).read (Enso_Project.data / "utf16_invalid.csv") on_problems
(Enso_Project.data / "utf16_invalid.csv").read (File_Format.Delimited "," headers=True encoding=Encoding.utf_16_be) on_problems
tester_2 table =
table.columns.map .name . should_equal ['a', 'b', 'c']
# This column does not raise a problem - the '\uFFFD' is simply present in the input file.
Expand Down Expand Up @@ -145,7 +148,7 @@ spec =

Test.specify "should behave correctly in presence of a mismatched quote" <|
action_1 on_problems =
(File_Format.Delimited "," headers=True).read (Enso_Project.data / "mismatched_quote.csv") on_problems
File.read (Enso_Project.data / "mismatched_quote.csv") (File_Format.Delimited "," headers=True) on_problems

tester_1 table =
table.columns.map .name . should_equal ['a', 'b', 'c']
Expand All @@ -156,7 +159,7 @@ spec =
Problems.test_problem_handling action_1 problems_1 tester_1

action_2 on_problems =
(File_Format.Delimited "," headers=True).read (Enso_Project.data / "mismatched_quote2.csv") on_problems
File.read (Enso_Project.data / "mismatched_quote2.csv") (File_Format.Delimited "," headers=True) on_problems

tester_2 table =
table.columns.map .name . should_equal ['a', 'b', 'c']
Expand All @@ -168,7 +171,7 @@ spec =

Test.specify "should handle too long and too short rows" <|
action keep_invalid_rows on_problems =
(File_Format.Delimited "," headers=True keep_invalid_rows=keep_invalid_rows).read (Enso_Project.data / "varying_rows.csv") on_problems
File.read (Enso_Project.data / "varying_rows.csv") (File_Format.Delimited "," headers=True keep_invalid_rows=keep_invalid_rows) on_problems

tester_kept table =
table.columns.map .name . should_equal ['a', 'b', 'c']
Expand All @@ -188,7 +191,7 @@ spec =

Test.specify "should aggregate invalid rows over some limit" <|
action on_problems =
(File_Format.Delimited "," headers=True keep_invalid_rows=False).read (Enso_Project.data / "many_invalid_rows.csv") on_problems
File.read (Enso_Project.data / "many_invalid_rows.csv") (File_Format.Delimited "," headers=True keep_invalid_rows=False) on_problems

tester table =
table.columns.map .name . should_equal ['a', 'b', 'c']
Expand Down Expand Up @@ -231,9 +234,9 @@ spec =
Test.specify "should check arguments" <|
path = (Enso_Project.data / "simple_empty.csv")
pb = Problem_Behavior.Report_Error
(File_Format.Delimited "," headers=False quote='abc').read path pb . should_fail_with Illegal_Argument_Error
(File_Format.Delimited "," headers=False quote='🚧').read path pb . should_fail_with Illegal_Argument_Error
(File_Format.Delimited "," headers=False quote_escape='//').read path pb . should_fail_with Illegal_Argument_Error
(File_Format.Delimited 'a\u{301}' headers=False).read path pb . should_fail_with Illegal_Argument_Error
path.read (File_Format.Delimited "," headers=False quote='abc') pb . should_fail_with Illegal_Argument_Error
path.read (File_Format.Delimited "," headers=False quote='🚧') pb . should_fail_with Illegal_Argument_Error
path.read (File_Format.Delimited "," headers=False quote_escape='//') pb . should_fail_with Illegal_Argument_Error
path.read (File_Format.Delimited 'a\u{301}' headers=False) pb . should_fail_with Illegal_Argument_Error

main = Test.Suite.run_main here.spec

0 comments on commit 5570820

Please sign in to comment.