Beispiel #1
0
 def test_save_new_font_to_exsisting_directory(self):
     for ufo in ("TestFont.ufo", "TestFont.ufoz"):
         path = makeTestFontCopy(getTestFontPath(ufo))
         font = Font()
         try:
             self.assertTrue(os.path.exists(path))
             font.save(path)
             self.assertTrue(os.path.isdir(path))
         finally:
             font.close()
             tearDownTestFontCopy(path)
Beispiel #2
0
    def test_save_ufo3z_as_ufo2(self):
        # https://github.com/robotools/defcon/issues/296
        font = Font()
        font.layers.defaultLayer.name = "a-custom-layer-name"
        font.newLayer("a-new-layer")

        with tempfile.TemporaryDirectory() as root:
            path_ufo3 = os.path.join(root, "three.ufo")
            font.save(path_ufo3, formatVersion=3, structure="zip")
            font.close()

            path_ufo2 = os.path.join(root, "two.ufo")

            with Font(path_ufo3) as font_ufo2:
                font_ufo2.save(path_ufo2, formatVersion=2)
Beispiel #3
0
 def test_save_same_path(self):
     for ufo in (u"TestFont.ufo", u"TestFont.ufoz"):
         path = makeTestFontCopy(getTestFontPath(ufo))
         isZip = zipfile.is_zipfile(path)
         font = Font(path)
         try:
             font = Font(path)
             font.save(path)
             if isZip:
                 self.assertTrue(zipfile.is_zipfile(path))
             else:
                 self.assertTrue(os.path.isdir(path))
         finally:
             font.close()
             tearDownTestFontCopy(path)
 def test_save_as(self):
     for ufo in (u"TestFont.ufo", u"TestFont.ufoz"):
         path = getTestFontPath(ufo)
         font = Font(path)
         origFileStructure = font.ufoFileStructure
         saveAsPath = getTestFontCopyPath(path)
         self.assertFalse(os.path.exists(saveAsPath))
         font.save(saveAsPath)
         try:
             fileNames = sorted([
                 fs.path.basename(m.path)
                 for m in UFOReader(saveAsPath).fs.glob("glyphs/*.glif")
             ])
             self.assertEqual(fileNames, ["A_.glif", "B_.glif", "C_.glif"])
             self.assertEqual(font.path, saveAsPath)
             self.assertEqual(origFileStructure, font.ufoFileStructure)
         finally:
             font.close()
             tearDownTestFontCopy(saveAsPath)
 def test_save_ufoz(self):
     path = getTestFontPath()
     tmpdir = tempfile.mkdtemp()
     dest = os.path.join(tmpdir, "TestFont.ufoz")
     font = Font(path)
     try:
         self.assertFalse(os.path.exists(dest))
         self.assertEqual(font.path, path)
         font.save(dest, structure="zip")
         self.assertTrue(os.path.exists(dest))
         self.assertTrue(zipfile.is_zipfile(dest))
         self.assertEqual(font.path, dest)
         self.assertEqual(font.ufoFileStructure, UFOFileStructure.ZIP)
         fileNames = sorted([
             fs.path.basename(m.path)
             for m in UFOReader(dest).fs.glob("glyphs/*.glif")
         ])
         self.assertEqual(fileNames, ["A_.glif", "B_.glif", "C_.glif"])
     finally:
         font.close()
         shutil.rmtree(tmpdir)