| 1 |
""" |
| 2 |
Copyright (C) 2013 Mayank Jha <[email protected]> |
| 3 |
|
| 4 |
This library is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU Lesser General Public License as published |
| 6 |
by the Free Software Foundation; either version 2.1 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
""" |
| 17 |
""" |
| 18 |
Copyright (C) 2013 Mayank Jha <[email protected]> |
| 19 |
|
| 20 |
This library is free software; you can redistribute it and/or modify |
| 21 |
it under the terms of the GNU Lesser General Public License as published |
| 22 |
by the Free Software Foundation; either version 2.1 of the License, or |
| 23 |
(at your option) any later version. |
| 24 |
|
| 25 |
This program is distributed in the hope that it will be useful, |
| 26 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
GNU General Public License for more details. |
| 29 |
|
| 30 |
You should have received a copy of the GNU Lesser General Public License |
| 31 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 32 |
""" |
| 33 |
from fc.FontCompare import FontCompare |
| 34 |
from fc.BitmapHandler import BitmapCompare |
| 35 |
from fc.GlyphConsistency import GlyphConsistency |
| 36 |
from fc.mockify import MockFont |
| 37 |
import shelve |
| 38 |
import pkg_resources |
| 39 |
import shutil |
| 40 |
import unittest |
| 41 |
import fontforge |
| 42 |
|
| 43 |
thefile = pkg_resources.resource_filename("fc","data/mockfile.mcy") |
| 44 |
shutil.copy(thefile,"/var/tmp/tmp.mcy") |
| 45 |
mock_font = shelve.open("/var/tmp/tmp.mcy") |
| 46 |
mockfont = mock_font["font"] |
| 47 |
mock_font.close() |
| 48 |
|
| 49 |
class Basictests(unittest.TestCase): |
| 50 |
def testFontCompare(self): |
| 51 |
cm = FontCompare() |
| 52 |
testfont = fontforge.open("unittests/lohit.ttf") |
| 53 |
basic = cm.font_basiccompare(testfont,mockfont) |
| 54 |
bastest=1 |
| 55 |
for tup in basic: |
| 56 |
if tup[1]!=10: |
| 57 |
bastest=0 |
| 58 |
self.failUnless(bastest) |
| 59 |
testfont = fontforge.open("unittests/lohit.ttf") |
| 60 |
bold = cm.font_facecompare(testfont,mockfont,(0x900,0x97f),\ |
| 61 |
600,12,1,"bold") |
| 62 |
testfont = fontforge.open("unittests/lohit.ttf") |
| 63 |
italic = cm.font_facecompare(testfont,mockfont,(0x900,0x97f),\ |
| 64 |
600,12,1,"italic") |
| 65 |
testfont = fontforge.open("unittests/lohit.ttf") |
| 66 |
normal = cm.font_facecompare(testfont,mockfont,(0x900,0x97f),\ |
| 67 |
600,12,1,"normal") |
| 68 |
test = 1 |
| 69 |
print len(normal) |
| 70 |
for tup in bold: |
| 71 |
if tup[1]==100 or tup[1]==0: |
| 72 |
test1=1 |
| 73 |
break |
| 74 |
self.failUnless(test) |
| 75 |
test = 0 |
| 76 |
for tup in italic: |
| 77 |
if tup[1]==100 or tup[1]==0: |
| 78 |
test=1 |
| 79 |
break |
| 80 |
self.failUnless(test is 1) |
| 81 |
test = 0 |
| 82 |
for tup in normal: |
| 83 |
if tup[1]==100 or tup[1]==0: |
| 84 |
test=1 |
| 85 |
break |
| 86 |
self.failUnless(test is 1) |
| 87 |
test = 0 |
| 88 |
if len(normal) == len(bold) == len(italic): |
| 89 |
test = 1 |
| 90 |
self.failUnless(test is 1) |
| 91 |
|
| 92 |
def testGlyphConsistency(self): |
| 93 |
cm = GlyphConsistency() |
| 94 |
testfont = fontforge.open("unittests/lohit.ttf") |
| 95 |
test1 = cm.glyph_basicConsistency(testfont,(0x900,0x97f)) |
| 96 |
testfont = fontforge.open("unittests/lohit.ttf") |
| 97 |
test2 = cm.glyph_basicset_consistency(testfont,(0x900,0x97f)) |
| 98 |
testfont = fontforge.open("unittests/lohit.ttf") |
| 99 |
test3 = cm.glyph_round_consistency(testfont,(0x900,0x97f),50) |
| 100 |
|
| 101 |
test = (0 <= test1[0][1] <= 10) |
| 102 |
self.failUnless(test) |
| 103 |
test2 = (0 <= test2 <= 10) |
| 104 |
self.failUnless(test2) |
| 105 |
test3 = (0 <= test3 <= 10) |
| 106 |
self.failUnless(test3) |
| 107 |
|
| 108 |
""" |
| 109 |
unittests for DocCompare not required. |
| 110 |
""" |
| 111 |
def main(): |
| 112 |
unittest.main() |
| 113 |
|
| 114 |
if __name__ == '__main__': |
| 115 |
main() |