Skip to content

Commit 7200545

Browse files
committed
test: make the integration harness work with the current packaging
The shell integration harness (test_calendar-cli.sh) no longer worked out of the box: - Radicale rejected the hard-coded testuser/password1 because it was started without an auth backend; configure htpasswd auth so the tests authenticate (radicale's defaults deny anonymous access). - Servers were launched via "sh -c '... &'", so $! was the wrapper shell and the later kill orphaned the actual server, leaving it holding its port and breaking the next run. Launch them directly and add an EXIT trap that always tears them down. - The xandikos branch invoked ../bin/calendar-cli without PYTHONPATH, which now fails with ModuleNotFoundError (no setup.py installs the package into the source tree anymore); set PYTHONPATH like the radicale branch. - _setup_alias: prefer the installed 'calendar-cli' console script, and make the source-tree fallback self-contained by setting PYTHONPATH. The radicale path now runs the full tests.sh suite to completion. Xandikos remains functionally incompatible (already noted in the tests README). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> AI Prompts: claude-sonnet-4-6: Create an issue for the "out of scope"-task claude-sonnet-4-6: post it against pycalendar/calendar-cli claude-sonnet-4-6: Please look through the test script for integration testing, does it still work? claude-sonnet-4-6: please fix things claude-sonnet-4-6: retry
1 parent 4d98a96 commit 7200545

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

‎tests/_setup_alias‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,29 @@ error() {
1212
}
1313

1414
find_executable_to_test() {
15-
local candidate
15+
local candidate root
1616

17+
## Prefer the installed console-script entry point (created by
18+
## `pip install` / `make install`); it needs no PYTHONPATH.
19+
if command -v calendar-cli >/dev/null 2>&1; then
20+
echo "calendar-cli"
21+
return 0
22+
fi
23+
24+
## Otherwise run from a source checkout via bin/calendar-cli.py, wrapping it
25+
## with PYTHONPATH pointing at the repo root so `import calendar_cli` works.
1726
for candidate in \
18-
'./calendar-cli.py' \
19-
'../calendar-cli.py' \
20-
'./bin/calendar-cli.py'
27+
'./bin/calendar-cli.py' \
28+
'../bin/calendar-cli.py'
2129
do
2230
if [ -x "$candidate" ]; then
23-
echo "$candidate"
31+
root=$(dirname "$(dirname "$candidate")")
32+
echo "env PYTHONPATH=$root:$PYTHONPATH $candidate"
2433
return 0
2534
fi
2635
done
2736

28-
error "couldn't find ./calendar_cli.py nor ../calendar_cli.py"
37+
error "couldn't find an installed 'calendar-cli' nor bin/calendar-cli.py"
2938
}
3039

3140
set_test_command() {

‎tests/test_calendar-cli.sh‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44

55
storage=$(mktemp -d)
66

7+
## Radicale (like most real servers) requires authentication; set up an
8+
## htpasswd file so the hard-coded testuser/password1 used below is accepted.
9+
htpasswd_file="$storage/htpasswd"
10+
printf 'testuser:password1\n' > "$htpasswd_file"
11+
12+
## Always tear the test servers down, even if the script is interrupted -
13+
## otherwise an orphaned server keeps holding its port and breaks the next run.
14+
radicale_pid=""
15+
xandikos_pid=""
16+
cleanup() {
17+
[ -n "$radicale_pid" ] && kill "$radicale_pid" 2>/dev/null
18+
[ -n "$xandikos_pid" ] && kill "$xandikos_pid" 2>/dev/null
19+
rm -rf "$storage"
20+
}
21+
trap cleanup EXIT
22+
723
echo "This script will attempt to set up a Radicale server and a Xandikos server and run the test code towards those two servers"
824
echo "The test code itself is found in tests.sh"
925

@@ -12,11 +28,15 @@ export RUNTESTSNOPAUSE="foo"
1228
echo "########################################################################"
1329
echo "## RADICALE"
1430
echo "########################################################################"
15-
sh -c "$PYTHON3 -m radicale --storage-filesystem-folder='$storage' \
16-
${DAEMONS_OUTPUT_TO_FILES:+>$storage/radicale.stdout} \
17-
${DAEMONS_OUTPUT_TO_FILES:+2>$storage/radicale.stderr}" &
31+
## Launch radicale directly in the background (not via "sh -c ... &") so that
32+
## $! is radicale's own pid and the kill below actually stops it.
33+
rad_out=/dev/stdout; rad_err=/dev/stderr
34+
[ -n "$DAEMONS_OUTPUT_TO_FILES" ] && { rad_out="$storage/radicale.stdout"; rad_err="$storage/radicale.stderr"; }
35+
"$PYTHON3" -m radicale --storage-filesystem-folder="$storage" \
36+
--auth-type htpasswd --auth-htpasswd-filename "$htpasswd_file" --auth-htpasswd-encryption plain \
37+
>"$rad_out" 2>"$rad_err" &
1838
radicale_pid=$!
19-
sleep 0.3
39+
sleep 0.5
2040
if [ -n "$radicale_pid" ]; then
2141
echo "## Radicale now running on pid $radicale_pid"
2242
calendar_cli="env PYTHONPATH=..:$PYTHONPATH $( printf "%s%s%s%s" '../bin/calendar-cli.py ' \
@@ -38,7 +58,8 @@ if [ -n "$radicale_pid" ]; then
3858
echo "press enter to take down test server"
3959
read -r
4060
fi
41-
kill "$radicale_pid"
61+
kill "$radicale_pid" 2>/dev/null
62+
radicale_pid=""
4263
sleep 0.3
4364
else
4465
echo "## Could not start up radicale (is it installed?). Will skip running tests towards radicale"
@@ -50,19 +71,21 @@ echo "## XANDIKOS"
5071
echo "########################################################################"
5172
xandikos_bin=$(which xandikos 2> /dev/null)
5273
if [ -n "$xandikos_bin" ]; then
53-
sh -c "$xandikos_bin --defaults -d '$storage' \
54-
${DAEMONS_OUTPUT_TO_FILES:+>$storage/xandikos.stdout} \
55-
${DAEMONS_OUTPUT_TO_FILES:+2>$storage/xandikos.stderr}" &
74+
## Launch directly in the background so $! is xandikos' own pid.
75+
xan_out=/dev/stdout; xan_err=/dev/stderr
76+
[ -n "$DAEMONS_OUTPUT_TO_FILES" ] && { xan_out="$storage/xandikos.stdout"; xan_err="$storage/xandikos.stderr"; }
77+
"$xandikos_bin" --defaults -d "$storage" >"$xan_out" 2>"$xan_err" &
5678
xandikos_pid=$!
5779
sleep 0.5
5880
fi
5981

6082
if [ -n "$xandikos_pid" ]; then
6183
echo "## Xandikos now running on pid $xandikos_pid"
62-
calendar_cli="../bin/calendar-cli --caldav-url=http://localhost:8080/ --caldav-user=user"
84+
calendar_cli="env PYTHONPATH=..:$PYTHONPATH ../bin/calendar-cli.py --caldav-url=http://localhost:8080/ --caldav-user=user"
6385

6486
./tests.sh "$calendar_cli"
65-
kill "$xandikos_pid"
87+
kill "$xandikos_pid" 2>/dev/null
88+
xandikos_pid=""
6689
else
6790
echo "## Could not start up xandikos (is it installed?). Will skip running tests towards xandikos"
6891
fi

0 commit comments

Comments
 (0)