Przeglądaj źródła

Add some simple initial image testing scripts

Tianon Gravi 11 lat temu
rodzic
commit
649817d695

+ 8 - 0
test/python-artifacts/test-hy.sh

@@ -0,0 +1,8 @@
+#!/bin/bash
+set -e
+
+pip install -q hy
+[ "$(hy -c '(-> (+ 2 2) (print))')" = '4' ]
+
+pip install -q sh
+[ "$(hy -c '(import [sh [echo]]) (-> (echo 42) (print))')" = '42' ]

+ 8 - 0
test/python-artifacts/test-pip-requests-ssl.py

@@ -0,0 +1,8 @@
+import pip
+
+pip.main(['install', '-q', 'requests'])
+
+import requests
+
+r = requests.get('https://google.com')
+assert(r.status_code == 200)

+ 12 - 0
test/python-artifacts/test-sqlite3.py

@@ -0,0 +1,12 @@
+import sqlite3
+
+ver = sqlite3.sqlite_version
+
+con = sqlite3.connect(':memory:', 1, sqlite3.PARSE_DECLTYPES, None)
+cur = con.cursor()
+cur.execute('CREATE TABLE test (id INT, txt TEXT)')
+cur.execute('INSERT INTO test VALUES (?, ?)', (42, 'wut'))
+cur.execute('SELECT * FROM test')
+assert(cur.fetchall() == [(42, 'wut')])
+cur.execute('DROP TABLE test')
+con.close()

+ 3 - 0
test/python-artifacts/test-zlib.py

@@ -0,0 +1,3 @@
+import zlib
+
+assert(zlib.decompress(zlib.compress(b'IT WORKS IT WORKS IT WORKS')) == b'IT WORKS IT WORKS IT WORKS')

+ 30 - 0
test/python.sh

@@ -0,0 +1,30 @@
+#!/bin/bash
+set -e
+
+python="$(docker run --rm "$1" bash -ec '
+	for c in python3 python pypy3 pypy; do
+		if command -v "$c" &> /dev/null; then
+			echo "$c"
+			break
+		fi
+	done
+')"
+
+if [ -z "$python" ]; then
+	echo >&2 "error: unable to determine how to run 'python' in '$1'"
+	exit 1
+fi
+
+# run each test artifact in a separate, isolated container
+for artifact in "$(dirname "$(readlink -f "$BASH_SOURCE")")"/python-artifacts/*; do
+	inContainerPath="/tmp/$(basename "$artifact")"
+	case "$artifact" in
+		*.py) cmd=( "$python" "$inContainerPath" ) ;;
+		*.sh) cmd=( "$inContainerPath" ) ;;
+		*)    continue ;;
+	esac
+	if ! docker run --rm -e PYTHON="$python" -v "$artifact":"$inContainerPath":ro "$1" "${cmd[@]}"; then
+		echo >&2 "error: '$artifact' failed!"
+		exit 1
+	fi
+done

+ 9 - 0
test/utc.sh

@@ -0,0 +1,9 @@
+#!/bin/bash
+set -e
+
+tz="$(docker run --rm --entrypoint date "$1" +%Z)"
+tzE='UTC'
+if [ "$tz" != "$tzE" ]; then
+	echo >&2 "error: expected '$tzE', got '$tz'"
+	exit 1
+fi