Skip to content

Commit 2c056cf

Browse files
committed
fix: Platform-specific issues in example tests
- macOS: Install coreutils for timeout command (gtimeout) - macOS: Auto-detect gtimeout vs timeout command - Windows: Set PYTHONIOENCODING=utf-8 to handle emoji characters - All: Fix artifact names to use hyphens instead of slashes - Prevents UnicodeEncodeError on Windows with cp1252 encoding - Prevents 'timeout: command not found' on macOS
1 parent f378235 commit 2c056cf

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

.github/workflows/test-python-examples.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ jobs:
170170
# Install dependencies needed by examples
171171
pip install numpy requests
172172
173+
- name: Install timeout command (macOS only)
174+
if: matrix.platform == 'darwin/amd64' || matrix.platform == 'darwin/arm64'
175+
shell: bash
176+
run: |
177+
# macOS doesn't have timeout command by default, use coreutils
178+
brew install coreutils
179+
180+
- name: Set UTF-8 encoding (Windows only)
181+
if: matrix.platform == 'windows/amd64' || matrix.platform == 'windows/arm64'
182+
shell: bash
183+
run: |
184+
# Set UTF-8 encoding to handle emoji characters
185+
echo "PYTHONIOENCODING=utf-8" >> $GITHUB_ENV
186+
173187
- name: Run all examples
174188
id: run_examples
175189
shell: bash
@@ -200,6 +214,13 @@ jobs:
200214
exit 1
201215
fi
202216
217+
# Detect timeout command (macOS uses gtimeout, Linux uses timeout)
218+
if command -v gtimeout &> /dev/null; then
219+
TIMEOUT_CMD="gtimeout"
220+
else
221+
TIMEOUT_CMD="timeout"
222+
fi
223+
203224
# Run each example
204225
for example in $examples; do
205226
# For example 04, test both small and large datasets
@@ -220,7 +241,7 @@ jobs:
220241
timeout_duration=3600
221242
fi
222243
223-
if timeout $timeout_duration python "$example" --size "$size" > "$log_file" 2>&1; then
244+
if $TIMEOUT_CMD $timeout_duration python "$example" --size "$size" > "$log_file" 2>&1; then
224245
echo "✅ PASSED: $example_name" | tee -a $results_file
225246
passed=$((passed + 1))
226247
else
@@ -245,7 +266,7 @@ jobs:
245266
echo "----------------------------------------"
246267
247268
# Create a timeout wrapper to prevent hanging
248-
if timeout 1800 python "$example" > "${example}.log" 2>&1; then
269+
if $TIMEOUT_CMD 1800 python "$example" > "${example}.log" 2>&1; then
249270
echo "✅ PASSED: $example" | tee -a $results_file
250271
passed=$((passed + 1))
251272
else
@@ -348,7 +369,7 @@ jobs:
348369
if: always()
349370
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
350371
with:
351-
name: example-logs-${{ matrix.platform }}
372+
name: example-logs-${{ matrix.platform == 'linux/amd64' && 'linux-amd64' || matrix.platform == 'linux/arm64' && 'linux-arm64' || matrix.platform == 'darwin/amd64' && 'darwin-amd64' || matrix.platform == 'darwin/arm64' && 'darwin-arm64' || matrix.platform == 'windows/amd64' && 'windows-amd64' || 'windows-arm64' }}
352373
path: |
353374
bindings/python/examples/*.log
354375
bindings/python/examples/example-results.txt
@@ -358,7 +379,7 @@ jobs:
358379
if: failure()
359380
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
360381
with:
361-
name: example-databases-${{ matrix.platform }}
382+
name: example-databases-${{ matrix.platform == 'linux/amd64' && 'linux-amd64' || matrix.platform == 'linux/arm64' && 'linux-arm64' || matrix.platform == 'darwin/amd64' && 'darwin-amd64' || matrix.platform == 'darwin/arm64' && 'darwin-arm64' || matrix.platform == 'windows/amd64' && 'windows-amd64' || 'windows-arm64' }}
362383
path: bindings/python/examples/my_test_databases/
363384
retention-days: 3
364385

0 commit comments

Comments
 (0)