aboutsummaryrefslogtreecommitdiff
path: root/Tests/ttLib/ttVisitor_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/ttLib/ttVisitor_test.py')
-rw-r--r--Tests/ttLib/ttVisitor_test.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Tests/ttLib/ttVisitor_test.py b/Tests/ttLib/ttVisitor_test.py
new file mode 100644
index 00000000..e84e213c
--- /dev/null
+++ b/Tests/ttLib/ttVisitor_test.py
@@ -0,0 +1,39 @@
+from fontTools.ttLib import TTFont
+from fontTools.ttLib.ttVisitor import TTVisitor
+import os
+import pytest
+
+
+class TestVisitor(TTVisitor):
+ def __init__(self):
+ self.value = []
+ self.depth = 0
+
+ def _add(self, s):
+ self.value.append(s)
+
+ def visit(self, obj, target_depth):
+ if self.depth == target_depth:
+ self._add(obj)
+ self.depth += 1
+ super().visit(obj, target_depth)
+ self.depth -= 1
+
+
+class TTVisitorTest(object):
+
+ @staticmethod
+ def getpath(testfile):
+ path = os.path.dirname(__file__)
+ return os.path.join(path, "data", testfile)
+
+ def test_ttvisitor(self):
+
+ font = TTFont(self.getpath("TestVGID-Regular.otf"))
+ visitor = TestVisitor()
+
+ # Count number of objects at depth 1:
+ # That is, number of font tables, including GlyphOrder.
+ visitor.visit(font, 1)
+
+ assert len(visitor.value) == 14