~ubuntu-branches/ubuntu/quantal/spectacle/quantal

« back to all changes in this revision

Viewing changes to tests/testbase.py

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2010-08-08 20:01:42 UTC
  • Revision ID: james.westby@ubuntu.com-20100808200142-q09anvq02isk4o6n
Tags: upstream-0.18+git19+4768025
ImportĀ upstreamĀ versionĀ 0.18+git19+4768025

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -tt
 
2
# vim: ai ts=4 sts=4 et sw=4
 
3
 
 
4
#    Copyright (c) 2009 Intel Corporation
 
5
#
 
6
#    This program is free software; you can redistribute it and/or modify it
 
7
#    under the terms of the GNU General Public License as published by the Free
 
8
#    Software Foundation; version 2 of the License
 
9
#
 
10
#    This program is distributed in the hope that it will be useful, but
 
11
#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
12
#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
13
#    for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License along
 
16
#    with this program; if not, write to the Free Software Foundation, Inc., 59
 
17
#    Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 
 
19
SCRIPTS = """
 
20
specify -N -o output.spec testpkg.yaml 1>output.1.o 2>output.2.o
 
21
mv output.spec output.orig.spec
 
22
patch -s < input.p
 
23
specify -N -o output.spec testpkg.yaml 1>ouput.1 2>output.2
 
24
if [ ! -f output.no -a ! -f output.spec ]; then
 
25
  mv output.2 output.error
 
26
  exit 1
 
27
fi
 
28
if [ -f output.p ]; then
 
29
  diff -upN output.orig.spec output.spec > newoutput.p
 
30
  mv output.spec output.new.spec
 
31
  patch < output.p >/dev/null
 
32
fi
 
33
if [ -f output.1p ]; then
 
34
  diff -upN output.1.o output.1 > newoutput.1p
 
35
  mv output.1 output.1.n
 
36
  patch < output.1p >/dev/null
 
37
fi
 
38
if [ -f output.2p ]; then
 
39
  diff -upN output.2.o output.2 > newoutput.2p
 
40
  mv output.2 output.2.n
 
41
  patch < output.2p >/dev/null
 
42
fi
 
43
"""
 
44
 
 
45
import os,sys
 
46
import glob
 
47
import shutil
 
48
import filecmp
 
49
 
 
50
BLUE='\033[%dm' % 34
 
51
RED='\033[%dm' % 31
 
52
RESET = '\033[0m'
 
53
 
 
54
def prep_working_env(cases_dir, case, dst_dir):
 
55
    shutil.copy(os.path.join(cases_dir, 'base', 'testpkg.yaml'), dst_dir)
 
56
    for out in glob.glob(os.path.join(cases_dir, 'test-'+case, '*')):
 
57
        try:
 
58
            if not os.path.isdir(out):
 
59
                shutil.copy(out, dst_dir)
 
60
        except:
 
61
            pass # ignore if file missing
 
62
 
 
63
def cleanup(work_dir):
 
64
    shutil.rmtree(work_dir)
 
65
 
 
66
def run_and_check(work_dir):
 
67
    result = True
 
68
    cwd = os.getcwd()
 
69
    os.chdir(work_dir)
 
70
    os.system(SCRIPTS)
 
71
    if os.path.exists('output.error'):
 
72
        # something wrong with tested tools
 
73
        print >> sys.stderr, file(os.path.join(work_dir, 'output.error')).read()
 
74
        result = False
 
75
 
 
76
    os.chdir(cwd)
 
77
    return result
 
78
 
 
79
def compare_outfile(work_dir):
 
80
    all_equ = True
 
81
    #print glob.glob(os.path.join(work_dir, '*'))
 
82
    desc = {'output.p': '*.spec',
 
83
            'output.1p': 'STDOUT',
 
84
            'output.2p': 'STDERR'}
 
85
    orig = {'output.p': 'output.orig.spec',
 
86
            'output.1p': 'output.1.o',
 
87
            'output.2p': 'output.2.o'}
 
88
    new  = {'output.p': 'output.new.spec',
 
89
            'output.1p': 'output.1.n',
 
90
            'output.2p': 'output.2.n'}
 
91
    for out in ('output.p', 'output.1p', 'output.2p'):
 
92
        fp = os.path.join(work_dir, out)
 
93
        if os.path.exists(fp):
 
94
            if not filecmp.cmp(os.path.join(work_dir, orig[out]),\
 
95
                               os.path.join(work_dir, new[out])):
 
96
                all_equ = False
 
97
 
 
98
                exp_output_diff = file(fp).read().strip()
 
99
                output_diff = file(os.path.join(work_dir, 'new'+out)).read().strip()
 
100
 
 
101
                if not output_diff:
 
102
                    output_diff = '<EMPTY>'
 
103
                if not exp_output_diff:
 
104
                    exp_output_diff = '<EMPTY>'
 
105
 
 
106
                print "%sExpected changes of %s:" % (BLUE,desc[out])
 
107
                print '----------------------------------------------------------------------%s' % RESET
 
108
                print exp_output_diff
 
109
                print '%s----------------------------------------------------------------------%s' % (BLUE,RESET)
 
110
                print "%sActual:" % RED
 
111
                print '----------------------------------------------------------------------%s' % RESET
 
112
                print output_diff
 
113
                print '%s----------------------------------------------------------------------%s' % (RED,RESET)
 
114
 
 
115
    return all_equ