Skip to content

Commit

Permalink
fix 0.7 warnings and 0.6 iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Aug 7, 2018
1 parent f6ff634 commit 74151b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/NCDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1150,15 +1150,15 @@ Base.start(a::NCIterable) = keys(a)
Base.done(a::NCIterable,state) = length(state) == 0
Base.next(a::NCIterable,state) = (state[1] => a[popfirst!(state)], state)


@static if VERSION >= v"0.7.0-beta.0"
function Base.iterate(a::NCIterable, state = keys(a))
if length(state) == 0
return nothing
end

return (state[1] => a[popfirst!(state)], state)
end

end

"""
escape(val)
Expand Down
36 changes: 25 additions & 11 deletions test/test_writevar.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
using NCDatasets
if VERSION >= v"0.7.0-beta.0"
using Test
using Dates
using Printf
else
using Base.Test
end

using Compat

sz = (4,5)
filename = tempname()
#filename = "/tmp/test-9.nc"
Expand Down Expand Up @@ -75,45 +86,49 @@ v = NCDatasets.defVar(ds,"var-Char",Char,("lon","lat"))

# write array (without transformation)
v.var[:,:] = fill('a',size(v))
@test all(v.var[:,:][:] .== 'a')
@test all(i -> i == 'a',v.var[:,:][:])

# write scalar
v.var[:,:] = 'b'
@test all(v.var[:,:][:] .== 'b')
@test all(i -> i == 'b',v.var[:,:][:])

# write array (with transformation)
v[:,:] = fill('c',size(v))
@test all(v[:,:][:] .== 'c')
@test all(i -> i == 'c',v.var[:,:][:])

# write scalar
v[:,:] = 'd'
@test all(v[:,:][:] .== 'd')
@test all(i -> i == 'd',v.var[:,:][:])

# using StepRange as index
# write array (without transformation)
v.var[1:end,1:end] = fill('e',size(v))
@test all(v.var[1:end,1:end][:] .== 'e')
@test all(i -> i == 'e',v.var[:,:][:])

# write scalar
v.var[1:end,1:end] = 'f'
@test all(v.var[1:end,1:end][:] .== 'f')
@test all(i -> i == 'f',v.var[:,:][:])

# write array (with transformation)
v[1:end,1:end] = fill('g',size(v))
@test all(v[1:end,1:end][:] .== 'g')
@test all(i -> i == 'g',v.var[:,:][:])

# write scalar
v[1:end,1:end] = 'h'
@test all(v[1:end,1:end][:] .== 'h')
@test all(i -> i == 'h',v.var[:,:][:])

# write with StepRange
v[:,:] = 'h'
ref = fill('h',sz)

ref[1:2:end,1:2:end] .= 'i'
if VERSION >= v"0.7.0-beta.0"
ref[1:2:end,1:2:end] .= Ref('i')
else
ref[1:2:end,1:2:end] = 'i'
end
v[1:2:end,1:2:end] = 'i'
@test v[:,:] == ref

@test v[:,:] == ref


ref = ['a'+i+2*j for i = 0:sz[1]-1, j= 0:sz[2]-1]
Expand All @@ -130,4 +145,3 @@ v[:,:] = ref

NCDatasets.close(ds)


0 comments on commit 74151b6

Please sign in to comment.