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
|
#!/bin/bash
set -e
pkg=multisplitby
CUR_DIR=`pwd`
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi
cd "${AUTOPKGTEST_TMP}"
cat >test_sample.py <<HERE
from multisplitby import multi_split_by
import unittest
class TestBasicFunctionality(unittest.TestCase):
def test_one_predicate(self):
values = range(4)
predicates = [lambda x: 2 < x]
self.assertEqual(list(map(list, multi_split_by(values, predicates))),
[[0, 1, 2], [3]])
def test_many_predicates(self):
values = range(9)
predicates = [lambda x: 2 < x, lambda x: 4 < x, lambda x: 7 < x]
self.assertEqual(list(map(list, multi_split_by(values, predicates))),
[[0, 1, 2], [3, 4], [5, 6, 7], [8]])
def test_noinfo(self):
values = []
predicates = [lambda x: 2 < x, lambda x: 4 < x, lambda x: 7 < x]
self.assertEqual(list(map(list, multi_split_by(values, predicates))),
[[], [], [], []])
def test_no_predicates(self):
values = range(4)
predicates = []
self.assertEqual(list(map(list, multi_split_by(values, predicates))),
[[0, 1, 2, 3]])
if __name__ == '__main__':
unittest.main()
HERE
echo "Running sample test"
python3 -m unittest -v
rm -f ./test_sample.py
echo "=============== PASS ====================="
cp -a ${CUR_DIR}/tests "${AUTOPKGTEST_TMP}"
echo "Run upstream test"
python3 -m unittest -v
echo "=============== PASS ====================="
|