From b9ec2c2dbb38c17819bb3e26409029bd35d63ba5 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Fri, 1 Apr 2022 10:00:11 -0400 Subject: [PATCH] Allow using python3 for timestamps on macOS and BSD (#362) Note that macOS 12.3 removed python2. --- tests/unittest.bash | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unittest.bash b/tests/unittest.bash index a43678d2..da37cb6b 100755 --- a/tests/unittest.bash +++ b/tests/unittest.bash @@ -674,8 +674,12 @@ if [ "$UNAME" = "linux" ] || [[ "$UNAME" =~ msys_nt* ]]; then } else function timestamp() { - # OS X and FreeBSD do not have %N so python is the best we can do - python -c 'import time; print int(round(time.time() * 1000))' + # macOS and BSDs do not have %N, so Python is the best we can do. + # LC_ALL=C works around python 3.8 and 3.9 crash on macOS when the + # filesystem encoding is unspecified (e.g. when LANG=en_US). + local PYTHON=python + command -v python3 &> /dev/null && PYTHON=python3 + LC_ALL=C "${PYTHON}" -c 'import time; print(int(round(time.time() * 1000)))' } fi