Skip to content

Commit 1a519d9

Browse files
committed
test: added test for attribute type retrieval
1 parent 26c98db commit 1a519d9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/test_attribute_value_list.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from igraph_ctypes.enums import AttributeType
12
from igraph_ctypes._internal.attributes.value_list import (
23
AttributeValueList,
34
_slice_length,
@@ -381,3 +382,17 @@ def test__extend_length_with(items: AVL):
381382
assert len(items) == 8 and items.fixed_length
382383
items._extend_length_by(0)
383384
assert len(items) == 8 and items.fixed_length
385+
386+
387+
def test_type_getter():
388+
items = AVL([1, 2, 3, 4, 5])
389+
assert items.type == AttributeType.NUMERIC
390+
391+
items = AVL([False, False, True])
392+
assert items.type == AttributeType.BOOLEAN
393+
394+
items = AVL(["foo", "bar", "baz"])
395+
assert items.type == AttributeType.STRING
396+
397+
items = AVL(["foo", "bar", False, 42])
398+
assert items.type == AttributeType.OBJECT

tests/test_vertex_attributes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ def test_shallow_copy():
7878
map = g.vattrs.copy()
7979
assert map["name"] == g.vattrs["name"] and map["name"] is not g.vattrs["name"]
8080
assert map["age"] == g.vattrs["age"] and map["age"] is not g.vattrs["age"]
81+
82+
83+
def test_attempt_to_change_attribute_type():
84+
g = create_empty_graph(5)
85+
g.vattrs.set("age", (5, 10, 15, 20, 25))
86+
87+
with raises(ValueError, match="could not convert"):
88+
g.vattrs["age"][2] = "test"

0 commit comments

Comments
 (0)