Skip to content

Commit

Permalink
Merge pull request #218 from fixstars/fix/param-type-check
Browse files Browse the repository at this point in the history
type check for bool on param
  • Loading branch information
iitaku authored Jan 22, 2024
2 parents 5b5f954 + b32a972 commit be71528
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions python/ionpy/Param.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def __init__(self,
):
if obj_ is None:
obj_ = c_ion_param_t()

ret = ion_param_create(ctypes.byref(obj_), key.encode(), str(val).lower().encode())
if isinstance(val, bool):
if val:
val = "true"
else:
val = "false"
ret = ion_param_create(ctypes.byref(obj_), key.encode(), str(val).encode())
if ret != 0:
raise Exception('Invalid operation')

Expand Down
8 changes: 6 additions & 2 deletions python/test/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@


def test_param():
p = Param(key='iamkey', val='iamval')
print(p)
p1 = Param(key='iamkey1', val="IAMKEY") # 'IAMKEY'
p2 = Param(key='iamkey2', val="iamkey") # 'iamkey'
p3 = Param(key='iamkey3', val=1) # '1'
p4 = Param(key='iamkey4', val=0.1) # '0.1'
p5 = Param(key='iamkey5', val=True) # 'true'
p6 = Param(key='iamkey6', val=False) # 'false'

0 comments on commit be71528

Please sign in to comment.