-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathattribute_write_simple_test.go
More file actions
62 lines (49 loc) · 1.55 KB
/
attribute_write_simple_test.go
File metadata and controls
62 lines (49 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package hdf5
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestWriteAttributeBasic tests basic attribute writing functionality.
func TestWriteAttributeBasic(t *testing.T) {
fw, err := CreateForWrite("testdata/test_attr_basic.h5", CreateTruncate)
require.NoError(t, err)
defer func() {
_ = fw.Close()
}()
ds, err := fw.CreateDataset("/data", Float64, []uint64{10})
require.NoError(t, err)
// Test int32
err = ds.WriteAttribute("int_val", int32(42))
assert.NoError(t, err)
// Test float64
err = ds.WriteAttribute("float_val", float64(3.14))
assert.NoError(t, err)
// Test string
err = ds.WriteAttribute("units", "meters")
assert.NoError(t, err)
// Test array
err = ds.WriteAttribute("calibration", []int32{1, 2, 3})
assert.NoError(t, err)
}
// TestWriteAttributeErrorCases tests error handling.
func TestWriteAttributeErrorCases(t *testing.T) {
t.Skip("SKIPPED: Fix attribute write error handling (known issue, not Phase 3)")
fw, err := CreateForWrite("testdata/test_attr_errors.h5", CreateTruncate)
require.NoError(t, err)
defer func() {
_ = fw.Close()
}()
ds, err := fw.CreateDataset("/data", Int32, []uint64{5})
require.NoError(t, err)
// Empty name
err = ds.WriteAttribute("", int32(1))
assert.Error(t, err)
assert.Contains(t, err.Error(), "attribute name cannot be empty")
// Duplicate attribute
err = ds.WriteAttribute("test", int32(1))
assert.NoError(t, err)
err = ds.WriteAttribute("test", int32(2))
assert.Error(t, err)
assert.Contains(t, err.Error(), "already exists")
}