~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to .pc/00_bzr-run-tests-setup.patch/run-tests.sh

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2013-03-22 09:48:37 UTC
  • Revision ID: package-import@ubuntu.com-20130322094837-3eq2ntujq0m9jbtm
Tags: 5.5.6-0ubuntu2
* debian/patches/00_bzr-run-tests-setup.patch:
  - Run setup.py build before the tests get run; clean after. (LP: #1158290)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
set -e
 
4
 
 
5
TESTS_DIR="tests"
 
6
 
 
7
dpkg-checkbuilddeps -d 'python-coverage, xvfb, python-mock, python-unittest2,
 
8
                       python3-aptdaemon.test, python-lxml, python-qt4'
 
9
 
 
10
if [ ! -e /var/lib/apt-xapian-index/index ]; then
 
11
    echo "please run sudo update-apt-xapian-index"
 
12
    exit 1
 
13
fi
 
14
 
 
15
# check if basic http access works
 
16
HTTP_URL=http://software-center.ubuntu.com
 
17
if ! curl -s $HTTP_URL >/dev/null; then
 
18
    echo "NEED curl and http access to $HTTP_URL"
 
19
    exit 1
 
20
fi
 
21
 
 
22
# clear coverage data
 
23
# coverage erase will not erase the files from --parallel-mode
 
24
rm -f $TESTS_DIR/.coverage*
 
25
 
 
26
# run with xvfb and coverage
 
27
 
 
28
XVFB_CMDLINE=""
 
29
 
 
30
# mvo 2012-11-05: disabled as this causes hangs in raring
 
31
#XVFB=$(which xvfb-run)
 
32
XVFB=""
 
33
 
 
34
if [ $XVFB ]; then
 
35
    XVFB_CMDLINE="$XVFB -a"
 
36
fi
 
37
 
 
38
COVERAGE_CMDLINE=""
 
39
COVERAGE=$(which python-coverage)
 
40
if [ $COVERAGE ]; then
 
41
    # If you are measuring coverage in a multi-process program, or across a
 
42
    # number of machines, you’ll want the --parallel-mode switch to keep the
 
43
    # data separate during measurement. See Combining data files below.
 
44
    ##COVERAGE_CMDLINE="$COVERAGE run --parallel-mode"
 
45
    echo "No coverage for now."
 
46
fi
 
47
 
 
48
PYTHON="$XVFB_CMDLINE $COVERAGE_CMDLINE python -m unittest"
 
49
 
 
50
# and record failures here
 
51
OUTPUT=$TESTS_DIR"/output"
 
52
 
 
53
FAILED=""
 
54
run_tests_for_dir() {
 
55
    for i in $(find $1 -maxdepth 1 -name 'test_*.py'); do
 
56
        TEST_NAME=$(basename $i | cut -d '.' -f 1)
 
57
        TEST_PREFIX=$(echo `dirname $i` | sed -e s'/\//./g')
 
58
        printf '%-50s' "Testing $TEST_NAME..."
 
59
        if ! $PYTHON -v -c -b $TEST_PREFIX.$TEST_NAME > $OUTPUT/$TEST_NAME.out 2>&1; then
 
60
            FAILED="$FAILED $TEST_NAME"
 
61
            echo "[ FAIL ]"
 
62
            # add .FAIL symlink to make finding the broken ones trivial
 
63
            (cd $OUTPUT ; ln -s $TEST_NAME.out $TEST_NAME.out.FAIL)
 
64
        else
 
65
            echo "[  OK  ]"
 
66
            rm -f ${OUTPUT}/$file.out;
 
67
        fi
 
68
    done
 
69
}
 
70
 
 
71
if [ "$1" = "--sso-gtk" ]; then
 
72
    # Run the SSO GTK+ suite
 
73
    $PYTHON discover -s softwarecenter/sso/
 
74
elif [ $# -gt 0 ]; then
 
75
    # run the requested tests if arguments were given,
 
76
    # otherwise run the whole suite
 
77
    # example of custom params (discover all the tests under the tests/gtk3 dir):
 
78
 
 
79
    # ./run-tests.sh discover -v -s tests/gtk3/
 
80
 
 
81
    # See http://docs.python.org/library/unittest.html#test-discovery
 
82
    # for more info.
 
83
    RUN_TESTS="$PYTHON $@"
 
84
    echo "Running the command: $RUN_TESTS"
 
85
    $RUN_TESTS
 
86
else
 
87
    # 2012-05-30, nessita: Ideally, we should be able to run the whole suite
 
88
    # using discovery, but there is too much interference between tests in
 
89
    # order to do so, so we need a new python process per test file.
 
90
    ##RUN_TESTS="$PYTHON discover -v -c -b"
 
91
    rm -rf $OUTPUT
 
92
    mkdir $OUTPUT
 
93
    run_tests_for_dir "$TESTS_DIR/gtk3"
 
94
    run_tests_for_dir $TESTS_DIR
 
95
 
 
96
    # gather the coverage data
 
97
    ##./gen-coverage-report.sh
 
98
 
 
99
    if [ -n "$FAILED" ]; then
 
100
        echo "FAILED: $FAILED"
 
101
        echo "Check ${OUTPUT}/ directory for the details"
 
102
        exit 1
 
103
    else
 
104
        echo "All OK!"
 
105
    fi
 
106
fi