forked from astropy/astropy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_profiling.py
More file actions
88 lines (65 loc) · 2.97 KB
/
Copy pathtest_profiling.py
File metadata and controls
88 lines (65 loc) · 2.97 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import glob
import os
import sys
import numpy as np
from numpy.testing import assert_array_almost_equal
from ...config import get_data_filenames, get_data_contents
from ... import wcs
def test_maps():
def test_map(filename):
header = get_data_contents(os.path.join("maps", filename))
wcsobj = wcs.WCS(header)
x = np.random.rand(2 ** 12, wcsobj.wcs.naxis)
world = wcsobj.wcs_pix2world(x, 1)
pix = wcsobj.wcs_world2pix(x, 1)
hdr_file_list = list(get_data_filenames("maps", "*.hdr"))
# actually perform a test for each one
for filename in hdr_file_list:
# use the base name of the file, because everything we yield
# will show up in the test name in the pandokia report
filename = os.path.basename(filename)
# yield a function name and parameters to make a generated test
yield test_map, filename
# AFTER we tested with every file that we found, check to see that we
# actually have the list we expect. If N=0, we will not have performed
# any tests at all. If N < n_data_files, we are missing some files,
# so we will have skipped some tests. Without this check, both cases
# happen silently!
# how many do we expect to see?
n_data_files = 28
if len(hdr_file_list) != n_data_files:
assert False, (
"test_maps has wrong number data files: found %d, expected "
" %d" % (
len(hdr_file_list), n_data_files))
# b.t.w. If this assert happens, py.test reports one more test
# than it would have otherwise.
def test_spectra():
def test_spectrum(filename):
header = get_data_contents(os.path.join("spectra", filename))
wcsobj = wcs.WCS(header)
x = np.random.rand(2 ** 16, wcsobj.wcs.naxis)
world = wcsobj.wcs_pix2world(x, 1)
pix = wcsobj.wcs_world2pix(x, 1)
hdr_file_list = list(get_data_filenames("spectra", "*.hdr"))
# actually perform a test for each one
for filename in hdr_file_list:
# use the base name of the file, because everything we yield
# will show up in the test name in the pandokia report
filename = os.path.basename(filename)
# yield a function name and parameters to make a generated test
yield test_spectrum, filename
# AFTER we tested with every file that we found, check to see that we
# actually have the list we expect. If N=0, we will not have performed
# any tests at all. If N < n_data_files, we are missing some files,
# so we will have skipped some tests. Without this check, both cases
# happen silently!
# how many do we expect to see?
n_data_files = 6
if len(hdr_file_list) != n_data_files:
assert False, (
"test_spectra has wrong number data files: found %d, expected "
" %d" % (
len(hdr_file_list), n_data_files))
# b.t.w. If this assert happens, py.test reports one more test
# than it would have otherwise.