Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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")))
Exemplo n.º 4
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)
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
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()
Exemplo n.º 8
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()
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def test_save_as(self):
     path = getTestFontPath()
     font = Font(path)
     saveAsPath = getTestFontCopyPath(path)
     font.save(saveAsPath)
     fileNames = glob.glob(os.path.join(saveAsPath, 'glyphs', '*.glif'))
     fileNames = [os.path.basename(fileName) for fileName in fileNames]
     self.assertEqual(sorted(fileNames), ["A_.glif", "B_.glif", "C_.glif"])
     self.assertEqual(font.path, saveAsPath)
     tearDownTestFontCopy(saveAsPath)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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()
Exemplo n.º 14
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)
Exemplo n.º 15
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()
Exemplo n.º 16
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()
Exemplo n.º 17
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()
Exemplo n.º 18
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)
Exemplo n.º 19
0
 def test_save_as(self):
     path = getTestFontPath()
     font = Font(path)
     saveAsPath = getTestFontCopyPath(path)
     font.save(saveAsPath)
     imagesDirectory = os.path.join(saveAsPath, "images")
     self.assertTrue(os.path.exists(imagesDirectory))
     imagePath = os.path.join(imagesDirectory, "image 1.png")
     self.assertTrue(os.path.exists(imagePath))
     imagePath = os.path.join(imagesDirectory, "image 2.png")
     self.assertTrue(os.path.exists(imagePath))
     tearDownTestFontCopy(saveAsPath)
Exemplo n.º 20
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)
Exemplo n.º 21
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)
Exemplo n.º 22
0
 def test_save_same_path(self):
     for ufo in ("TestFont.ufo", "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)
Exemplo n.º 23
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()
Exemplo n.º 24
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()
Exemplo n.º 25
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()
Exemplo n.º 26
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()
Exemplo n.º 27
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()
Exemplo n.º 28
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()
Exemplo n.º 29
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)
Exemplo n.º 30
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)
Exemplo n.º 31
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)
Exemplo n.º 32
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)
Exemplo n.º 33
0
 def test_testExternalChanges_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("images", "image 1.png")
         dest = fs.path.join("images", "image 3.png")
         fileSystem.copy(source, dest)
         closeTestFontAsFileSystem(fileSystem, font.path)
         reader = UFOReader(path)
         self.assertEqual(font.images.testForExternalChanges(reader),
                          ([], ["image 3.png"], []))
         tearDownTestFontCopy(font.path)
Exemplo n.º 34
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)
Exemplo n.º 35
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)
Exemplo n.º 36
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()
Exemplo n.º 37
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)
Exemplo n.º 38
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()
Exemplo n.º 39
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()
Exemplo n.º 40
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)
Exemplo n.º 41
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()
Exemplo n.º 42
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)
Exemplo n.º 43
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)
Exemplo n.º 44
0
 def test_testForExternalChanges_modify_on_disk_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         # d = font.data["com.typesupply.defcon.test.file"]
         font.data["com.typesupply.defcon.test.file"]
         fileSystem = openTestFontAsFileSystem(font.path)
         filePath = fs.path.join("data", "com.typesupply.defcon.test.file")
         fileSystem.setbytes(filePath, b"blah")
         closeTestFontAsFileSystem(fileSystem, font.path)
         reader = UFOReader(path)
         self.assertEqual(font.data.testForExternalChanges(reader),
                          (["com.typesupply.defcon.test.file"], [], []))
         tearDownTestFontCopy(font.path)
Exemplo n.º 45
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)
Exemplo n.º 46
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)
Exemplo n.º 47
0
 def test_testForExternalChanges_remove_on_disk_and_scan(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         with Font(path) as font:
             # image = font.data["com.typesupply.defcon.test.file"]
             font.data["com.typesupply.defcon.test.file"]
             fileSystem = openTestFontAsFileSystem(font.path)
             fileSystem.remove(
                 fs.path.join("data", "com.typesupply.defcon.test.file"))
             closeTestFontAsFileSystem(fileSystem, font.path)
             with UFOReader(path) as reader:
                 self.assertEqual(
                     font.data.testForExternalChanges(reader),
                     ([], [], ["com.typesupply.defcon.test.file"]))
         tearDownTestFontCopy(font.path)
Exemplo n.º 48
0
 def test_write(self):
     path = makeTestFontCopy()
     font = Font(path)
     glyph = font.layers[None]["A"]
     glyph.image = glyph.instantiateImage()
     glyph.image.color = "1,1,1,1"
     glyph.image.fileName = "foo.png"
     glyph.image.transformation = (1, 2, 3, 4, 5, 6)
     font.save()
     font = Font(path)
     glyph = font.layers[None]["A"]
     self.assertEqual(sorted(glyph.image.items()),
                      [('color', '1,1,1,1'), ('fileName', 'foo.png'),
                       ('xOffset', 5), ('xScale', 1), ('xyScale', 2),
                       ('yOffset', 6), ('yScale', 4), ('yxScale', 3)])
     tearDownTestFontCopy()
Exemplo n.º 49
0
 def test_reloadLayers_change_default_layer(self):
     path = getTestFontPath(u"TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     shutil.copytree(os.path.join(path, "glyphs"),
                     os.path.join(path, "glyphs.test"))
     contents = [("foo", "glyphs"), ("test", "glyphs.test")]
     with open(os.path.join(path, "layercontents.plist"), "wb") as f:
         dump(contents, f)
     font = Font(path)
     contents = [("test", "glyphs"), ("foo", "glyphs.test")]
     contents.reverse()
     with open(os.path.join(path, "layercontents.plist"), "wb") as f:
         dump(contents, f)
     font.reloadLayers(dict(default=True))
     self.assertEqual(font.layers.defaultLayer.name, "test")
     tearDownTestFontCopy(font.path)
Exemplo n.º 50
0
 def test_save(self):
     for ufo in (u"TestFont.ufo", u"TestFont.ufoz"):
         path = makeTestFontCopy(getTestFontPath(ufo))
         try:
             font = Font(path)
             origFileStructure = font.ufoFileStructure
             for glyph in font:
                 glyph.dirty = True
             font.save()
             fileNames = sorted([
                 fs.path.basename(m.path)
                 for m in UFOReader(path).fs.glob("glyphs/*.glif")
             ])
             self.assertEqual(fileNames, ["A_.glif", "B_.glif", "C_.glif"])
             self.assertEqual(origFileStructure, font.ufoFileStructure)
         finally:
             tearDownTestFontCopy(path)
Exemplo n.º 51
0
 def test_delitem(self):
     path = makeTestFontCopy()
     font = Font(path)
     del font["A"]
     self.assertTrue(font.dirty)
     font.newGlyph("NewGlyphTest")
     del font["NewGlyphTest"]
     self.assertEqual(sorted(font.keys()), ["B", "C"])
     self.assertEqual(len(font), 2)
     self.assertFalse("A" in font)
     font.save()
     fileNames = glob.glob(os.path.join(path, 'glyphs', '*.glif'))
     fileNames = [os.path.basename(fileName) for fileName in fileNames]
     self.assertEqual(sorted(fileNames), ["B_.glif", "C_.glif"])
     with self.assertRaises(KeyError):
         del font["NotInFont"]
     tearDownTestFontCopy()
Exemplo n.º 52
0
 def test_testForExternalChanges_add_a_layer(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(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)
         reader = UFOReader(path)
         self.assertEqual(
             font.layers.testForExternalChanges(reader)["added"], ["test"])
         tearDownTestFontCopy(font.path)
Exemplo n.º 53
0
 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:
             tearDownTestFontCopy(saveAsPath)
Exemplo n.º 54
0
 def test_delitem_glyph_not_dirty(self):
     path = makeTestFontCopy()
     font = Font(path)
     font["A"]  # glyph = font["A"]
     glyphPath = os.path.join(path, "glyphs", "A_.glif")
     os.remove(glyphPath)
     contentsPath = os.path.join(path, "glyphs", "contents.plist")
     with open(contentsPath, "rb") as f:
         plist = load(f)
     del plist["A"]
     with open(contentsPath, "wb") as f:
         dump(plist, f)
     r = font.testForExternalChanges()
     self.assertEqual(r["deletedGlyphs"], ["A"])
     del font["A"]
     font.save()
     self.assertFalse(os.path.exists(glyphPath))
     tearDownTestFontCopy()
Exemplo n.º 55
0
 def test_testForExternalChanges_change_default_layer(self):
     path = getTestFontPath("TestExternalEditing.ufo")
     path = makeTestFontCopy(path)
     shutil.copytree(os.path.join(path, "glyphs"),
                     os.path.join(path, "glyphs.test"))
     contents = [("foo", "glyphs"), ("test", "glyphs.test")]
     with open(os.path.join(path, "layercontents.plist"), "wb") as f:
         dump(contents, f)
     font = Font(path)
     contents = [("test", "glyphs"), ("foo", "glyphs.test")]
     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": True, "order": False})
     tearDownTestFontCopy(font.path)
Exemplo n.º 56
0
 def test_write(self):
     path = makeTestFontCopy()
     font = Font(path)
     font.data[
         "com.typesupply.defcon.test.newdirectory/file.txt"] = b"hello."
     del font.data[
         "com.typesupply.defcon.test.directory/sub directory/file 2.txt"]
     font.save()
     p = os.path.join(path, "data",
                      "com.typesupply.defcon.test.newdirectory", "file.txt")
     self.assertTrue(os.path.exists(p))
     with open(p, "r") as f:
         t = f.read()
     self.assertEqual(t, "hello.")
     p = os.path.join(path, "data", "com.typesupply.defcon.test.directory",
                      "sub directory", "file 2.txt")
     self.assertFalse(os.path.exists(p))
     tearDownTestFontCopy()
Exemplo n.º 57
0
 def test_testForExternalChanges_layerinfo(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         # layerinfo.plist
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         data = {"lib": {}}
         data["lib"]["testForExternalChanges.test"] = 1
         fileSystem = openTestFontAsFileSystem(path)
         p = fs.path.join("glyphs", "layerinfo.plist")
         with fileSystem.open(p, mode="wb") as f:
             dump(data, f)
         closeTestFontAsFileSystem(fileSystem, path)
         reader = UFOReader(path)
         self.assertTrue(
             font.layers.testForExternalChanges(reader)["modified"]
             ["public.default"]["info"])
         tearDownTestFontCopy(font.path)
Exemplo n.º 58
0
    def test_testForExternalChanges(self):
        for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
            path = getTestFontPath(ufo)
            path = makeTestFontCopy(path)
            font = Font(path)

            # load all the objects so that they get stamped
            font.info  # i = font.info
            k = font.kerning
            font.groups  # g = font.groups
            font.lib  # l = font.lib
            font["A"]  # g = font["A"]

            d = font.testForExternalChanges()
            self.assertFalse(d["info"])
            self.assertFalse(d["kerning"])
            self.assertFalse(d["groups"])
            self.assertFalse(d["lib"])

            # make a simple change to the kerning data
            fileSystem = openTestFontAsFileSystem(font.path)
            path = u"kerning.plist"
            t = fileSystem.getbytes(path)
            t += b"<!-- test -->"
            fileSystem.setbytes(path, t)
            k._dataOnDiskTimeStamp -= 1
            closeTestFontAsFileSystem(fileSystem, font.path)

            d = font.testForExternalChanges()
            self.assertTrue(d["kerning"])
            self.assertFalse(d["groups"])
            self.assertFalse(d["info"])
            self.assertFalse(d["lib"])

            # save the kerning data and test again
            font.kerning.dirty = True
            font.save()
            d = font.testForExternalChanges()
            self.assertFalse(d["kerning"])
            self.assertFalse(d["groups"])
            self.assertFalse(d["info"])
            self.assertFalse(d["lib"])

            tearDownTestFontCopy(font.path)
Exemplo n.º 59
0
    def test_layer_info(self):
        # open and change some values
        font = Font(makeTestFontCopy())
        layer = font.layers["Layer 1"]
        self.assertEqual(layer.color, "0.1,0.2,0.3,0.4")
        layer.color = "0.5,0.5,0.5,0.5"
        self.assertEqual(layer.lib, {"com.typesupply.defcon.test": "1 2 3"})
        layer.lib["foo"] = "bar"
        font.save()
        path = font.path

        # reopen and check the changes
        font = Font(path)
        layer = font.layers["Layer 1"]
        self.assertEqual(layer.color, "0.5,0.5,0.5,0.5")
        self.assertEqual(sorted(layer.lib.items()),
                         [("com.typesupply.defcon.test", "1 2 3"),
                          ("foo", "bar")])
        tearDownTestFontCopy()
Exemplo n.º 60
0
 def test_delitem_glyph_not_dirty(self):
     for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
         path = getTestFontPath(ufo)
         path = makeTestFontCopy(path)
         font = Font(path)
         font["A"]  # glyph = font["A"]
         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()
         self.assertFalse(os.path.exists(glyphPath))
         tearDownTestFontCopy(font.path)