mirror of
https://github.com/enso-org/enso.git
synced 2024-11-23 08:08:34 +03:00
Additional tests for Excel Append (#3580)
Add some additional scenarios to Excel append tests: - Non-A1 start - Name duplication - Hitting another range # Important Notes Also fixed a warning in the Image library.
This commit is contained in:
parent
73e9240a11
commit
e41936f436
@ -38,7 +38,7 @@ read location flags=[] =
|
|||||||
if flags.is_empty then Java_Codecs.READ_FLAG_EMPTY else
|
if flags.is_empty then Java_Codecs.READ_FLAG_EMPTY else
|
||||||
flags.map .to_integer . reduce (_.bit_or _)
|
flags.map .to_integer . reduce (_.bit_or _)
|
||||||
_ -> flags.to_integer
|
_ -> flags.to_integer
|
||||||
Panic.catch_java Any (Image.Image (Java_Codecs.read path read_flags)) java_exception->
|
Panic.catch_java Any (Image.Image (Java_Codecs.read path read_flags)) _->
|
||||||
Error.throw (File.Io_Error (File.new path) 'Failed to read the file')
|
Error.throw (File.Io_Error (File.new path) 'Failed to read the file')
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
@ -69,7 +69,7 @@ Image.Image.write location flags=[] =
|
|||||||
Vector.Vector _ -> flags
|
Vector.Vector _ -> flags
|
||||||
_ -> [flags]
|
_ -> [flags]
|
||||||
int_flags = Internal.mat_of_int (write_flags.flat_map x-> [x.to_integer, x.value])
|
int_flags = Internal.mat_of_int (write_flags.flat_map x-> [x.to_integer, x.value])
|
||||||
Panic.catch_java Any (Java_Codecs.write path self.opencv_mat int_flags) java_exception->
|
Panic.catch_java Any (Java_Codecs.write path self.opencv_mat int_flags) _->
|
||||||
Error.throw (File.Io_Error (File.new path) 'Failed to write to the file')
|
Error.throw (File.Io_Error (File.new path) 'Failed to write to the file')
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
@ -21,6 +21,7 @@ import org.enso.table.excel.ExcelRange;
|
|||||||
import org.enso.table.excel.ExcelRow;
|
import org.enso.table.excel.ExcelRow;
|
||||||
import org.enso.table.excel.ExcelSheet;
|
import org.enso.table.excel.ExcelSheet;
|
||||||
import org.enso.table.util.ColumnMapper;
|
import org.enso.table.util.ColumnMapper;
|
||||||
|
import org.enso.table.util.NameDeduplicator;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -158,7 +159,7 @@ public class ExcelWriter {
|
|||||||
throw new IllegalArgumentException("Cannot append by name when headers are not present in the existing data.");
|
throw new IllegalArgumentException("Cannot append by name when headers are not present in the existing data.");
|
||||||
}
|
}
|
||||||
String[] currentHeaders = sheet.get(expanded.getTopRow()).getCellsAsText(expanded.getLeftColumn(), expanded.getRightColumn());
|
String[] currentHeaders = sheet.get(expanded.getTopRow()).getCellsAsText(expanded.getLeftColumn(), expanded.getRightColumn());
|
||||||
yield ColumnMapper.mapColumnsByName(table, currentHeaders);
|
yield ColumnMapper.mapColumnsByName(table, new NameDeduplicator().makeUnique(currentHeaders));
|
||||||
}
|
}
|
||||||
default ->
|
default ->
|
||||||
throw new IllegalArgumentException("Internal Error: appendRangeWithTable called with illegal existing data mode '" + existingDataMode + "'.");
|
throw new IllegalArgumentException("Internal Error: appendRangeWithTable called with illegal existing data mode '" + existingDataMode + "'.");
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -251,8 +251,8 @@ spec_write suffix test_sheet_name =
|
|||||||
Test.specify 'should be able to append to a range by name' <|
|
Test.specify 'should be able to append to a range by name' <|
|
||||||
out.delete_if_exists
|
out.delete_if_exists
|
||||||
(enso_project.data / test_sheet_name) . copy_to out
|
(enso_project.data / test_sheet_name) . copy_to out
|
||||||
extra_another = Table.new [['AA', ['d', 'e']], ['BB',[4, 5]], ['CC',[True, False]], ['DD', ['2022-01-20', '2022-01-21']]]
|
extra_another = Table.new [['AA', ['d', 'e']], ['BB', [4, 5]], ['CC', [True, False]], ['DD', ['2022-01-20', '2022-01-21']]]
|
||||||
expected = Table.new [['AA', ['a','b','c','d', 'e']], ['BB',[1,2,3,4,5]], ['CC',[True, False, False, True, False]]]
|
expected = Table.new [['AA', ['a', 'b', 'c', 'd', 'e']], ['BB', [1, 2, 3, 4, 5]], ['CC', [True, False, False, True, False]]]
|
||||||
extra_another.write out (File_Format.Excel (Cell_Range "Another!A1:D6")) on_existing_file=Existing_File_Behavior.Append
|
extra_another.write out (File_Format.Excel (Cell_Range "Another!A1:D6")) on_existing_file=Existing_File_Behavior.Append
|
||||||
written = out.read (File_Format.Excel (Sheet "Another")) . select_columns (By_Index [0, 1, 2])
|
written = out.read (File_Format.Excel (Sheet "Another")) . select_columns (By_Index [0, 1, 2])
|
||||||
written.should_equal expected
|
written.should_equal expected
|
||||||
@ -268,6 +268,36 @@ spec_write suffix test_sheet_name =
|
|||||||
written.should_equal expected
|
written.should_equal expected
|
||||||
out.delete_if_exists
|
out.delete_if_exists
|
||||||
|
|
||||||
|
Test.specify 'should be able to append to a range by name not in top left' <|
|
||||||
|
out.delete_if_exists
|
||||||
|
(enso_project.data / test_sheet_name) . copy_to out
|
||||||
|
extra_another = Table.new [['AA', ['d', 'e']], ['BB',[4, 5]], ['CC',[True, False]], ['DD', ['2022-01-20', '2022-01-21']]]
|
||||||
|
expected = Table.new [['AA', ['f', 'g', 'h', 'd', 'e']], ['BB',[1, 2, 3, 4, 5]], ['CC',[True, False, False, True, False]]]
|
||||||
|
extra_another.write out (File_Format.Excel (Cell_Range "Random!K9")) on_existing_file=Existing_File_Behavior.Append
|
||||||
|
written = out.read (File_Format.Excel (Cell_Range "Random!K9")) . select_columns (By_Index [0, 1, 2])
|
||||||
|
written.should_equal expected
|
||||||
|
out.delete_if_exists
|
||||||
|
|
||||||
|
Test.specify 'should be able to append to a range by name after deduplication of names' <|
|
||||||
|
out.delete_if_exists
|
||||||
|
(enso_project.data / test_sheet_name) . copy_to out
|
||||||
|
extra_another = Table.new [['AA', ['d', 'e']], ['BB',[4, 5]], ['AA_1',[True, False]], ['BB_1', ['2022-01-20', '2022-01-21']]]
|
||||||
|
expected = Table.new [['AA', ['f', 'g', 'h', 'd', 'e']], ['BB',[1, 2, 3, 4, 5]], ['AA_1',[True, False, False, True, False]]]
|
||||||
|
extra_another.write out (File_Format.Excel (Cell_Range "Random!S3")) on_existing_file=Existing_File_Behavior.Append
|
||||||
|
written = out.read (File_Format.Excel (Cell_Range "Random!S3")) . select_columns (By_Index [0, 1, 2])
|
||||||
|
written.should_equal expected
|
||||||
|
out.delete_if_exists
|
||||||
|
|
||||||
|
Test.specify 'should be able to append to a range by position not in top left' <|
|
||||||
|
out.delete_if_exists
|
||||||
|
(enso_project.data / test_sheet_name) . copy_to out
|
||||||
|
extra_another = Table.new [['A', ['d', 'e']], ['B',[4, 5]], ['C',[True, False]], ['D', ['2022-01-20', '2022-01-21']]]
|
||||||
|
expected = Table.new [['AA', ['f', 'g', 'h', 'd', 'e']], ['BB',[1, 2, 3, 4, 5]], ['CC',[True, False, False, True, False]]]
|
||||||
|
extra_another.write out (File_Format.Excel (Cell_Range "Random!K9")) on_existing_file=Existing_File_Behavior.Append match_columns=Match_Columns.By_Position
|
||||||
|
written = out.read (File_Format.Excel (Cell_Range "Random!K9")) . select_columns (By_Index [0, 1, 2])
|
||||||
|
written.should_equal expected
|
||||||
|
out.delete_if_exists
|
||||||
|
|
||||||
Test.specify 'should be able to append to a range by name out of order' <|
|
Test.specify 'should be able to append to a range by name out of order' <|
|
||||||
out.delete_if_exists
|
out.delete_if_exists
|
||||||
(enso_project.data / test_sheet_name) . copy_to out
|
(enso_project.data / test_sheet_name) . copy_to out
|
||||||
@ -331,6 +361,15 @@ spec_write suffix test_sheet_name =
|
|||||||
out.last_modified_time.should_equal lmd
|
out.last_modified_time.should_equal lmd
|
||||||
out.delete_if_exists
|
out.delete_if_exists
|
||||||
|
|
||||||
|
Test.specify 'should fail to append to a range by name if it hits another table' <|
|
||||||
|
out.delete_if_exists
|
||||||
|
(enso_project.data / test_sheet_name) . copy_to out
|
||||||
|
lmd = out.last_modified_time
|
||||||
|
extra_another = Table.new [['AA', ['d', 'e']], ['BB',[4, 5]], ['CC',[True, False]], ['DD', ['2022-01-20', '2022-01-21']]]
|
||||||
|
extra_another.write out (File_Format.Excel (Cell_Range "Random!B3")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Existing_Data
|
||||||
|
out.last_modified_time.should_equal lmd
|
||||||
|
out.delete_if_exists
|
||||||
|
|
||||||
out.delete_if_exists
|
out.delete_if_exists
|
||||||
out_bak.delete_if_exists
|
out_bak.delete_if_exists
|
||||||
|
|
||||||
@ -466,7 +505,7 @@ spec =
|
|||||||
check_table <| File.read xls_path File_Format.Excel
|
check_table <| File.read xls_path File_Format.Excel
|
||||||
|
|
||||||
Test.specify "should let you read the sheet names" <|
|
Test.specify "should let you read the sheet names" <|
|
||||||
sheet_names = ["Sheet1", "Another", "NoHeaders"]
|
sheet_names = ["Sheet1", "Another", "NoHeaders", "Random"]
|
||||||
xlsx_sheet.read (File_Format.Excel Sheet_Names) . should_equal sheet_names
|
xlsx_sheet.read (File_Format.Excel Sheet_Names) . should_equal sheet_names
|
||||||
xls_sheet.read (File_Format.Excel Sheet_Names) . should_equal sheet_names
|
xls_sheet.read (File_Format.Excel Sheet_Names) . should_equal sheet_names
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user