示例#1
0
    def test_delitem(self):
        font = Font(makeTestFontCopy())
        path = os.path.join(font.path, "glyphs.public.background")
        self.assertTrue(os.path.exists(path))
        layers = font.layers
        del layers["public.background"]
        layers.dirty = True
        self.assertEqual(layers.layerOrder, ["public.default", "Layer 1"])
        self.assertNotIn("public.background", layers)

        self.assertEqual(len(layers), 2)
        with self.assertRaisesRegex(KeyError, "public.background"):
            layers["public.background"]
        font.save()
        path = os.path.join(font.path, "glyphs.public.background")
        self.assertFalse(os.path.exists(path))
        tearDownTestFontCopy()

        font = Font(makeTestFontCopy())
        path = os.path.join(font.path, "glyphs.public.background")
        del font.layers["public.background"]
        layer = font.newLayer("public.background")
        layer.newGlyph("B")
        font.save()
        self.assertFalse(os.path.exists(os.path.join(path, "A_.glif")))
        self.assertTrue(os.path.exists(os.path.join(path, "B_.glif")))
示例#2
0
    def test_delitem(self):
        font = Font(makeTestFontCopy())
        path = os.path.join(font.path, "glyphs.public.background")
        self.assertTrue(os.path.exists(path))
        layers = font.layers
        del layers["public.background"]
        layers.dirty = True
        self.assertEqual(layers.layerOrder, ["public.default", "Layer 1"])
        self.assertNotIn("public.background", layers)

        self.assertEqual(len(layers), 2)
        with self.assertRaisesRegex(KeyError, "public.background"):
            layers["public.background"]
        font.save()
        path = os.path.join(font.path, "glyphs.public.background")
        self.assertFalse(os.path.exists(path))
        tearDownTestFontCopy()

        font = Font(makeTestFontCopy())
        path = os.path.join(font.path, "glyphs.public.background")
        del font.layers["public.background"]
        layer = font.newLayer("public.background")
        layer.newGlyph("B")
        font.save()
        self.assertFalse(os.path.exists(os.path.join(path, "A_.glif")))
        self.assertTrue(os.path.exists(os.path.join(path, "B_.glif")))
示例#3
0
 def test_testForExternalChanges_change_layer_order(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         fileSystem = openTestFontAsFileSystem(path)
         fs.copy.copy_dir(fileSystem, "glyphs", fileSystem, "glyphs.test")
         with fileSystem.open(u"layercontents.plist", "rb") as f:
             contents = load(f)
         contents.append(("test", "glyphs.test"))
         with fileSystem.open(u"layercontents.plist", "wb") as f:
             dump(contents, f)
         closeTestFontAsFileSystem(fileSystem, path)
         font = Font(path)
         fileSystem = openTestFontAsFileSystem(path)
         with fileSystem.open(u"layercontents.plist", "rb") as f:
             contents = load(f)
         contents.reverse()
         with fileSystem.open(u"layercontents.plist", "wb") as f:
             dump(contents, f)
         closeTestFontAsFileSystem(fileSystem, path)
         reader = UFOReader(path)
         self.assertEqual(font.layers.testForExternalChanges(reader),
                          {"deleted": [], "added": [], "modified": {},
                           "defaultLayer": False, "order": True})
         tearDownTestFontCopy(font.path)
示例#4
0
 def test_testForExternalChanges_remove_a_layer(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         fileSystem = openTestFontAsFileSystem(path)
         fs.copy.copy_dir(fileSystem, "glyphs", fileSystem, "glyphs.test")
         with fileSystem.open(u"layercontents.plist", "rb") as f:
             contents = load(f)
         contents.append(("test", "glyphs.test"))
         with fileSystem.open(u"layercontents.plist", "wb") as f:
             dump(contents, f)
         closeTestFontAsFileSystem(fileSystem, path)
         font = Font(path)
         fileSystem = openTestFontAsFileSystem(path)
         fileSystem.removetree(u"glyphs.test")
         with fileSystem.open(u"layercontents.plist", "rb") as f:
             contents = load(f)
         del contents[-1]
         with fileSystem.open(u"layercontents.plist", "wb") as f:
             dump(contents, f)
         closeTestFontAsFileSystem(fileSystem, path)
         reader = UFOReader(path)
         self.assertEqual(
             font.layers.testForExternalChanges(reader)["deleted"],
             ["test"])
         tearDownTestFontCopy(font.path)
示例#5
0
    def test_testForExternalChanges_change_default_layer(self):
        for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
            path = getTestFontPath(ufo)
            path = makeTestFontCopy(path)

            fileSystem = openTestFontAsFileSystem(path)
            fs.copy.copy_dir(fileSystem, "glyphs", fileSystem, "glyphs.test")
            contents = [("foo", "glyphs"), ("test", "glyphs.test")]
            with fileSystem.open(u"layercontents.plist", "wb") as f:
                dump(contents, f)
            closeTestFontAsFileSystem(fileSystem, path)
            font = Font(path)
            fileSystem = openTestFontAsFileSystem(path)
            contents = [("foo", "glyphs.test"), ("test", "glyphs")]
            with fileSystem.open(u"layercontents.plist", "wb") as f:
                dump(contents, f)
            closeTestFontAsFileSystem(fileSystem, path)
            reader = UFOReader(path)
            self.assertEqual(
                font.layers.testForExternalChanges(reader), {
                    "deleted": [],
                    "added": [],
                    "modified": {},
                    "defaultLayer": True,
                    "order": False
                })
            tearDownTestFontCopy(font.path)
示例#6
0
 def test_testForExternalChanges_change_layer_order(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         fileSystem = openTestFontAsFileSystem(path)
         fs.copy.copy_dir(fileSystem, "glyphs", fileSystem, "glyphs.test")
         with fileSystem.open(u"layercontents.plist", "rb") as f:
             contents = load(f)
         contents.append(("test", "glyphs.test"))
         with fileSystem.open(u"layercontents.plist", "wb") as f:
             dump(contents, f)
         closeTestFontAsFileSystem(fileSystem, path)
         with Font(path) as font:
             fileSystem = openTestFontAsFileSystem(path)
             with fileSystem.open(u"layercontents.plist", "rb") as f:
                 contents = load(f)
             contents.reverse()
             with fileSystem.open(u"layercontents.plist", "wb") as f:
                 dump(contents, f)
             closeTestFontAsFileSystem(fileSystem, path)
             with UFOReader(path) as reader:
                 self.assertEqual(font.layers.testForExternalChanges(reader),
                                  {"deleted": [], "added": [], "modified": {},
                                   "defaultLayer": False, "order": True})
         tearDownTestFontCopy(font.path)
示例#7
0
 def test_delitem_glyph_dirty(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         glyph = font["A"]
         glyph.dirty = True
         fileSystem = openTestFontAsFileSystem(path)
         glyphPath = fs.path.join("glyphs", "A_.glif")
         fileSystem.remove(glyphPath)
         contentsPath = fs.path.join("glyphs", "contents.plist")
         with fileSystem.open(contentsPath, "rb") as f:
             plist = load(f)
         del plist["A"]
         with fileSystem.open(contentsPath, "wb") as f:
             dump(plist, f)
         closeTestFontAsFileSystem(fileSystem, path)
         r = font.testForExternalChanges()
         self.assertEqual(r["deletedGlyphs"], ["A"])
         del font["A"]
         font.save()
         fileSystem = openTestFontAsFileSystem(path)
         self.assertFalse(fileSystem.exists(glyphPath))
         closeTestFontAsFileSystem(fileSystem, path)
         tearDownTestFontCopy(font.path)
示例#8
0
 def test_delitem_glyph_dirty(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         glyph = font["A"]
         glyph.dirty = True
         fileSystem = openTestFontAsFileSystem(path)
         glyphPath = fs.path.join("glyphs", "A_.glif")
         fileSystem.remove(glyphPath)
         contentsPath = fs.path.join("glyphs", "contents.plist")
         with fileSystem.open(contentsPath, "rb") as f:
             plist = load(f)
         del plist["A"]
         with fileSystem.open(contentsPath, "wb") as f:
             dump(plist, f)
         closeTestFontAsFileSystem(fileSystem, path)
         r = font.testForExternalChanges()
         self.assertEqual(r["deletedGlyphs"], ["A"])
         del font["A"]
         font.save()
         fileSystem = openTestFontAsFileSystem(path)
         self.assertFalse(fileSystem.exists(glyphPath))
         closeTestFontAsFileSystem(fileSystem, path)
         tearDownTestFontCopy(font.path)
示例#9
0
 def test_testForExternalChanges_remove_a_layer(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         fileSystem = openTestFontAsFileSystem(path)
         fs.copy.copy_dir(fileSystem, "glyphs", fileSystem, "glyphs.test")
         with fileSystem.open(u"layercontents.plist", "rb") as f:
             contents = load(f)
         contents.append(("test", "glyphs.test"))
         with fileSystem.open(u"layercontents.plist", "wb") as f:
             dump(contents, f)
         closeTestFontAsFileSystem(fileSystem, path)
         font = Font(path)
         fileSystem = openTestFontAsFileSystem(path)
         fileSystem.removetree(u"glyphs.test")
         with fileSystem.open(u"layercontents.plist", "rb") as f:
             contents = load(f)
         del contents[-1]
         with fileSystem.open(u"layercontents.plist", "wb") as f:
             dump(contents, f)
         closeTestFontAsFileSystem(fileSystem, path)
         reader = UFOReader(path)
         self.assertEqual(font.layers.testForExternalChanges(reader)["deleted"],
                          ["test"])
         tearDownTestFontCopy(font.path)
示例#10
0
 def test_testForExternalChanges_change_layer_order(self):
     path = getTestFontPath("TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     shutil.copytree(os.path.join(path, "glyphs"),
                     os.path.join(path, "glyphs.test"))
     with open(os.path.join(path, "layercontents.plist"), "rb") as f:
         contents = load(f)
     contents.append(("test", "glyphs.test"))
     with open(os.path.join(path, "layercontents.plist"), "wb") as f:
         dump(contents, f)
     font = Font(path)
     with open(os.path.join(path, "layercontents.plist"), "rb") as f:
         contents = load(f)
     contents.reverse()
     with open(os.path.join(path, "layercontents.plist"), "wb") as f:
         dump(contents, f)
     reader = UFOReader(path)
     self.assertEqual(
         font.layers.testForExternalChanges(reader), {
             "deleted": [],
             "added": [],
             "modified": {},
             "defaultLayer": False,
             "order": True
         })
     tearDownTestFontCopy(font.path)
示例#11
0
 def test_testExternalChanges_remove_on_disk_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     os.remove(os.path.join(path, "images", "image 1.png"))
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      ([], [], ["image 1.png"]))
     tearDownTestFontCopy()
示例#12
0
 def test_testExternalChanges_modify_in_memory_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     font.images["image 1.png"] = pngSignature + b"blah"
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      ([], [], []))
     tearDownTestFontCopy()
示例#13
0
 def test_testForExternalChanges_add_in_memory_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     font.data["com.typesupply.defcon.test.file2"] = "blah"
     reader = UFOReader(path)
     self.assertEqual(font.data.testForExternalChanges(reader),
                      ([], [], []))
     tearDownTestFontCopy()
示例#14
0
 def test_save_in_place_different_format(self):
     path = makeTestFontCopy()
     font = Font(path)
     self.assertEqual(font.ufoFormatVersion, 3)
     self.assertEqual(font.ufoFormatVersionTuple, (3, 0))
     font.save(formatVersion=2)
     self.assertEqual(font.ufoFormatVersion, 2)
     self.assertEqual(font.ufoFormatVersionTuple, (2, 0))
示例#15
0
 def test_testForExternalChanges_add_in_memory_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     font.data["com.typesupply.defcon.test.file2"] = "blah"
     reader = UFOReader(path)
     self.assertEqual(font.data.testForExternalChanges(reader),
                      ([], [], []))
     tearDownTestFontCopy()
示例#16
0
 def test_testExternalChanges_remove_on_disk_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     os.remove(os.path.join(path, "images", "image 1.png"))
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      ([], [], ["image 1.png"]))
     tearDownTestFontCopy()
示例#17
0
 def test_testExternalChanges_remove_in_memory_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     del font.images["image 1.png"]
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      ([], [], []))
     tearDownTestFontCopy()
示例#18
0
 def test_testExternalChanges_modify_in_memory_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     font.images["image 1.png"] = pngSignature + b"blah"
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      ([], [], []))
     tearDownTestFontCopy()
示例#19
0
 def test_testExternalChanges_remove_in_memory_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     del font.images["image 1.png"]
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      ([], [], []))
     tearDownTestFontCopy()
示例#20
0
 def test_testForExternalChanges(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         with Font(path) as font, UFOReader(path) as reader:
             self.assertEqual(font.layers.testForExternalChanges(reader),
                              {"deleted": [], "added": [], "modified": {},
                               "defaultLayer": False, "order": False})
         tearDownTestFontCopy(font.path)
示例#21
0
 def test_testExternalChanges_remove_in_memory_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         with Font(path) as font, UFOReader(path) as reader:
             del font.images["image 1.png"]
             self.assertEqual(font.images.testForExternalChanges(reader),
                              ([], [], []))
         tearDownTestFontCopy(font.path)
示例#22
0
 def test_save(self):
     path = makeTestFontCopy()
     font = Font(path)
     for glyph in font:
         glyph.dirty = True
     font.save()
     fileNames = glob.glob(os.path.join(path, 'glyphs', '*.glif'))
     fileNames = [os.path.basename(fileName) for fileName in fileNames]
     self.assertEqual(sorted(fileNames), ["A_.glif", "B_.glif", "C_.glif"])
示例#23
0
 def test_testForExternalChanges(self):
     path = getTestFontPath("TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     font = Font(path)
     reader = UFOReader(path)
     self.assertEqual(font.layers.testForExternalChanges(reader),
                      {"deleted": [], "added": [], "modified": {},
                       "defaultLayer": False, "order": False})
     tearDownTestFontCopy(font.path)
示例#24
0
 def test_testForExternalChanges(self):
     path = getTestFontPath("TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     font = Font(path)
     reader = UFOReader(path)
     self.assertEqual(font.layers.testForExternalChanges(reader),
                      {"deleted": [], "added": [], "modified": {},
                       "defaultLayer": False, "order": False})
     tearDownTestFontCopy(font.path)
示例#25
0
 def test_save(self):
     path = makeTestFontCopy()
     font = Font(path)
     for glyph in font:
         glyph.dirty = True
     font.save()
     fileNames = glob.glob(os.path.join(path, 'glyphs', '*.glif'))
     fileNames = [os.path.basename(fileName) for fileName in fileNames]
     self.assertEqual(sorted(fileNames), ["A_.glif", "B_.glif", "C_.glif"])
     tearDownTestFontCopy()
示例#26
0
 def test_save_new_font_to_exsisting_directory(self):
     for ufo in ("TestFont.ufo", "TestFont.ufoz"):
         path = makeTestFontCopy(getTestFontPath(ufo))
         try:
             self.assertTrue(os.path.exists(path))
             font = Font()
             font.save(path)
             self.assertTrue(os.path.isdir(path))
         finally:
             tearDownTestFontCopy(path)
示例#27
0
 def test_testForExternalChanges_remove_in_memory_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         with Font(path) as font:
             del font.data["com.typesupply.defcon.test.file"]
             with UFOReader(path) as reader:
                 self.assertEqual(font.data.testForExternalChanges(reader),
                                  ([], [], []))
         tearDownTestFontCopy(font.path)
示例#28
0
 def test_save_new_font_to_exsisting_directory(self):
     for ufo in ("TestFont.ufo", "TestFont.ufoz"):
         path = makeTestFontCopy(getTestFontPath(ufo))
         try:
             self.assertTrue(os.path.exists(path))
             font = Font()
             font.save(path)
             self.assertTrue(os.path.isdir(path))
         finally:
             tearDownTestFontCopy(path)
示例#29
0
 def test_testForExternalChanges_modify_in_memory_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         reader = UFOReader(path)
         font.data["com.typesupply.defcon.test.file"] = "blah"
         self.assertEqual(font.data.testForExternalChanges(reader),
                          ([], [], []))
         tearDownTestFontCopy(font.path)
示例#30
0
 def test_save_same_path_different_structure(self):
     for ufo in ("TestFont.ufo", "TestFont.ufoz"):
         path = makeTestFontCopy(getTestFontPath(ufo))
         isZip = zipfile.is_zipfile(path)
         with Font(path) as font:
             with self.assertRaisesRegex(
                     DefconError,
                     "Can't save font in-place with a different structure"):
                 font.save(path, structure="package" if isZip else "zip")
         tearDownTestFontCopy(path)
示例#31
0
 def test_testExternalChanges_remove_in_memory_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         del font.images["image 1.png"]
         reader = UFOReader(path)
         self.assertEqual(font.images.testForExternalChanges(reader),
                          ([], [], []))
         tearDownTestFontCopy(font.path)
示例#32
0
 def test_testForExternalChanges_add_in_memory_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         font.data["com.typesupply.defcon.test.file2"] = "blah"
         reader = UFOReader(path)
         self.assertEqual(font.data.testForExternalChanges(reader),
                          ([], [], []))
         tearDownTestFontCopy(font.path)
示例#33
0
 def test_testExternalChanges_modify_in_memory_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         font.images["image 1.png"] = pngSignature + b"blah"
         reader = UFOReader(path)
         self.assertEqual(font.images.testForExternalChanges(reader),
                          ([], [], []))
         tearDownTestFontCopy(font.path)
示例#34
0
 def test_testExternalChanges_add_on_disk_and_scan(self):
     import shutil
     path = makeTestFontCopy()
     font = Font(path)
     source = os.path.join(path, "images", "image 1.png")
     dest = os.path.join(path, "images", "image 3.png")
     shutil.copy(source, dest)
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      ([], ["image 3.png"], []))
     tearDownTestFontCopy()
示例#35
0
 def test_testExternalChanges_add_on_disk_and_scan(self):
     import shutil
     path = makeTestFontCopy()
     font = Font(path)
     source = os.path.join(path, "images", "image 1.png")
     dest = os.path.join(path, "images", "image 3.png")
     shutil.copy(source, dest)
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      ([], ["image 3.png"], []))
     tearDownTestFontCopy()
示例#36
0
 def test_testForExternalChanges_add_on_disk_and_scan(self):
     import shutil
     path = makeTestFontCopy()
     font = Font(path)
     reader = UFOReader(path)
     source = os.path.join(path, "data", "com.typesupply.defcon.test.file")
     dest = os.path.join(path, "data", "com.typesupply.defcon.test.file2")
     shutil.copy(source, dest)
     self.assertEqual(font.data.testForExternalChanges(reader),
                      ([], ["com.typesupply.defcon.test.file2"], []))
     tearDownTestFontCopy()
示例#37
0
 def test_testForExternalChanges_remove_on_disk_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     reader = UFOReader(path)
     # image = font.data["com.typesupply.defcon.test.file"]
     font.data["com.typesupply.defcon.test.file"]
     os.remove(os.path.join(path, "data",
                            "com.typesupply.defcon.test.file"))
     self.assertEqual(font.data.testForExternalChanges(reader),
                      ([], [], ["com.typesupply.defcon.test.file"]))
     tearDownTestFontCopy()
示例#38
0
 def test_testForExternalChanges_add_on_disk_and_scan(self):
     import shutil
     path = makeTestFontCopy()
     font = Font(path)
     reader = UFOReader(path)
     source = os.path.join(path, "data", "com.typesupply.defcon.test.file")
     dest = os.path.join(path, "data", "com.typesupply.defcon.test.file2")
     shutil.copy(source, dest)
     self.assertEqual(font.data.testForExternalChanges(reader),
                      ([], ["com.typesupply.defcon.test.file2"], []))
     tearDownTestFontCopy()
示例#39
0
 def test_testForExternalChanges_remove_on_disk_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     reader = UFOReader(path)
     # image = font.data["com.typesupply.defcon.test.file"]
     font.data["com.typesupply.defcon.test.file"]
     os.remove(os.path.join(path, "data",
                            "com.typesupply.defcon.test.file"))
     self.assertEqual(font.data.testForExternalChanges(reader),
                      ([], [], ["com.typesupply.defcon.test.file"]))
     tearDownTestFontCopy()
示例#40
0
 def test_testExternalChanges_remove_on_disk_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         fileSystem = openTestFontAsFileSystem(font.path)
         fileSystem.remove(fs.path.join("images", "image 1.png"))
         closeTestFontAsFileSystem(fileSystem, font.path)
         reader = UFOReader(path)
         self.assertEqual(font.images.testForExternalChanges(reader),
                          ([], [], ["image 1.png"]))
         tearDownTestFontCopy(font.path)
示例#41
0
 def test_testExternalChanges_remove_on_disk_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         fileSystem = openTestFontAsFileSystem(font.path)
         fileSystem.remove(fs.path.join("images", "image 1.png"))
         closeTestFontAsFileSystem(fileSystem, font.path)
         reader = UFOReader(path)
         self.assertEqual(font.images.testForExternalChanges(reader),
                          ([], [], ["image 1.png"]))
         tearDownTestFontCopy(font.path)
示例#42
0
    def test_unreferenced_images(self):
        path = getTestFontPath()
        font = Font(path)
        self.assertEqual(font.images.unreferencedFileNames, ["image 2.png"])

        path = makeTestFontCopy()
        font = Font(path)
        font.save(removeUnreferencedImages=True)
        p = os.path.join(path, "images", "image 1.png")
        self.assertTrue(os.path.exists(p))
        p = os.path.join(path, "images", "image 2.png")
        self.assertFalse(os.path.exists(p))
        tearDownTestFontCopy()
示例#43
0
 def test_write(self):
     path = makeTestFontCopy()
     font = Font(path)
     font.images["image 3.png"] = font.images["image 1.png"]
     del font.images["image 1.png"]
     font.save()
     p = os.path.join(path, "images", "image 1.png")
     self.assertFalse(os.path.exists(p))
     p = os.path.join(path, "images", "image 2.png")
     self.assertTrue(os.path.exists(p))
     p = os.path.join(path, "images", "image 3.png")
     self.assertTrue(os.path.exists(p))
     tearDownTestFontCopy()
示例#44
0
 def test_reloadImages(self):
     path = makeTestFontCopy()
     font = Font(path)
     image = font.images["image 1.png"]
     imagePath = os.path.join(path, "images", "image 1.png")
     newImageData = pngSignature + b"blah"
     f = open(imagePath, "wb")
     f.write(newImageData)
     f.close()
     font.images.reloadImages(["image 1.png"])
     image = font.images["image 1.png"]
     self.assertEqual(image, newImageData)
     tearDownTestFontCopy()
示例#45
0
 def test_write(self):
     path = makeTestFontCopy()
     font = Font(path)
     font.images["image 3.png"] = font.images["image 1.png"]
     del font.images["image 1.png"]
     font.save()
     p = os.path.join(path, "images", "image 1.png")
     self.assertFalse(os.path.exists(p))
     p = os.path.join(path, "images", "image 2.png")
     self.assertTrue(os.path.exists(p))
     p = os.path.join(path, "images", "image 3.png")
     self.assertTrue(os.path.exists(p))
     tearDownTestFontCopy()
示例#46
0
    def test_unreferenced_images(self):
        path = getTestFontPath()
        font = Font(path)
        self.assertEqual(font.images.unreferencedFileNames, ["image 2.png"])

        path = makeTestFontCopy()
        font = Font(path)
        font.save(removeUnreferencedImages=True)
        p = os.path.join(path, "images", "image 1.png")
        self.assertTrue(os.path.exists(p))
        p = os.path.join(path, "images", "image 2.png")
        self.assertFalse(os.path.exists(p))
        tearDownTestFontCopy()
示例#47
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)
         try:
             font = Font(path)
             font.save(path)
             if isZip:
                 self.assertTrue(zipfile.is_zipfile(path))
             else:
                 self.assertTrue(os.path.isdir(path))
         finally:
             tearDownTestFontCopy(path)
示例#48
0
 def test_reloadLayers_layerinfo(self):
     path = getTestFontPath(u"TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     font = Font(path)
     p = os.path.join(path, "glyphs", "layerinfo.plist")
     data = {"lib": {}}
     data["lib"]["testForExternalChanges.test"] = 1
     with open(p, "wb") as f:
         dump(data, f)
     font.reloadLayers(dict(layers={"public.default": dict(info=True)}))
     self.assertEqual(font.layers["public.default"].lib,
                      {"testForExternalChanges.test": 1})
     tearDownTestFontCopy(font.path)
示例#49
0
 def test_reloadImages(self):
     path = makeTestFontCopy()
     font = Font(path)
     image = font.images["image 1.png"]
     imagePath = os.path.join(path, "images", "image 1.png")
     newImageData = pngSignature + b"blah"
     f = open(imagePath, "wb")
     f.write(newImageData)
     f.close()
     font.images.reloadImages(["image 1.png"])
     image = font.images["image 1.png"]
     self.assertEqual(image, newImageData)
     tearDownTestFontCopy()
示例#50
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)
         try:
             font = Font(path)
             font.save(path)
             if isZip:
                 self.assertTrue(zipfile.is_zipfile(path))
             else:
                 self.assertTrue(os.path.isdir(path))
         finally:
             tearDownTestFontCopy(path)
示例#51
0
 def test_reloadLayers_layerinfo(self):
     path = getTestFontPath(u"TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     font = Font(path)
     p = os.path.join(path, "glyphs", "layerinfo.plist")
     data = {"lib": {}}
     data["lib"]["testForExternalChanges.test"] = 1
     with open(p, "wb") as f:
         dump(data, f)
     font.reloadLayers(dict(layers={"public.default": dict(info=True)}))
     self.assertEqual(font.layers["public.default"].lib,
                      {"testForExternalChanges.test": 1})
     tearDownTestFontCopy(font.path)
示例#52
0
 def test_reloadLayers_add_a_layer(self):
     path = getTestFontPath(u"TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     font = Font(path)
     shutil.copytree(os.path.join(path, "glyphs"),
                     os.path.join(path, "glyphs.test"))
     with open(os.path.join(path, "layercontents.plist"), "rb") as f:
         contents = load(f)
     contents.append(("test", "glyphs.test"))
     with open(os.path.join(path, "layercontents.plist"), "wb") as f:
         dump(contents, f)
     font.reloadLayers(dict(layers={"test": {}}))
     self.assertEqual(font.layers.layerOrder, ["public.default", "test"])
     tearDownTestFontCopy(font.path)
示例#53
0
 def test_testForExternalChanges_add_on_disk_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         fileSystem = openTestFontAsFileSystem(font.path)
         source = fs.path.join("data", "com.typesupply.defcon.test.file")
         dest = fs.path.join("data", "com.typesupply.defcon.test.file2")
         fileSystem.copy(source, dest)
         closeTestFontAsFileSystem(fileSystem, font.path)
         reader = UFOReader(path)
         self.assertEqual(font.data.testForExternalChanges(reader),
                          ([], ["com.typesupply.defcon.test.file2"], []))
         tearDownTestFontCopy(font.path)
示例#54
0
 def test_reloadLayers_add_a_layer(self):
     path = getTestFontPath(u"TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     font = Font(path)
     shutil.copytree(os.path.join(path, "glyphs"),
                     os.path.join(path, "glyphs.test"))
     with open(os.path.join(path, "layercontents.plist"), "rb") as f:
         contents = load(f)
     contents.append(("test", "glyphs.test"))
     with open(os.path.join(path, "layercontents.plist"), "wb") as f:
         dump(contents, f)
     font.reloadLayers(dict(layers={"test": {}}))
     self.assertEqual(font.layers.layerOrder, ["public.default", "test"])
     tearDownTestFontCopy(font.path)
示例#55
0
 def test_testExternalChanges_modify_on_disk_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         font.images["image 1.png"]  # image = font.images["image 1.png"]
         fileSystem = openTestFontAsFileSystem(font.path)
         imagePath = fs.path.join("images", "image 1.png")
         data = fileSystem.getbytes(imagePath)
         fileSystem.setbytes(imagePath, data + b"blah")
         closeTestFontAsFileSystem(fileSystem, font.path)
         reader = UFOReader(path)
         self.assertEqual(font.images.testForExternalChanges(reader),
                          (["image 1.png"], [], []))
         tearDownTestFontCopy(font.path)
示例#56
0
 def test_testForExternalChanges_add_a_layer(self):
     path = getTestFontPath("TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     font = Font(path)
     shutil.copytree(os.path.join(path, "glyphs"),
                     os.path.join(path, "glyphs.test"))
     with open(os.path.join(path, "layercontents.plist"), "rb") as f:
         contents = load(f)
     contents.append(("test", "glyphs.test"))
     with open(os.path.join(path, "layercontents.plist"), "wb") as f:
         dump(contents, f)
     reader = UFOReader(path)
     self.assertEqual(font.layers.testForExternalChanges(reader)["added"],
                      ["test"])
     tearDownTestFontCopy(font.path)
示例#57
0
 def test_testForExternalChanges_layerinfo(self):
     # layerinfo.plist
     path = getTestFontPath("TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     font = Font(path)
     reader = UFOReader(path)
     p = os.path.join(path, "glyphs", "layerinfo.plist")
     data = {"lib": {}}
     data["lib"]["testForExternalChanges.test"] = 1
     with open(p, "wb") as f:
         dump(data, f)
     self.assertTrue(
         font.layers.testForExternalChanges(reader)
         ["modified"]["public.default"]["info"])
     tearDownTestFontCopy(font.path)
示例#58
0
 def test_reload_data(self):
     path = makeTestFontCopy()
     font = Font(path)
     # d = font.data["com.typesupply.defcon.test.file"]
     font.data["com.typesupply.defcon.test.file"]
     filePath = os.path.join(path, "data",
                             "com.typesupply.defcon.test.file")
     newData = b"blah"
     f = open(filePath, "wb")
     f.write(newData)
     f.close()
     font.data.reloadData(["com.typesupply.defcon.test.file"])
     data = font.data["com.typesupply.defcon.test.file"]
     self.assertEqual(data, newData)
     tearDownTestFontCopy()
示例#59
0
 def test_testForExternalChanges_modify_on_disk_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     reader = UFOReader(path)
     # d = font.data["com.typesupply.defcon.test.file"]
     font.data["com.typesupply.defcon.test.file"]
     filePath = os.path.join(path, "data",
                             "com.typesupply.defcon.test.file")
     f = open(filePath, "wb")
     f.write(b"blah")
     f.close()
     reader = UFOReader(path)
     self.assertEqual(font.data.testForExternalChanges(reader),
                      (["com.typesupply.defcon.test.file"], [], []))
     tearDownTestFontCopy()
示例#60
0
 def test_testExternalChanges_modify_on_disk_and_scan(self):
     path = makeTestFontCopy()
     font = Font(path)
     font.images["image 1.png"]  # image = font.images["image 1.png"]
     imagePath = os.path.join(path, "images", "image 1.png")
     f = open(imagePath, "rb")
     data = f.read()
     f.close()
     f = open(imagePath, "wb")
     f.write(data + b"blah")
     f.close()
     reader = UFOReader(path)
     self.assertEqual(font.images.testForExternalChanges(reader),
                      (["image 1.png"], [], []))
     tearDownTestFontCopy()