|
1 | 1 | @testitem "ExcelReaders" begin |
2 | 2 | using Dates, PyCall, DataValues |
3 | 3 |
|
4 | | -# TODO Throw julia specific exceptions for these errors |
| 4 | + # TODO Throw julia specific exceptions for these errors |
5 | 5 | @test_throws PyCall.PyError openxl("FileThatDoesNotExist.xls") |
6 | 6 | @test_throws PyCall.PyError openxl("runtests.jl") |
7 | 7 |
|
|
10 | 10 | @test file.filename == "TestData.xls" |
11 | 11 |
|
12 | 12 | buffer = IOBuffer() |
13 | | - |
| 13 | + |
14 | 14 | @test sprint(show, file) == "ExcelFile <TestData.xls>" |
15 | 15 |
|
16 | 16 | for (k, v) in Dict(0 => "#NULL!", 7 => "#DIV/0!", 23 => "#REF!", 42 => "#N/A", 29 => "#NAME?", 36 => "#NUM!", 15 => "#VALUE!") |
17 | 17 | errorcell = ExcelErrorCell(k) |
18 | 18 | @test sprint(show, errorcell) == v |
19 | 19 | end |
20 | 20 |
|
21 | | -# Read into DataValueArray |
| 21 | + # Read into DataValueArray |
22 | 22 | for f in [file, filename] |
23 | 23 | @test_throws ErrorException readxl(f, "Sheet1!C4:G3") |
24 | 24 | @test_throws ErrorException readxl(f, "Sheet1!G2:B5") |
25 | 25 | @test_throws ErrorException readxl(f, "Sheet1!G5:B2") |
26 | 26 |
|
27 | 27 | data = readxl(f, "Sheet1!C3:N7") |
28 | 28 | @test size(data) == (5, 12) |
29 | | - @test data[4,1] == 2.0 |
30 | | - @test data[2,2] == "A" |
31 | | - @test data[2,3] == true |
32 | | - @test DataValues.isna(data[4,5]) |
33 | | - @test data[2,9] == Date(2015, 3, 3) |
34 | | - @test data[3,9] == DateTime(2015, 2, 4, 10, 14) |
35 | | - @test data[4,9] == DateTime(1988, 4, 9, 0, 0) |
36 | | - @test data[5,9] == Time(15, 2, 0) |
37 | | - @test data[3,10] == DateTime(1950, 8, 9, 18, 40) |
38 | | - @test DataValues.isna(data[5,10]) |
39 | | - @test isa(data[2,11], ExcelErrorCell) |
40 | | - @test isa(data[3,11], ExcelErrorCell) |
41 | | - @test isa(data[4,12], ExcelErrorCell) |
42 | | - @test DataValues.isna(data[5,12]) |
43 | | - |
44 | | - # Test readxlsheet function |
| 29 | + @test data[4, 1] == 2.0 |
| 30 | + @test data[2, 2] == "A" |
| 31 | + @test data[2, 3] == true |
| 32 | + @test DataValues.isna(data[4, 5]) |
| 33 | + @test data[2, 9] == Date(2015, 3, 3) |
| 34 | + @test data[3, 9] == DateTime(2015, 2, 4, 10, 14) |
| 35 | + @test data[4, 9] == DateTime(1988, 4, 9, 0, 0) |
| 36 | + @test data[5, 9] == Time(15, 2, 0) |
| 37 | + @test data[3, 10] == DateTime(1950, 8, 9, 18, 40) |
| 38 | + @test DataValues.isna(data[5, 10]) |
| 39 | + @test isa(data[2, 11], ExcelErrorCell) |
| 40 | + @test isa(data[3, 11], ExcelErrorCell) |
| 41 | + @test isa(data[4, 12], ExcelErrorCell) |
| 42 | + @test DataValues.isna(data[5, 12]) |
| 43 | + |
| 44 | + # Test readxlsheet function |
45 | 45 | @test_throws ErrorException readxlsheet(f, "Empty Sheet") |
46 | 46 | for sheetinfo = ["Second Sheet", 2] |
47 | | - @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows = -1) |
48 | | - @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows = :nonsense) |
| 47 | + @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows=-1) |
| 48 | + @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows=:nonsense) |
49 | 49 |
|
50 | | - @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols = -1) |
51 | | - @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols = :nonsense) |
| 50 | + @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols=-1) |
| 51 | + @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols=:nonsense) |
52 | 52 |
|
53 | | - @test_throws ErrorException readxlsheet(f, sheetinfo, nrows = -1) |
54 | | - @test_throws ErrorException readxlsheet(f, sheetinfo, nrows = :nonsense) |
| 53 | + @test_throws ErrorException readxlsheet(f, sheetinfo, nrows=-1) |
| 54 | + @test_throws ErrorException readxlsheet(f, sheetinfo, nrows=:nonsense) |
55 | 55 |
|
56 | | - @test_throws ErrorException readxlsheet(f, sheetinfo, ncols = -1) |
57 | | - @test_throws ErrorException readxlsheet(f, sheetinfo, ncols = :nonsense) |
| 56 | + @test_throws ErrorException readxlsheet(f, sheetinfo, ncols=-1) |
| 57 | + @test_throws ErrorException readxlsheet(f, sheetinfo, ncols=:nonsense) |
58 | 58 |
|
59 | 59 | data = readxlsheet(f, sheetinfo) |
60 | 60 | @test size(data) == (6, 6) |
61 | | - @test data[2,1] == 1. |
62 | | - @test data[5,2] == "CCC" |
63 | | - @test data[3,3] == false |
64 | | - @test data[6,6] == Time(15, 2, 00) |
65 | | - @test DataValues.isna(data[4,3]) |
66 | | - @test DataValues.isna(data[4,6]) |
67 | | - |
68 | | - data = readxlsheet(f, sheetinfo, skipstartrows = :blanks, skipstartcols = :blanks) |
| 61 | + @test data[2, 1] == 1. |
| 62 | + @test data[5, 2] == "CCC" |
| 63 | + @test data[3, 3] == false |
| 64 | + @test data[6, 6] == Time(15, 2, 00) |
| 65 | + @test DataValues.isna(data[4, 3]) |
| 66 | + @test DataValues.isna(data[4, 6]) |
| 67 | + |
| 68 | + data = readxlsheet(f, sheetinfo, skipstartrows=:blanks, skipstartcols=:blanks) |
69 | 69 | @test size(data) == (6, 6) |
70 | | - @test data[2,1] == 1. |
71 | | - @test data[5,2] == "CCC" |
72 | | - @test data[3,3] == false |
73 | | - @test data[6,6] == Time(15, 2, 00) |
74 | | - @test DataValues.isna(data[4,3]) |
75 | | - @test DataValues.isna(data[4,6]) |
76 | | - |
77 | | - data = readxlsheet(f, sheetinfo, skipstartrows = 0, skipstartcols = 0) |
| 70 | + @test data[2, 1] == 1. |
| 71 | + @test data[5, 2] == "CCC" |
| 72 | + @test data[3, 3] == false |
| 73 | + @test data[6, 6] == Time(15, 2, 00) |
| 74 | + @test DataValues.isna(data[4, 3]) |
| 75 | + @test DataValues.isna(data[4, 6]) |
| 76 | + |
| 77 | + data = readxlsheet(f, sheetinfo, skipstartrows=0, skipstartcols=0) |
78 | 78 | @test size(data) == (6 + 7, 6 + 3) |
79 | | - @test data[2 + 7,1 + 3] == 1. |
80 | | - @test data[5 + 7,2 + 3] == "CCC" |
81 | | - @test data[3 + 7,3 + 3] == false |
82 | | - @test data[6 + 7,6 + 3] == Time(15, 2, 00) |
83 | | - @test DataValues.isna(data[4 + 7,3 + 3]) |
84 | | - @test DataValues.isna(data[4 + 7,6 + 3]) |
85 | | - |
86 | | - data = readxlsheet(f, sheetinfo, skipstartrows = 0, ) |
| 79 | + @test data[2+7, 1+3] == 1. |
| 80 | + @test data[5+7, 2+3] == "CCC" |
| 81 | + @test data[3+7, 3+3] == false |
| 82 | + @test data[6+7, 6+3] == Time(15, 2, 00) |
| 83 | + @test DataValues.isna(data[4+7, 3+3]) |
| 84 | + @test DataValues.isna(data[4+7, 6+3]) |
| 85 | + |
| 86 | + data = readxlsheet(f, sheetinfo, skipstartrows=0,) |
87 | 87 | @test size(data) == (6 + 7, 6) |
88 | | - @test data[2 + 7,1] == 1. |
89 | | - @test data[5 + 7,2] == "CCC" |
90 | | - @test data[3 + 7,3] == false |
91 | | - @test data[6 + 7,6] == Time(15, 2, 00) |
92 | | - @test DataValues.isna(data[4 + 7,3]) |
93 | | - @test DataValues.isna(data[4 + 7,6]) |
94 | | - |
95 | | - data = readxlsheet(f, sheetinfo, skipstartcols = 0) |
| 88 | + @test data[2+7, 1] == 1. |
| 89 | + @test data[5+7, 2] == "CCC" |
| 90 | + @test data[3+7, 3] == false |
| 91 | + @test data[6+7, 6] == Time(15, 2, 00) |
| 92 | + @test DataValues.isna(data[4+7, 3]) |
| 93 | + @test DataValues.isna(data[4+7, 6]) |
| 94 | + |
| 95 | + data = readxlsheet(f, sheetinfo, skipstartcols=0) |
96 | 96 | @test size(data) == (6, 6 + 3) |
97 | | - @test data[2,1 + 3] == 1. |
98 | | - @test data[5,2 + 3] == "CCC" |
99 | | - @test data[3,3 + 3] == false |
100 | | - @test data[6,6 + 3] == Time(15, 2, 00) |
101 | | - @test DataValues.isna(data[4,3 + 3]) |
102 | | - @test DataValues.isna(data[4,6 + 3]) |
103 | | - |
104 | | - data = readxlsheet(f, sheetinfo, skipstartrows = 1, skipstartcols = 1, nrows = 11, ncols = 7) |
| 97 | + @test data[2, 1+3] == 1. |
| 98 | + @test data[5, 2+3] == "CCC" |
| 99 | + @test data[3, 3+3] == false |
| 100 | + @test data[6, 6+3] == Time(15, 2, 00) |
| 101 | + @test DataValues.isna(data[4, 3+3]) |
| 102 | + @test DataValues.isna(data[4, 6+3]) |
| 103 | + |
| 104 | + data = readxlsheet(f, sheetinfo, skipstartrows=1, skipstartcols=1, nrows=11, ncols=7) |
105 | 105 | @test size(data) == (11, 7) |
106 | | - @test data[2 + 6,1 + 2] == 1. |
107 | | - @test data[5 + 6,2 + 2] == "CCC" |
108 | | - @test data[3 + 6,3 + 2] == false |
109 | | - @test_throws BoundsError data[6 + 6,6 + 2] == Time(15, 2, 00) |
110 | | - @test DataValues.isna(data[4 + 6,2 + 2]) |
| 106 | + @test data[2+6, 1+2] == 1. |
| 107 | + @test data[5+6, 2+2] == "CCC" |
| 108 | + @test data[3+6, 3+2] == false |
| 109 | + @test_throws BoundsError data[6+6, 6+2] == Time(15, 2, 00) |
| 110 | + @test DataValues.isna(data[4+6, 2+2]) |
111 | 111 | end |
112 | 112 | end |
113 | 113 |
|
|
0 commit comments