Skip to content

Commit

Permalink
add a test a for python container object about function dir and getattr
Browse files Browse the repository at this point in the history
  • Loading branch information
syang-ng committed Sep 3, 2021
1 parent 70baa9f commit e29e65a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/python/unittest/test_ir_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ def test_array_save_load_json():
assert a_loaded[1].value == 2


def test_dir_array():
a = tvm.runtime.convert([1, 2, 3])
dir(a)


def test_getattr_array():
a = tvm.runtime.convert([1, 2, 3])
type_key = getattr(a, "type_key")
assert type_key == "Array"
try:
getattr(a, "test_key")
except AttributeError:
pass


def test_map():
a = te.var("a")
b = te.var("b")
Expand Down Expand Up @@ -70,6 +85,25 @@ def test_map_save_load_json():
assert dd == {"a": 2, "b": 3}


def test_dir_map():
a = te.var("a")
b = te.var("b")
amap = tvm.runtime.convert({a: 2, b: 3})
dir(amap)


def test_getattr_map():
a = te.var("a")
b = te.var("b")
amap = tvm.runtime.convert({a: 2, b: 3})
type_key = getattr(amap, "type_key")
assert type_key == "Map"
try:
getattr(amap, "test_key")
except AttributeError:
pass


def test_in_container():
arr = tvm.runtime.convert(["a", "b", "c"])
assert "a" in arr
Expand All @@ -91,5 +125,10 @@ def test_ndarray_container():
test_map()
test_array_save_load_json()
test_map_save_load_json()
test_dir_array()
test_dir_map()
test_getattr_array()
test_getattr_map()
test_in_container()
test_ndarray_container()

0 comments on commit e29e65a

Please sign in to comment.