-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphdu_test.go
86 lines (73 loc) · 1.57 KB
/
phdu_test.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cfitsio
import (
"io/ioutil"
"os"
"testing"
)
func TestCreatePHDU(t *testing.T) {
curdir, err := os.Getwd()
if err != nil {
t.Fatalf(err.Error())
}
defer os.Chdir(curdir)
workdir, err := ioutil.TempDir("", "go-cfitsio-test-")
if err != nil {
t.Fatalf(err.Error())
}
defer os.RemoveAll(workdir)
err = os.Chdir(workdir)
if err != nil {
t.Fatalf(err.Error())
}
fname := "new.fits"
for _, fct := range []func(){
// create
func() {
f, err := Create(fname)
if err != nil {
t.Fatalf("error creating new file [%v]: %v", fname, err)
}
defer f.Close()
phdu, err := NewPrimaryHDU(&f, NewDefaultHeader())
if err != nil {
t.Fatalf("error creating PHDU: %v", err)
}
defer phdu.Close()
hdr := phdu.Header()
if hdr.bitpix != 8 {
t.Fatalf("expected BITPIX=%v. got %v", 8, hdr.bitpix)
}
name := phdu.Name()
if name != "PRIMARY" {
t.Fatalf("expected EXTNAME==%v. got %v", "PRIMARY", name)
}
vers := phdu.Version()
if vers != 1 {
t.Fatalf("expected EXTVER==%v. got %v", 1, vers)
}
},
// read-back
func() {
f, err := Open(fname, ReadOnly)
if err != nil {
t.Fatalf("error opening file [%v]: %v", fname, err)
}
defer f.Close()
hdu := f.HDU(0)
hdr := hdu.Header()
if hdr.bitpix != 8 {
t.Fatalf("expected BITPIX=%v. got %v", 8, hdr.bitpix)
}
name := hdu.Name()
if name != "PRIMARY" {
t.Fatalf("expected EXTNAME==%v. got %v", "PRIMARY", name)
}
vers := hdu.Version()
if vers != 1 {
t.Fatalf("expected EXTVER==%v. got %v", 1, vers)
}
},
} {
fct()
}
}