File: test_ui.py

package info (click to toggle)
kiwi 1.9.22-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 11,912 kB
  • ctags: 5,549
  • sloc: python: 15,779; ansic: 193; xml: 77; makefile: 57; sh: 18
file content (49 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (3)
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
import os
import subprocess
import sys
import unittest

def setup(self, rootdir):
    self._dir = os.getcwd()
    os.chdir(rootdir)

def teardown(self):
    os.chdir(self._dir)

def test_filename(rootdir, filename):
    cmd = '%s %s -v %s' % (sys.executable,
                           os.path.join(rootdir, 'bin', 'kiwi-ui-test'),
                           os.path.join('tests', 'ui', filename))
    proc = subprocess.Popen(cmd, shell=True)
    status = proc.wait()

    if status != 0:
        raise AssertionError("UI Test %s failed" % filename)

def create():
    testdir = os.path.dirname(__file__)
    uidir = os.path.join(testdir, 'ui')
    rootdir = os.path.dirname(testdir)
    tests = {}
    tests['setUp'] = lambda self, rootdir=rootdir: setup(self, rootdir)
    tests['tearDown'] = lambda self, rootdir=rootdir: teardown(self)

    for filename in os.listdir(uidir):
        if not filename.endswith('.doctest'):
            continue
        name = 'test_' + filename[:-7]

        full = os.path.join(uidir, filename)

        func = lambda self, filename=filename: test_filename(rootdir, filename)
        try:
            func.__name__ = name
        except TypeError:
            pass
        tests[name] = func
    return type('TestUI', (unittest.TestCase,), tests)

# Disable UI tests on win32, they do not quite work yet.
if sys.platform != 'win32':
    TestUI = create()