Commit 95305858 authored by SVN-Git Migration's avatar SVN-Git Migration

Imported Upstream version 0.7.4+dfsg

parent 791eb0e3
......@@ -7,6 +7,9 @@ python:
- "3.4"
- "pypy"
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq toilet figlet
script: PYTHONPATH=. python pyfiglet/test.py
- "sudo apt-get update -qq"
- "sudo apt-get install -qq toilet figlet"
install:
- "pip install -r requirements.txt || true"
- "pip install ."
script: python pyfiglet/test.py
......@@ -60,19 +60,6 @@ USAGE
print f.renderText('text to render')
pyfiglet also supports reading fonts from a zip archive. pyfiglet
comes with a file called fonts.zip which includes all of the default
fonts FIGlet comes with as well as the standard collection of user-
contributed fonts. By default, pyfiglet uses this for fonts. Specifying
a directory (on the commandline or in the Figlet() object) will override
this behavior. You may also specify a zipfile to use with -z or zipfile=PATH
in the Figlet() constructor.
If you wish to add/remove fonts or create your own font package, be aware
that there *must* be a folder in the root of the zipfile called "fonts". You
can examine the bunlded fonts.zip to see how it should be packaged.
AUTHOR
pyfiglet is a *port* of FIGlet, and much of the code is directly translated
......@@ -113,6 +100,14 @@ LICENSE
CHANGELOG
2015-05-27 0.7.4
#43 Don't leak file handles
2015-04-14 0.7.3
#41 Add newline and text wrapping support
2014-09-14 0.7.2
#35 Add this CHANGELOG
......
This diff is collapsed.
......@@ -6,49 +6,77 @@ import sys
from optparse import OptionParser
from pyfiglet import Figlet
from subprocess import Popen, PIPE
try:
from colorama import init
init(strip=not sys.stdout.isatty())
from termcolor import cprint
except:
def cprint(text, color):
print(text)
__version__ = '0.1'
def fail(text):
cprint(text, 'red')
def win(text):
cprint(text, 'green')
def dump(text):
for line in text.split('\n'):
print(repr(line))
def main():
parser = OptionParser(version=__version__)
parser.add_option('-s', '--show', action='store_true', default=False,
help='pause at each failure and compare output '
'(default: %default)')
opts, args = parser.parse_args()
f = Figlet()
ok = 0
fail = 0
failed = []
skip = ['runic'] # known bug..
for font in f.getFonts():
if font in skip:
continue
f.setFont(font=font)
outputPyfiglet = f.renderText('foo')
fontpath = os.path.join('pyfiglet', 'fonts', font)
class Test(object):
def __init__(self, opts):
self.opts = opts
self.ok = 0
self.fail = 0
self.failed = []
self.oked = []
self.skip = ['runic','pyramid','eftifont'] # known bug..
self.f = Figlet()
def outputUsingFigletorToilet(self, text, font, fontpath):
if os.path.isfile(fontpath + '.flf'):
cmd = ('figlet', '-d', 'pyfiglet/fonts', '-f', font, 'foo')
cmd = ('figlet', '-d', 'pyfiglet/fonts', '-f', font, text)
elif os.path.isfile(fontpath + '.tlf'):
cmd = ('toilet', '-d', 'pyfiglet/fonts', '-f', font, 'foo')
cmd = ('toilet', '-d', 'pyfiglet/fonts', '-f', font, text)
else:
raise Exception('Missing font file: '+fontpath)
p = Popen(cmd, bufsize=1, stdout=PIPE)
outputFiglet = p.communicate()[0].decode('UTF-8')
p = Popen(cmd, bufsize=4096, stdout=PIPE)
outputFiglet = p.communicate()[0].decode('utf8')
return outputFiglet
def validate_font_output(self, font, outputFiglet, outputPyfiglet):
if outputPyfiglet == outputFiglet:
win('[OK] %s' % font)
self.ok += 1
self.oked.append(font)
return
fail('[FAIL] %s' % font)
self.fail += 1
self.failed.append(font)
self.show_result(outputFiglet, outputPyfiglet, font)
def show_result(self, outputFiglet, outputPyfiglet, font):
if self.opts.show is True:
print('[PYTHON] *** %s\n\n' % font)
dump(outputPyfiglet)
print('[FIGLET] *** %s\n\n' % font)
dump(outputFiglet)
raw_input()
def check_font(self, text, font):
if font in self.skip:
return
fontpath = os.path.join('pyfiglet', 'fonts', font)
self.f.setFont(font=font)
outputPyfiglet = self.f.renderText(text)
outputFiglet = self.outputUsingFigletorToilet(text, font, fontpath)
# Our TLF rendering isn't perfect, yet
strict = os.path.isfile(fontpath + '.flf')
......@@ -56,27 +84,44 @@ def main():
outputPyfiglet = outputPyfiglet.strip('\n')
outputFiglet = outputFiglet.strip('\n')
if outputPyfiglet == outputFiglet:
print('[OK] %s' % font)
ok += 1
continue
self.validate_font_output(font, outputFiglet, outputPyfiglet)
print('[FAIL] %s' % font)
fail += 1
failed.append(font)
if opts.show is True:
print('[PYTHON] *** %s\n\n' % font)
dump(outputPyfiglet)
print('[FIGLET] *** %s\n\n' % font)
dump(outputFiglet)
raw_input()
def check_text(self, text):
for font in self.f.getFonts():
self.check_font(text, font)
def check_result(self):
print('OK = %d, FAIL = %d' % (self.ok, self.fail))
if len(self.failed) > 0:
print('FAILED = %s' % repr(self.failed))
return self.failed, self.oked
print('OK = %d, FAIL = %d' % (ok, fail))
if len(failed) > 0:
print('FAILED = %s' % repr(failed))
def banner(text):
cprint(Figlet().renderText(text), "blue")
def main():
parser = OptionParser(version=__version__)
return 0
parser.add_option('-s', '--show', action='store_true', default=False,
help='pause at each failure and compare output '
'(default: %default)')
opts, args = parser.parse_args()
test = Test(opts)
banner("TESTING one word")
test.check_text("foo")
banner("TESTING cut at space")
test.check_text("This is a very long text with many spaces and little words")
banner("TESTING cut at last char")
test.check_text("Averylongwordthatwillbecutatsomepoint I hope")
banner("TESTING explicit new line")
test.check_text("this text\nuse new line")
if len(test.check_result()[0]) == 0:
return 0
else:
return 1
if __name__ == '__main__':
......
__version__ = '0.7.2'
__version__ = '0.7.4'
#!/bin/bash
set -eux
pyfiglet -f $2 "$1" > /tmp/pyfiglet
figlet -d pyfiglet/fonts -f $2 "$1"> /tmp/figlet
vimdiff /tmp/figlet /tmp/pyfiglet
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment