File: __init__.py

package info (click to toggle)
mutagen 1.14-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,800 kB
  • ctags: 2,364
  • sloc: python: 9,915; makefile: 6
file content (66 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
from __future__ import division

import glob
import os
import sys
import unittest

from unittest import TestCase
TestCase.uses_mmap = True
suites = []
add = suites.append

for name in glob.glob(os.path.join(os.path.dirname(__file__), "test_*.py")):
    module = "tests." + os.path.basename(name)
    __import__(module[:-3], {}, {}, [])

class Result(unittest.TestResult):

    separator1 = '=' * 70
    separator2 = '-' * 70

    def addSuccess(self, test):
        unittest.TestResult.addSuccess(self, test)
        sys.stdout.write('.')

    def addError(self, test, err):
        unittest.TestResult.addError(self, test, err)
        sys.stdout.write('E')

    def addFailure(self, test, err):
        unittest.TestResult.addFailure(self, test, err)
        sys.stdout.write('F')

    def printErrors(self):
        succ = self.testsRun - (len(self.errors) + len(self.failures))
        v = "%3d" % succ
        count = 50 - self.testsRun
        sys.stdout.write((" " * count) + v + "\n")
        self.printErrorList('ERROR', self.errors)
        self.printErrorList('FAIL', self.failures)

    def printErrorList(self, flavour, errors):
        for test, err in errors:
            sys.stdout.write(self.separator1 + "\n")
            sys.stdout.write("%s: %s\n" % (flavour, str(test)))
            sys.stdout.write(self.separator2 + "\n")
            sys.stdout.write("%s\n" % err)

class Runner(object):
    def run(self, test):
        suite = unittest.makeSuite(test)
        pref = '%s (%d): ' % (test.__name__, len(suite._tests))
        print pref + " " * (25 - len(pref)),
        result = Result()
        suite(result)
        result.printErrors()
        return bool(result.failures + result.errors)

def unit(run=[], filter_func=None):
    runner = Runner()
    failures = False
    use_suites = filter(filter_func, suites)
    for test in use_suites:
        if not run or test.__name__ in run:
            failures |= runner.run(test)
    return failures