-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-cli.sh
executable file
·68 lines (58 loc) · 2.2 KB
/
test-cli.sh
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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
die() { set +v; echo "${red}$*${reset}" 1>&2 ; sleep 1; exit 1; }
function test_good() {
# Make tempdir and cleanup afterwards.
OLD_DIR=`mktemp -d`
NEW_DIR=`mktemp -d`
NEW_XLSX="$NEW_DIR/template.xlsx"
PYTHONPATH="${PYTHONPATH}:tableschema_to_template" \
tableschema_to_template/ts2xl.py \
tests/fixtures/schema.yaml $NEW_XLSX \
--sheet_name 'Enter data here' \
--idempotent
unzip -q $NEW_XLSX -d $NEW_DIR
cp tests/fixtures/template.xlsx $OLD_DIR
unzip -q $OLD_DIR/template.xlsx -d $OLD_DIR
for UNZIPPED_PATH in `cd tests/fixtures/output-unzipped; find . | grep .xml`; do
# We look in output-unzipped only to get a list of files:
# Those have been pretty-printed, and should not be directly compared against the command-line output.
# Here, we just unzip and do a byte-wise comparison of the XML.
cmp -s $NEW_DIR/$UNZIPPED_PATH \
$OLD_DIR/$UNZIPPED_PATH \
|| die "On $UNZIPPED_PATH, CLI output ($NEW_DIR) output does not match fixture ($OLD_DIR). Consider:
cp $NEW_XLSX ./tests/fixtures/"
echo "Newly generated XSLX matches XLSX fixture on $UNZIPPED_PATH"
done
rm -rf $NEW_DIR
rm -rf $OLD_DIR
}
function test_bad() {
( ! PYTHONPATH="${PYTHONPATH}:tableschema_to_template" \
tableschema_to_template/ts2xl.py <(echo '{}') /tmp/should-not-exist.xlsx \
2>&1 ) \
| grep "Not a valid Table Schema: 'fields' is \(a \)\?required property" \
|| die 'Did not see expected error'
# The error message changed slightly between versions.
}
function test_cli_doc() {
diff \
<(perl -ne 'print if /usage:/../```/ and ! /```/' README-cli.md) \
<(PYTHONPATH="${PYTHONPATH}:tableschema_to_template" tableschema_to_template/ts2xl.py --help) \
|| die 'Update README-cli.md'
}
function test_py_doc() {
# Plain 'pydoc' ran wrong version on Travis.
diff --ignore-all-space \
<(grep -v '```' README-py.md) \
<(python -m pydoc tableschema_to_template.create_xlsx) \
|| die 'Update README-py.md'
}
for TEST in `declare -F | grep test | sed -e 's/declare -f //'`; do
echo "${green}${TEST}${reset}"
$TEST
done