Skip to content

Commit

Permalink
- Missing imports.
Browse files Browse the repository at this point in the history
- Remove context overrides from tests.
- Add test for `File` operations in context.
  • Loading branch information
jdunkerley committed May 2, 2023
1 parent 9cc71de commit ffba738
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 18 deletions.
6 changes: 3 additions & 3 deletions test/Table_Tests/src/Database/SQLite_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ sqlite_spec connection prefix =
spec =
enso_project.data.create_directory
file = enso_project.data / "sqlite_test.db"
Context.Output.with_enabled <| file.delete_if_exists
file.delete_if_exists
in_file_prefix = "[SQLite File] "
sqlite_spec (Database.connect (SQLite file)) in_file_prefix
Upload_Spec.spec (_ -> Database.connect (SQLite file)) in_file_prefix
Context.Output.with_enabled <| file.delete
file.delete

in_memory_prefix = "[SQLite In-Memory] "
sqlite_spec (Database.connect (SQLite In_Memory)) in_memory_prefix
Upload_Spec.spec (_ -> Database.connect (SQLite In_Memory)) in_memory_prefix persistent_connector=False

SQLite_Type_Mapping_Spec.spec

Test.group "SQLite_Format should allow connecting to SQLite files" <| Context.Output.with_enabled <|
Test.group "SQLite_Format should allow connecting to SQLite files" <|
file.delete_if_exists

connection = Database.connect (SQLite file)
Expand Down
4 changes: 2 additions & 2 deletions test/Table_Tests/src/IO/Csv_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ spec =
res.should_equal expected


Test.specify 'should write CSV to a file' <| Context.Output.with_enabled <|
Test.specify 'should write CSV to a file' <|
varied_column = (enso_project.data / "varied_column.csv") . read
out = enso_project.data / "transient" / "out.csv"
out.delete_if_exists
Expand All @@ -110,7 +110,7 @@ spec =
out.read_text.should_equal exp
out.delete_if_exists

Test.group "Integration" <| Context.Output.with_enabled <|
Test.group "Integration" <|
Test.specify "should be able to round-trip a table with all kinds of weird characters to CSV and back" <|
names = ['Śłąęźż");DROP TABLE Students;--', 'This;Name;;Is""Strange', 'Marcin,,', '\'', 'a\n\nb', 'a\tc', Nothing, Nothing, Nothing, '42', '💁👌🎍😍', '', 'null?\0?', 'FFFD', '\uFFFD', '\r\n', 'a\r\nb\n\rc\rd\ne', 'what about these # ?? // /* hmm */ is it included?', 'and the rare \v vertical tab?']
d = Date_Time.new 2015 10 29 23 55 49
Expand Down
6 changes: 3 additions & 3 deletions test/Table_Tests/src/IO/Delimited_Read_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec =
r2.should_fail_with File_Error
r2.catch.should_be_a File_Error.IO_Error

Test.specify "should work with all kinds of line endings" <| Context.Output.with_enabled <|
Test.specify "should work with all kinds of line endings" <|
path name = enso_project.data / 'transient' / name
create_file name ending_style =
lines = ['a,b,c', 'd,e,f', '1,2,3']
Expand All @@ -130,7 +130,7 @@ spec =

['crlf.csv', 'lf.csv', 'cr.csv', 'mixed.csv'].each (path >> .delete)

Test.specify "should allow to override line endings style" <| Context.Output.with_enabled <|
Test.specify "should allow to override line endings style" <|
file = enso_project.data / "transient" / "lf.csv"
lines = ['a,b,c', 'd,e,f', '1,2,3']
text = lines.join '\n'
Expand Down Expand Up @@ -171,7 +171,7 @@ spec =
table.at '🚀b' . to_vector . should_equal ['✨🚀🚧😍😃😍😎😙😉☺']
table.at 'ć😎' . to_vector . should_equal ['แมวมีสี่ขา']

Test.specify "should report errors when encountering malformed characters" <| Context.Output.with_enabled <|
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_bytes.write_bytes utf8_file
Expand Down
2 changes: 1 addition & 1 deletion test/Table_Tests/src/IO/Delimited_Write_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ join_lines lines trailing_newline=True =

spec =
line_ending_pairs = [[Line_Ending_Style.Unix, '\n'], [Line_Ending_Style.Windows, '\r\n'], [Line_Ending_Style.Mac_Legacy, '\r']]
Test.group "Delimited File Writing" <| Context.Output.with_enabled <|
Test.group "Delimited File Writing" <|
Test.specify "should correctly write a simple table and return the written file object on success" <|
table = Table.new [["A", [1,2,3]], ["B", [1.0,1.5,2.2]], ["C", ["x","y","z"]], ["D", ["a", 2, My_Type.Value 10]]]
file = (enso_project.data / "transient" / "written.csv")
Expand Down
4 changes: 2 additions & 2 deletions test/Table_Tests/src/IO/Excel_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ spec_fmt header file read_method sheet_count=5 =
t_3.at 'C' . to_vector . should_equal [43.2, 54]

spec_write suffix test_sheet_name =
Test.group ("Write " + suffix + " Files") <| Context.Output.with_enabled <|
Test.group ("Write " + suffix + " Files") <|
out = enso_project.data / ('out.' + suffix)
out_bak = enso_project.data / ('out.' + suffix + '.bak')
table = enso_project.data/'varied_column.csv' . read
Expand Down Expand Up @@ -679,7 +679,7 @@ spec =
r2.should_fail_with File_Error
r2.catch.should_be_a File_Error.Corrupted_Format

Test.specify "should handle malformed XLS files gracefully" <| Context.Output.with_enabled <|
Test.specify "should handle malformed XLS files gracefully" <|
bad_file = enso_project.data / "transient" / "malformed.xls"
"not really an XLS file contents...".write bad_file on_existing_file=Existing_File_Behavior.Overwrite

Expand Down
3 changes: 1 addition & 2 deletions test/Table_Tests/src/IO/Formats_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import Standard.Test.Extensions

import project.Util


spec = Test.group 'Various File Format support on Table' <| Context.Output.with_enabled <|
spec = Test.group 'Various File Format support on Table' <|
t1 = Table.new [["X", [1, 2, 3]]]
transient = enso_project.data / "transient"
simple_empty = enso_project.data/'simple_empty.csv' . read
Expand Down
75 changes: 73 additions & 2 deletions test/Tests/src/System/File_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base.Errors.Common.Forbidden_Operation
import Standard.Base.Errors.Encoding_Error.Encoding_Error
import Standard.Base.Errors.File_Error.File_Error
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
Expand All @@ -19,7 +20,7 @@ spec =
windows_file = enso_project.data / "windows.txt"
non_existent_file = File.new "does_not_exist.txt"

Test.group "File Operations" <| Context.Output.with_enabled <|
Test.group "File Operations" <|
Test.specify "should allow creating a new file" <|
path = sample_file.path
File.new path
Expand Down Expand Up @@ -78,6 +79,76 @@ spec =
f.delete
f.exists.should_be_false

Test.specify "should only allow writing a file if Output is enabled" <|
f = enso_project.data / "short.txt"
f.delete_if_exists

byte_vector = "Hello World!".bytes Encoding.utf_8
write_bytes bytes = f.with_output_stream [File_Access.Create, File_Access.Write] stream->
stream.write_bytes bytes
stream.close

write_bytes byte_vector . should_succeed
f.exists.should_be_true
f.delete

Context.Output.with_disabled <|
write_bytes byte_vector . should_fail_with Forbidden_Operation
f.exists.should_be_false

f.delete_if_exists

Test.specify "should only allow deleting a file if Output is enabled" <|
f = enso_project.data / "short.txt"
f.delete_if_exists
"Cup".write f on_existing_file=Existing_File_Behavior.Overwrite

Context.Output.with_disabled <|
f.delete . should_fail_with Forbidden_Operation
f.exists.should_be_true

f.delete.should_succeed
f.exists.should_be_false

Test.specify "should only allow copying a file if Output is enabled" <|
f = enso_project.data / "short.txt"
f.delete_if_exists
"Cup".write f on_existing_file=Existing_File_Behavior.Overwrite

g = enso_project.data / "short_copy.txt"
g.delete_if_exists

f.copy_to g . should_succeed
g.exists.should_be_true
g.delete_if_exists

Context.Output.with_disabled <|
f.copy_to g . should_fail_with Forbidden_Operation
g.exists.should_be_false

f.delete_if_exists
g.delete_if_exists

Test.specify "should only allow moving a file if Output is enabled" <|
f = enso_project.data / "short.txt"
f.delete_if_exists
"Cup".write f on_existing_file=Existing_File_Behavior.Overwrite

g = enso_project.data / "short_copy.txt"
g.delete_if_exists

Context.Output.with_disabled <|
f.move_to g . should_fail_with Forbidden_Operation
f.exists.should_be_true
g.exists.should_be_false

f.move_to g . should_succeed
f.exists.should_be_false
g.exists.should_be_true

f.delete_if_exists
g.delete_if_exists

Test.specify "should handle exceptions when deleting a missing file" <|
file = File.new "does_not_exist.txt"
result = file.delete
Expand Down Expand Up @@ -205,7 +276,7 @@ spec =
contents_2 = Data.read_text file
contents_2.should_start_with "Cupcake ipsum dolor sit amet."

Test.group "write operations" <| Context.Output.with_enabled <|
Test.group "write operations" <|
data = [32, 127, -128, 0]
data_2 = [10, 15, 20, 30]

Expand Down
2 changes: 1 addition & 1 deletion test/Tests/src/System/Reporting_Stream_Decoder_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec =
f.delete
f.exists.should_be_false

Test.specify "should work correctly when reading chunks of varying sizes" <| Context.Output.with_enabled <|
Test.specify "should work correctly when reading chunks of varying sizes" <|
f = enso_project.data / "transient" / "varying_chunks.txt"
fragment = 'Hello 😎🚀🚧!'
contents = 1.up_to 1000 . map _->fragment . join '\n'
Expand Down
2 changes: 1 addition & 1 deletion test/Tests/src/System/Reporting_Stream_Encoder_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from Standard.Test import Test, Test_Suite, Problems
import Standard.Test.Extensions

spec =
Test.group "ReportingStreamEncoder" <| Context.Output.with_enabled <|
Test.group "ReportingStreamEncoder" <|
Test.specify "should allow writing a file codepoint by codepoint" <|
f = enso_project.data / "transient" / "char-by-char.txt"
f.delete_if_exists
Expand Down
2 changes: 1 addition & 1 deletion test/Visualization_Tests/src/Table_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ visualization_spec connection =
Visualization.prepare_visualization Value_Type.Char . should_equal (make_json Value_Type.Char)
Visualization.prepare_visualization Value_Type.Unsupported_Data_Type . should_equal (make_json Value_Type.Unsupported_Data_Type)

spec = Context.Output.with_enabled <|
spec =
enso_project.data.create_directory
file = enso_project.data / "sqlite_test.db"
file.delete_if_exists
Expand Down

0 comments on commit ffba738

Please sign in to comment.