~ubuntu-branches/ubuntu/utopic/pyfiglet/utopic-proposed

« back to all changes in this revision

Viewing changes to pyfiglet/test.py

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-08-18 12:54:45 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110818125445-bmnz4bflddomaz30
Tags: 0.6+dfsg-1
* New upstream release.
  - Update copyright.
  - Update man page.
* Upstream moved to github, updated watch file and get-orig-source.
* Dropped patches superseded upstream:
  py26deprecation.diff, dir-error-path.diff, tlf-support.diff
* font-location.diff: Look in /usr/share/figlet for fonts, rather than using
  pkg_resources.
* Updated debian-defaults.diff.
* Install wrapper with dh_install, as upstream has a setup.py.
* Build-Depend on python-setuptools and clean up egg-info.
* Move DFSG repacking into a script called by uscan.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import os.path
 
4
import sys
 
5
from optparse import OptionParser
 
6
from pyfiglet import Figlet
 
7
from subprocess import Popen, STDOUT, PIPE
 
8
 
 
9
__version__ = '0.1'
 
10
 
 
11
def dump(text):
 
12
    for line in text.split('\n'):
 
13
        print repr(line)
 
14
 
 
15
def main():
 
16
    parser = OptionParser(version=__version__)
 
17
 
 
18
    parser.add_option('-s', '--show', action='store_true', default=False,
 
19
                      help='pause at each failure and compare output '
 
20
                           '(default: %default)')
 
21
 
 
22
    opts, args = parser.parse_args()
 
23
 
 
24
    f = Figlet()
 
25
 
 
26
    ok = 0
 
27
    fail = 0
 
28
    failed = []
 
29
    skip = ['runic'] # known bug..
 
30
 
 
31
    for font in f.getFonts():
 
32
        if font in skip: continue
 
33
 
 
34
        f.setFont(font=font)
 
35
 
 
36
        outputPyfiglet = f.renderText('foo')
 
37
 
 
38
        fontpath = os.path.join('pyfiglet', 'fonts', font)
 
39
        if os.path.isfile(fontpath + '.flf'):
 
40
            cmd = ('figlet', '-d', 'pyfiglet/fonts', '-f', font, 'foo')
 
41
        elif os.path.isfile(fontpath + '.tlf'):
 
42
            cmd = ('toilet', '-d', 'pyfiglet/fonts', '-f', font, 'foo')
 
43
        else:
 
44
            raise Exception('Missing font file')
 
45
            
 
46
        p = Popen(cmd, bufsize=1,stdout=PIPE)
 
47
        outputFiglet = p.communicate()[0]
 
48
 
 
49
        if outputPyfiglet == outputFiglet:
 
50
            print '[OK] %s' % font
 
51
            ok += 1
 
52
            continue
 
53
 
 
54
        print '[FAIL] %s' % font
 
55
        fail += 1
 
56
        failed.append(font)
 
57
 
 
58
        if opts.show is True:
 
59
            print '[PYTHON] *** %s\n\n' % font
 
60
            dump(outputPyfiglet)
 
61
            print '[FIGLET] *** %s\n\n' % font
 
62
            dump(outputFiglet)
 
63
            raw_input()
 
64
 
 
65
    print 'OK = %d, FAIL = %d' % (ok, fail)
 
66
    if len(failed) > 0:
 
67
        print 'FAILED = %s' % repr(failed)
 
68
 
 
69
    return 0
 
70
 
 
71
if __name__ == '__main__': sys.exit(main())