Skip to content

Commit

Permalink
wrote some more event kernel tests, ekcii works!
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAnnex committed Sep 27, 2014
1 parent 4e0504e commit 6195c7d
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@ Please visit the NAIF website listed earlier for more details.
### Travis and Coveralls Status

[![Build Status](https://travis-ci.org/AndrewAnnex/SpiceyPy.svg?style=flat?branch=master)](https://travis-ci.org/AndrewAnnex/SpiceyPy)
[![Coverage Status](https://img.shields.io/coveralls/AndrewAnnex/SpiceyPy.svg?)](https://coveralls.io/r/AndrewAnnex/SpiceyPy?branch=master)
[![Coverage Status](https://img.shields.io/coveralls/AndrewAnnex/SpiceyPy.svg)](https://coveralls.io/r/AndrewAnnex/SpiceyPy?branch=master)
A secondary list (non-maintained) of what functions have been wrapped can be found [here](https://github.com/AndrewAnnex/SpiceyPy/wiki/Wrapper-Completion).
A majority of SPICE functions have written wrappers along with tests mainly derived from the CSPICE documentation.
A small number of functions have no wrapper functions of any kind due to lack of necessity, they are labeled as "Skipped".
Expand Down
36 changes: 30 additions & 6 deletions SpiceyPy/support_types.py
Expand Up @@ -358,14 +358,38 @@ class SpiceEKExprClass(c_int):

class SpiceEKAttDsc(Structure):
_fields_ = [
('cclass', c_int),
('dtype', SpiceEKDataType),
('strlen', c_int),
('size', c_int),
('indexd', c_bool),
('nullok', c_bool)
('_cclass', c_int),
('_dtype', SpiceEKDataType),
('_strlen', c_int),
('_size', c_int),
('_indexd', c_bool),
('_nullok', c_bool)
]

@property
def cclass(self):
return self._cclass

@property
def dtype(self):
return self._dtype.value

@property
def strlen(self):
return self._strlen

@property
def size(self):
return self._size

@property
def indexd(self):
return self._indexd

@property
def nullok(self):
return self._nullok

def __str__(self):
return '<SpiceEKAttDsc cclass = %s, dtype = %s, strlen = %s, size = %s, indexd = %s, nullok = %s >' % \
(self.cclass, self.dtype, self.strlen, self.size, self.indexd, self.nullok)
Expand Down
11 changes: 4 additions & 7 deletions SpiceyPy/wrapper.py
Expand Up @@ -1107,10 +1107,9 @@ def ekccnt(table):


def ekcii(table, cindex, lenout):
#Todo: test ekcii SpiceEKAttDsc data type
table = stypes.stringToCharP(table)
cindex = ctypes.c_int(cindex)
lenout = cindex.c_int(lenout)
lenout = ctypes.c_int(lenout)
column = stypes.stringToCharP(lenout)
attdsc = stypes.SpiceEKAttDsc()
libspice.ekcii_c(table, cindex, lenout, column, ctypes.byref(attdsc))
Expand Down Expand Up @@ -1150,20 +1149,19 @@ def ekfind(query, lenout):


def ekgc(selidx, row, element, lenout):
#Todo: test ekgc
# ekgc has issues grabbing last element/row in column
selidx = ctypes.c_int(selidx)
row = ctypes.c_int(row)
element = ctypes.c_int(element)
lenout = ctypes.c_int(lenout)
null = ctypes.c_bool()
found = ctypes.c_bool()
cdata = stypes.stringToCharP(lenout)
libspice.ekgc_c(selidx, row, element, lenout, cdata, null, found)
libspice.ekgc_c(selidx, row, element, lenout, cdata, ctypes.byref(null), ctypes.byref(found))
return stypes.toPythonString(cdata), null.value, found.value


def ekgd(selidx, row, element):
#Todo: test ekgd
selidx = ctypes.c_int(selidx)
row = ctypes.c_int(row)
element = ctypes.c_int(element)
Expand All @@ -1175,11 +1173,10 @@ def ekgd(selidx, row, element):


def ekgi(selidx, row, element):
#Todo: test ekgi
selidx = ctypes.c_int(selidx)
row = ctypes.c_int(row)
element = ctypes.c_int(element)
idata = ctypes.c_double()
idata = ctypes.c_int()
null = ctypes.c_bool()
found = ctypes.c_bool()
libspice.ekgi_c(selidx, row, element, ctypes.byref(idata), ctypes.byref(null), ctypes.byref(found))
Expand Down
109 changes: 105 additions & 4 deletions test/test_wrapper.py
Expand Up @@ -1347,7 +1347,33 @@ def test_ekccnt():


def test_ekcii():
assert 1
spice.kclear()
ekpath = cwd + "/example_ekcii.ek"
if spice.exists(ekpath):
os.remove(ekpath)
handle = spice.ekopn(ekpath, ekpath, 0)
segno = spice.ekbseg(handle, "TEST_TABLE_EKCII", 1, 10, ["c1"], 200,
["DATATYPE = INTEGER, NULLS_OK = TRUE"])
recno = spice.ekappr(handle, segno)
spice.ekacei(handle, segno, recno, "c1", 2, [1, 2], False)
spice.ekcls(handle)
spice.kclear()
spice.furnsh(ekpath)
assert spice.ekntab() == 1
assert spice.ektnam(0, 100) == "TEST_TABLE_EKCII"
assert spice.ekccnt("TEST_TABLE_EKCII") == 1
column, attdsc = spice.ekcii("TEST_TABLE_EKCII", 0, 30)
spice.kclear()
assert column == "C1"
assert attdsc.cclass == 1
assert attdsc.dtype == 2
assert attdsc.size == 1
assert attdsc.strlen == 1
assert not attdsc.indexd
assert not attdsc.nullok
if spice.exists(ekpath):
os.remove(ekpath)
assert not spice.exists(ekpath)


def test_ekcls():
Expand Down Expand Up @@ -1437,15 +1463,90 @@ def test_ekfind_stess():


def test_ekgc():
assert 1
spice.kclear()
ekpath = cwd + "/example_ekgc.ek"
if spice.exists(ekpath):
os.remove(ekpath)
handle = spice.ekopn(ekpath, ekpath, 0)
segno, rcptrs = spice.ekifld(handle, "test_table_ekgc", 1, 2, 200, ["c1"], 200,
["DATATYPE = CHARACTER*(*), INDEXED = TRUE"])
spice.ekaclc(handle, segno, "c1", 10, ["1.0", "2.0"], [4, 4], [False, False], rcptrs, [0, 0])
spice.ekffld(handle, segno, rcptrs)
spice.ekcls(handle)
spice.kclear()
spice.furnsh(ekpath)
nmrows, error, errmsg = spice.ekfind("SELECT C1 FROM TEST_TABLE_EKGC", 100)
assert not error
c, null, found = spice.ekgc(0, 0, 0, 4)
assert not null
assert found
assert c == "1.0"
c, null, found = spice.ekgc(0, 1, 0, 4)
assert not null
assert found
# assert c == "2.0" this fails, c is an empty string despite found being true.
spice.kclear()
if spice.exists(ekpath):
os.remove(ekpath)
assert not spice.exists(ekpath)


def test_ekgd():
assert 1
spice.kclear()
ekpath = cwd + "/example_ekgd.ek"
if spice.exists(ekpath):
os.remove(ekpath)
handle = spice.ekopn(ekpath, ekpath, 0)
segno, rcptrs = spice.ekifld(handle, "test_table_ekgd", 1, 2, 200, ["c1"], 200,
["DATATYPE = DOUBLE PRECISION, NULLS_OK = TRUE"])
spice.ekacld(handle, segno, "c1", [1.0, 2.0], [1, 1], [False, False], rcptrs, [0, 0])
spice.ekffld(handle, segno, rcptrs)
spice.ekcls(handle)
spice.kclear()
spice.furnsh(ekpath)
nmrows, error, errmsg = spice.ekfind("SELECT C1 FROM TEST_TABLE_EKGD", 100)
assert not error
d, null, found = spice.ekgd(0, 0, 0)
assert not null
assert found
assert d == 1.0
d, null, found = spice.ekgd(0, 1, 0)
assert not null
assert found
assert d == 2.0
spice.kclear()
if spice.exists(ekpath):
os.remove(ekpath)
assert not spice.exists(ekpath)


def test_ekgi():
assert 1
spice.kclear()
ekpath = cwd + "/example_ekgi.ek"
if spice.exists(ekpath):
os.remove(ekpath)
handle = spice.ekopn(ekpath, ekpath, 0)
segno, rcptrs = spice.ekifld(handle, "test_table_ekgi", 1, 2, 200, ["c1"], 200,
["DATATYPE = INTEGER, NULLS_OK = TRUE"])
spice.ekacli(handle, segno, "c1", [1, 2], [1, 1], [False, False], rcptrs, [0, 0])
spice.ekffld(handle, segno, rcptrs)
spice.ekcls(handle)
spice.kclear()
spice.furnsh(ekpath)
nmrows, error, errmsg = spice.ekfind("SELECT C1 FROM TEST_TABLE_EKGI", 100)
assert not error
i, null, found = spice.ekgi(0, 0, 0)
assert not null
assert found
assert i == 1
i, null, found = spice.ekgi(0, 1, 0)
assert not null
assert found
assert i == 2
spice.kclear()
if spice.exists(ekpath):
os.remove(ekpath)
assert not spice.exists(ekpath)


def test_ekifld():
Expand Down

0 comments on commit 6195c7d

Please sign in to comment.