Skip to content

Commit 6c299f3

Browse files
committed
update tests, add error handling
1 parent fbf87e9 commit 6c299f3

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.1.0"
55

66
[deps]
77
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
8+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
89
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
910
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
1011

src/Cclib.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Cclib
22
using PythonCall
33
using CondaPkg
4+
using Logging
45

56
include("functions.jl")
67
include("config.jl")

src/functions.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
export ccread
22

3-
43
function pyccread(file)
54
data = cclib[].io.ccread(file)
65
keys = pyconvert(Array, data.__dict__.keys())
76
values = pyconvert(Array, data.__dict__.values())
87
return Dict(zip(keys, values))
98
end
109

11-
function ccread(pydict)
12-
datadict = pyccread(pydict)
10+
function get_data(file)
11+
datadict = pyccread(file)
1312
for (key, value) in datadict
1413
type = cclibtypes[key]
1514
datadict[key] = pyconvert(type, value)
1615
end
1716
return datadict
18-
end
17+
end
18+
19+
function ccread(file)
20+
try
21+
if !isfile(file)
22+
@error "$(file) is not file"
23+
return nothing
24+
end
25+
data = get_data(file)
26+
return data
27+
catch e
28+
if isa(e, PythonCall.PyException)
29+
@error "Unsupported file format"
30+
return nothing
31+
end
32+
end
33+
end

test/data/invalid_file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test invalid file

test/runtests.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using Cclib
2+
using PythonCall
23
using Test
34

45

56
@testset "Cclib.jl" begin
67

7-
# Start with something simple
8+
# Check that input is read correctly
89
@test ccread("./data/uracil_two.xyz")["natom"] == 12
910
@test ccread("./data/uracil_two.xyz")["atomnos"] == [7, 6, 1, 8, 7, 6, 8, 6, 6, 1, 1, 1]
1011
@test ccread("./data/uracil_two.xyz")["atomcoords"] == [5.435 4.091 6.109 3.647 3.253 3.636 2.79 5.065 5.906 2.243 5.448 7.003;
@@ -13,4 +14,8 @@ using Test
1314
3.24732 3.26356 3.354 3.39863 3.11963 2.96568 2.83961 2.95832 3.09904 3.12801 2.83814 3.10206;;;
1415
-0.916 -0.635 -0.144 0.495 -1.717 -3.039 -3.923 -3.239 -2.202 -1.514 -4.258 -2.345;
1516
-0.9432 -0.64127 -0.15563 0.50851 -1.70419 -3.0054 -3.9297 -3.25044 -2.21101 -1.51035 -4.27067 -2.32366]
17+
18+
# Check that it handles unsupported files correctly
19+
@test isnothing(ccread("./data/invalid_file.txt"))
20+
@test isnothing(ccread("./data/"))
1621
end

0 commit comments

Comments
 (0)