1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # ./csv2html-test.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | readonly REPO_ROOT=$(readlink -f $(dirname $0))/../..
|
11 |
|
12 | source $REPO_ROOT/test/common.sh
|
13 | source $REPO_ROOT/web/table/html.sh
|
14 |
|
15 |
|
16 | readonly BASE_DIR=_tmp/www
|
17 |
|
18 | link-static() {
|
19 | mkdir -p $BASE_DIR
|
20 |
|
21 | ln -s -f -v \
|
22 | $PWD/../ajax.js \
|
23 | $PWD/table-sort.js \
|
24 | $PWD/table-sort.css \
|
25 | $BASE_DIR
|
26 | }
|
27 |
|
28 | html-head() {
|
29 | PYTHONPATH=$REPO_ROOT $REPO_ROOT/doctools/html_head.py "$@"
|
30 | }
|
31 |
|
32 | header() {
|
33 | html-head --title 'csv2html-test' \
|
34 | ajax.js table-sort.js table-sort.css
|
35 |
|
36 | table-sort-begin
|
37 | }
|
38 |
|
39 | write-html() {
|
40 | local name=$1
|
41 | shift
|
42 |
|
43 | local out=$BASE_DIR/$name.html
|
44 |
|
45 | { header
|
46 | ./csv2html.py "$@" _tmp/$name.csv
|
47 | table-sort-end $name
|
48 | } > $out
|
49 | echo "Wrote $out"
|
50 | }
|
51 |
|
52 | test-no-schema() {
|
53 | cat >_tmp/foo.csv <<EOF
|
54 | a_number,b
|
55 | 1,2
|
56 | 3,4
|
57 | NA,4
|
58 | EOF
|
59 |
|
60 | write-html foo
|
61 | }
|
62 |
|
63 | test-schema() {
|
64 | cat >_tmp/bar.csv <<EOF
|
65 | name,name_HREF,num
|
66 | spam,#spam,11
|
67 | eggs,#eggs,22
|
68 | ham,#ham,99
|
69 | xxx,#xxx,123456
|
70 | zzz,#zzz,NA
|
71 | EOF
|
72 |
|
73 | # NOTE: Columns are out of order, which is OK.
|
74 |
|
75 | # type: could be html-anchor:shell-id, html-href:shell-id
|
76 |
|
77 | cat >_tmp/bar.schema.csv <<EOF
|
78 | column_name,type
|
79 | num,integer
|
80 | name,string
|
81 | name_HREF,string
|
82 | EOF
|
83 |
|
84 | write-html bar
|
85 |
|
86 | cp _tmp/bar.csv _tmp/bar2.csv
|
87 | cp _tmp/bar.schema.csv _tmp/bar2.schema.csv
|
88 | write-html bar2 --thead-offset 1
|
89 | }
|
90 |
|
91 | test-precision() {
|
92 | cat >_tmp/prec.csv <<EOF
|
93 | name,age
|
94 | andy,1.2345
|
95 | bob,2.3456789
|
96 | EOF
|
97 |
|
98 | # NOTE: Columns are out of order, which is OK.
|
99 |
|
100 | # type: could be html-anchor:shell-id, html-href:shell-id
|
101 |
|
102 | cat >_tmp/prec.schema.csv <<EOF
|
103 | column_name,type,precision
|
104 | name,string,1
|
105 | age,double,2
|
106 | EOF
|
107 |
|
108 | write-html prec
|
109 | }
|
110 |
|
111 | test-timestamp() {
|
112 | cat >_tmp/timestamp.csv <<EOF
|
113 | name,start_time,end_time
|
114 | python3,0.1,1000000000.2
|
115 | bash,1100000000.3,1200000000.4
|
116 | EOF
|
117 |
|
118 | # NOTE: Columns are out of order, which is OK.
|
119 |
|
120 | # type: could be html-anchor:shell-id, html-href:shell-id
|
121 |
|
122 | cat >_tmp/timestamp.schema.csv <<EOF
|
123 | column_name,type,strftime
|
124 | name,string,-
|
125 | start_time,float,iso
|
126 | end_time,float,iso
|
127 | EOF
|
128 |
|
129 | write-html timestamp
|
130 |
|
131 | cp _tmp/timestamp.csv _tmp/timestamp2.csv
|
132 |
|
133 | cat >_tmp/timestamp2.schema.csv <<EOF
|
134 | column_name,type,strftime
|
135 | name,string,-
|
136 | start_time,float,iso
|
137 | end_time,float,%H:%M:%S
|
138 | EOF
|
139 |
|
140 | write-html timestamp2
|
141 | }
|
142 |
|
143 | test-row-css-class() {
|
144 | cat >_tmp/css.csv <<EOF
|
145 | name,age
|
146 | andy,1.2345
|
147 | bob,2.3456789
|
148 | EOF
|
149 |
|
150 | # NOTE: Columns are out of order, which is OK.
|
151 |
|
152 | # type: could be html-anchor:shell-id, html-href:shell-id
|
153 |
|
154 | cat >_tmp/css.schema.csv <<EOF
|
155 | column_name,type,precision
|
156 | name,string,1
|
157 | age,double,3
|
158 | EOF
|
159 |
|
160 | write-html css --css-class-pattern 'myclass ^a'
|
161 |
|
162 | cat >_tmp/css2.csv <<EOF
|
163 | ROW_CSS_CLASS,name,age
|
164 | pass,andy,1.2345
|
165 | fail,bob,2.3456789
|
166 | EOF
|
167 |
|
168 | # NOTE: Columns are out of order, which is OK.
|
169 |
|
170 | # type: could be html-anchor:shell-id, html-href:shell-id
|
171 |
|
172 | cat >_tmp/css2.schema.csv <<EOF
|
173 | column_name,type,precision
|
174 | ROW_CSS_CLASS,string,0
|
175 | name,string,1
|
176 | age,double,3
|
177 | EOF
|
178 |
|
179 | write-html css2
|
180 |
|
181 | }
|
182 |
|
183 | all() {
|
184 | link-static
|
185 | echo
|
186 | run-test-funcs
|
187 | }
|
188 |
|
189 | "$@"
|
190 |
|