Skip to content

Commit a8312b4

Browse files
committed
[Entity] fix empty name and type handling in create_new
1 parent 81fa829 commit a8312b4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

nixio/entity.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ def __init__(self, nixfile, nixparent, h5group):
2121
@classmethod
2222
def create_new(cls, nixfile, nixparent, h5parent, name=None, type_=None):
2323
if name and type_:
24-
util.check_entity_name_and_type(name, type_)
2524
id_ = util.create_id()
26-
else:
25+
util.check_entity_name_and_type(name, type_)
26+
if not name:
2727
name = util.create_id()
2828
id_ = name
29+
util.check_entity_type(type_)
30+
2931
h5group = h5parent.open_group(name)
3032
h5group.set_attr("name", name)
3133
h5group.set_attr("type", type_)

nixio/test/test_file.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def test_file_blocks(self):
6363

6464
assert len(self.file.blocks) == 0
6565

66+
with self.assertRaises(ValueError):
67+
self.file.create_block()
68+
self.file.create_block(name="a name")
69+
70+
b = self.file.create_block(type_="type_a")
71+
assert(b.id == b.name)
72+
6673
def test_file_sections(self):
6774
assert len(self.file.sections) == 0
6875

0 commit comments

Comments
 (0)