コード例 #1
0
 def test_include_missing_file(self):
     lexer = IncludingLexer(self.getpath("include/includemissingfile.fea"))
     self.assertRaisesRegex(
         IncludedFeaNotFound,
         "includemissingfile.fea:1:8: The following feature file "
         "should be included but cannot be found: "
         "missingfile.fea", lambda: list(lexer))
コード例 #2
0
 def test_include_relative_to_cwd(self):
     # save current working directory, to be restored later
     cwd = os.getcwd()
     tmpdir = tempfile.mkdtemp()
     try:
         # create new feature file in a temporary directory
         with open(os.path.join(tmpdir, "included.fea"),
                   "w",
                   encoding="utf-8") as included:
             included.write("""
                 feature kern {
                     pos A B -40;
                 } kern;
                 """)
         # change current folder to the temporary dir
         os.chdir(tmpdir)
         # instantiate a new lexer that includes the above file
         # using a relative path; the IncludingLexer does not
         # itself have a path, because it was initialized from
         # an in-memory stream, so it will use the current working
         # directory to resolve relative include statements
         lexer = IncludingLexer(StringIO("include(included.fea);"))
         files = set(os.path.realpath(loc.file) for _, _, loc in lexer)
         expected = os.path.realpath(included.name)
         self.assertIn(expected, files)
     finally:
         # remove temporary folder and restore previous working directory
         os.chdir(cwd)
         shutil.rmtree(tmpdir)
コード例 #3
0
ファイル: lexer_test.py プロジェクト: codeman38/fonttools
 def test_include(self):
     lexer = IncludingLexer(self.getpath("include4.fea"))
     result = [
         '%s %s:%d' % (token, os.path.split(loc[0])[1], loc[1])
         for _, token, loc in lexer
     ]
     self.assertEqual(result, [
         "I4a include4.fea:1", "I3a include3.fea:1", "I2a include2.fea:1",
         "I1a include1.fea:1", "I0 include0.fea:1", "I1b include1.fea:3",
         "I2b include2.fea:3", "I3b include3.fea:3", "I4b include4.fea:3"
     ])
コード例 #4
0
 def __init__(self, path):
     self.doc_ = ast.FeatureFile()
     self.anchors_ = SymbolTable()
     self.glyphclasses_ = SymbolTable()
     self.lookups_ = SymbolTable()
     self.valuerecords_ = SymbolTable()
     self.symbol_tables_ = {
         self.anchors_, self.valuerecords_
     }
     self.next_token_type_, self.next_token_ = (None, None)
     self.next_token_location_ = None
     self.lexer_ = IncludingLexer(path)
     self.advance_lexer_()
コード例 #5
0
 def test_include_absolute_path(self):
     with tempfile.NamedTemporaryFile(delete=False) as included:
         included.write(tobytes("""
             feature kern {
                 pos A B -40;
             } kern;
             """, encoding="utf-8"))
     including = UnicodeIO("include(%s);" % included.name)
     try:
         lexer = IncludingLexer(including)
         files = set(loc[0] for _, _, loc in lexer)
         self.assertIn(included.name, files)
     finally:
         os.remove(included.name)
コード例 #6
0
 def test_featurefilepath_None(self):
     lexer = IncludingLexer(StringIO("# foobar"))
     self.assertIsNone(lexer.featurefilepath)
     files = set(loc.file for _, _, loc in lexer)
     self.assertIn("<features>", files)
コード例 #7
0
 def test_include_self(self):
     lexer = IncludingLexer(self.getpath("include/includeself.fea"))
     self.assertRaises(FeatureLibError, lambda: list(lexer))
コード例 #8
0
 def test_include_missing_file(self):
     lexer = IncludingLexer(self.getpath("include/includemissingfile.fea"))
     self.assertRaises(FeatureLibError, lambda: list(lexer))
コード例 #9
0
 def test_include_missing_file(self):
     lexer = IncludingLexer(self.getpath("include/includemissingfile.fea"))
     self.assertRaisesRegex(IncludedFeaNotFound,
                            "includemissingfile.fea:1:8: missingfile.fea",
                            lambda: list(lexer))
コード例 #10
0
ファイル: lexer_test.py プロジェクト: codeman38/fonttools
 def test_include_limit(self):
     lexer = IncludingLexer(self.getpath("include6.fea"))
     self.assertRaises(LexerError, lambda: list(lexer))