How to use getdigest method in tox

Best Python code snippet using tox_python

test_objectsUFO.py

Source:test_objectsUFO.py Github

copy

Full Screen

1"""This test suite for ufo glyph methods"""2import unittest3import os4import tempfile5import shutil6from robofab.objects.objectsRF import RFont7from robofab.test.testSupport import getDemoFontPath8from robofab.pens.digestPen import DigestPointPen9from robofab.pens.adapterPens import SegmentToPointPen, FabToFontToolsPenAdapter10class ContourMethodsTestCase(unittest.TestCase):11 12 def setUp(self):13 self.font = RFont(getDemoFontPath())14 15 def testReverseContour(self):16 for glyph in self.font:17 pen = DigestPointPen()18 glyph.drawPoints(pen)19 digest1 = pen.getDigest()20 for contour in glyph:21 contour.reverseContour()22 contour.reverseContour()23 pen = DigestPointPen()24 glyph.drawPoints(pen)25 digest2 = pen.getDigest()26 self.assertEqual(digest1, digest2, "%r not the same after reversing twice" % glyph.name)27 28 def testStartSegment(self):29 for glyph in self.font:30 pen = DigestPointPen()31 glyph.drawPoints(pen)32 digest1 = pen.getDigest()33 for contour in glyph:34 contour.setStartSegment(2)35 contour.setStartSegment(-2)36 pen = DigestPointPen()37 glyph.drawPoints(pen)38 digest2 = pen.getDigest()39 self.assertEqual(digest1, digest2, "%r not the same after seting start segment twice" % glyph.name)40 41 def testAppendSegment(self):42 for glyph in self.font:43 pen = DigestPointPen()44 glyph.drawPoints(pen)45 digest1 = pen.getDigest()46 for contour in glyph:47 contour.insertSegment(2, "curve", [(100, 100), (200, 200), (300, 300)])48 contour.removeSegment(2)49 pen = DigestPointPen()50 glyph.drawPoints(pen)51 digest2 = pen.getDigest()52 self.assertEqual(digest1, digest2, "%r not the same after inserting and removing segment" % glyph.name)53 54class GlyphsMethodsTestCase(ContourMethodsTestCase):55 def testCopyGlyph(self):56 for glyph in self.font:57 pen = DigestPointPen()58 glyph.drawPoints(pen)59 digest1 = pen.getDigest()60 copy = glyph.copy()61 pen = DigestPointPen()62 copy.drawPoints(pen)63 digest2 = pen.getDigest()64 self.assertEqual(digest1, digest2, "%r not the same after copying" % glyph.name)65 self.assertEqual(glyph.lib, copy.lib, "%r's lib not the same after copying" % glyph.name)66 self.assertEqual(glyph.width, copy.width, "%r's width not the same after copying" % glyph.name)67 self.assertEqual(glyph.unicodes, copy.unicodes, "%r's unicodes not the same after copying" % glyph.name)68 def testMoveGlyph(self):69 for glyph in self.font:70 pen = DigestPointPen()71 glyph.drawPoints(pen)72 digest1 = pen.getDigest()73 glyph.move((100, 200))74 glyph.move((-100, -200))75 pen = DigestPointPen()76 glyph.drawPoints(pen)77 digest2 = pen.getDigest()78 self.assertEqual(digest1, digest2, "%r not the same after moving twice" % glyph.name)79 80 def testScaleGlyph(self):81 for glyph in self.font:82 pen = DigestPointPen()83 glyph.drawPoints(pen)84 digest1 = pen.getDigest()85 glyph.scale((2, 2))86 glyph.scale((.5, .5))87 pen = DigestPointPen()88 glyph.drawPoints(pen)89 digest2 = pen.getDigest()90 self.assertEqual(digest1, digest2, "%r not the same after scaling twice" % glyph.name)91 def testSegmentPenInterface(self):92 for glyph in self.font:93 digestPen = DigestPointPen(ignoreSmoothAndName=True)94 pen = SegmentToPointPen(digestPen)95 glyph.draw(pen)96 digest1 = digestPen.getDigest()97 digestPen = DigestPointPen(ignoreSmoothAndName=True)98 glyph.drawPoints(digestPen)99 digest2 = digestPen.getDigest()100 self.assertEqual(digest1, digest2, "%r not the same for gl.draw() and gl.drawPoints()" % glyph.name)101 def testFabPenCompatibility(self):102 for glyph in self.font:103 digestPen = DigestPointPen(ignoreSmoothAndName=True)104 pen = FabToFontToolsPenAdapter(SegmentToPointPen(digestPen))105 glyph.draw(pen)106 digest1 = digestPen.getDigest()107 digestPen = DigestPointPen(ignoreSmoothAndName=True)108 glyph.drawPoints(digestPen)109 digest2 = digestPen.getDigest()110 self.assertEqual(digest1, digest2, "%r not the same for gl.draw() and gl.drawPoints()" % glyph.name)111 112 def testComponentTransformations(self):113 from robofab.objects.objectsRF import RComponent114 name = "baseGlyphName"115 c = RComponent(name, transform=(1,0,0,1,0,0))116 # get values117 assert c.baseGlyph == "baseGlyphName"118 assert c.transformation == c.transformation119 assert c.scale == (1,1)120 assert c.offset == (0,0)121 # set values122 c.offset = (12,34)123 assert c.transformation == (1, 0, 0, 1, 12, 34)124 c.offset = (0,0)125 assert c.transformation == (1,0,0,1,0,0)126 c.scale = (12,34)127 assert c.transformation == (12, 0, 0, 34, 0, 0)128class SaveTestCase(ContourMethodsTestCase):129 def testSaveAs(self):130 path = tempfile.mktemp(".ufo")131 try:132 keys1 = self.font.keys()133 self.font.save(path)134 keys2 = self.font.keys()135 keys1.sort()136 keys2.sort()137 self.assertEqual(keys1, keys2)138 self.assertEqual(self.font.path, path)139 font2 = RFont(path)140 keys3 = font2.keys()141 keys3.sort()142 self.assertEqual(keys1, keys3)143 finally:144 if os.path.exists(path):145 shutil.rmtree(path)146 def testSaveAs2(self):147 path = tempfile.mktemp(".ufo")148 # copy a glyph149 self.font["X"] = self.font["a"].copy()150# self.assertEqual(self.font["X"].name, "X")151 # remove a glyph152 self.font.removeGlyph("a")153 keys1 = self.font.keys()154 try:155 self.font.save(path)156 self.assertEqual(self.font.path, path)157 keys2 = self.font.keys()158 keys1.sort()159 keys2.sort()160 self.assertEqual(keys1, keys2)161 font2 = RFont(path)162 keys3 = font2.keys()163 keys3.sort()164 self.assertEqual(keys1, keys3)165 finally:166 if os.path.exists(path):167 shutil.rmtree(path)168 def testCustomFileNameScheme(self):169 path = tempfile.mktemp(".ufo")170 libKey = "org.robofab.glyphNameToFileNameFuncName"171 self.font.lib[libKey] = "robofab.test.test_objectsUFO.testGlyphNameToFileName"172 try:173 self.font.save(path)174 self.assertEqual(os.path.exists(os.path.join(path,175 "glyphs", "test_a.glif")), True)176 finally:177 if os.path.exists(path):178 shutil.rmtree(path)179def testGlyphNameToFileName(glyphName, glyphSet):180 from robofab.glifLib import glyphNameToFileName181 return "test_" + glyphNameToFileName(glyphName, glyphSet)182if __name__ == "__main__":183 from robofab.test.testSupport import runTests...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful