当前位置: 首页>>代码示例>>Python>>正文


Python TextDocument.read方法代码示例

本文整理汇总了Python中vai.models.TextDocument.TextDocument.read方法的典型用法代码示例。如果您正苦于以下问题:Python TextDocument.read方法的具体用法?Python TextDocument.read怎么用?Python TextDocument.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vai.models.TextDocument.TextDocument的用法示例。


在下文中一共展示了TextDocument.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testDeleteChars

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testDeleteChars(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)

        self.assertRaises(ValueError, lambda: doc.deleteChars((1, 3), -1))

        d = doc.deleteChars((1, 3), 1)
        self.assertEqual(doc.lineText(1), "helo\n")
        self.assertEqual(d[0], "l")

        d = doc.deleteChars((1, 2), 100)
        self.assertEqual(doc.lineText(1), "h\n")
        self.assertEqual(d[0], "elo")

        d = doc.deleteChars((1, 2), 100)
        self.assertEqual(doc.lineText(1), "h\n")
        self.assertEqual(d[0], "")

        d = doc.deleteChars((1, 1), 100)
        self.assertEqual(doc.lineText(1), "\n")
        self.assertEqual(d[0], "h")

        d = doc.deleteChars((1, 1), 100)
        self.assertEqual(doc.lineText(1), "\n")
        self.assertEqual(d[0], "")
开发者ID:rsdenijs,项目名称:vai,代码行数:28,代码来源:test_TextDocument.py

示例2: testUpdateDocumentMeta

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
 def testUpdateDocumentMeta(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
         doc.read(f)
     doc.createDocumentMetaInfo("Hello")
     doc.documentMetaInfo("Hello").setData(5)
     self.assertEqual(doc.documentMetaInfo("Hello").data(), 5)
开发者ID:rsdenijs,项目名称:vai,代码行数:9,代码来源:test_TextDocument.py

示例3: testBreakLine

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
 def testBreakLine(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
         doc.read(f)
     doc.breakLine((1, 3))
     self.assertEqual(doc.lineText(1), "he\n")
     self.assertEqual(doc.lineText(2), "llo\n")
开发者ID:rsdenijs,项目名称:vai,代码行数:9,代码来源:test_TextDocument.py

示例4: testCharMeta

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
 def testCharMeta(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
         doc.read(f)
     doc.updateCharMeta((1, 1), {"Hello": [1]})
     self.assertEqual(len(doc.charMeta((1, 1))["Hello"]), len(doc.lineText(1)))
     self.assertEqual(doc.charMeta((1, 1))["Hello"], [1, None, None, None, None, None])
开发者ID:rsdenijs,项目名称:vai,代码行数:9,代码来源:test_TextDocument.py

示例5: testJoinWithNextLine2

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
 def testJoinWithNextLine2(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
         doc.read(f)
     doc.joinWithNextLine(2)
     self.assertEqual(doc.lineText(1), "hello\n")
     self.assertEqual(doc.lineText(2), "how are you?\n")
     self.assertEqual(doc.numLines(), 2)
开发者ID:rsdenijs,项目名称:vai,代码行数:10,代码来源:test_TextDocument.py

示例6: testInitFromEmptyFile

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testInitFromEmptyFile(self):
        doc = TextDocument()
        with open(fixtures.get("empty_file.txt"), "r") as f:
            doc.read(f)

        self.assertTrue(doc.isEmpty())
        self.assertEqual(doc.numLines(), 1)
        self.assertEqual(doc.documentText(), "\n")
开发者ID:rsdenijs,项目名称:vai,代码行数:10,代码来源:test_TextDocument.py

示例7: testInitFromNonEmptyFile

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testInitFromNonEmptyFile(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)

        self.assertFalse(doc.isEmpty())
        self.assertEqual(doc.numLines(), 2)
        self.assertEqual(doc.documentText(), "hello\nhow are you?\n")
开发者ID:rsdenijs,项目名称:vai,代码行数:10,代码来源:test_TextDocument.py

示例8: testLineLength

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testLineLength(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)
        self.assertEqual(doc.lineLength(1), 6)
        self.assertEqual(doc.lineLength(2), 13)

        doc = TextDocument()
        with open(fixtures.get("empty_file.txt"), "r") as f:
            doc.read(f)
        self.assertEqual(doc.lineLength(1), 1)
开发者ID:rsdenijs,项目名称:vai,代码行数:13,代码来源:test_TextDocument.py

示例9: testReplaceChars

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testReplaceChars(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)
        doc.replaceChars((1, 3), 1, "hello")

        self.assertEqual(doc.lineText(1), "hehellolo\n")

        doc.replaceChars((1, 1), 1, "c")

        self.assertEqual(doc.lineText(1), "cehellolo\n")
开发者ID:rsdenijs,项目名称:vai,代码行数:13,代码来源:test_TextDocument.py

示例10: testLine

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testLine(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)

        self.assertEqual(doc.lineText(1), "hello\n")
        self.assertEqual(doc.lineText(2), "how are you?\n")

        self.assertRaises(IndexError, lambda: doc.lineText(-1))
        self.assertRaises(IndexError, lambda: doc.lineText(0))
        self.assertRaises(IndexError, lambda: doc.lineText(5))
开发者ID:rsdenijs,项目名称:vai,代码行数:13,代码来源:test_TextDocument.py

示例11: testInsertLine

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testInsertLine(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)
        self.assertEqual(doc.numLines(), 2)
        doc.insertLine(1, "babau")
        self.assertEqual(doc.numLines(), 3)

        self.assertRaises(IndexError, lambda: doc.insertLine(6, "say what again"))

        doc.insertLine(4, "say what again")
        self.assertEqual(doc.numLines(), 4)
开发者ID:rsdenijs,项目名称:vai,代码行数:14,代码来源:test_TextDocument.py

示例12: testReplaceFromMemento

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testReplaceFromMemento(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)
        doc.createLineMetaInfo("whatever")
        initial_text = doc.documentText()
        meta_info1 = doc.lineMetaInfo("whatever")
        meta_info1.setData("hello", 1)

        memento = doc.lineMemento(1)
        doc.insertChars((1, 1), "gnakgnak")
        meta_info1.setData("byebye", 1)
        doc.replaceFromMemento(1, memento)

        self.assertEqual(doc.documentText(), initial_text)
        self.assertEqual(meta_info1.data(1), "hello")
开发者ID:rsdenijs,项目名称:vai,代码行数:18,代码来源:test_TextDocument.py

示例13: testInsertFragment

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testInsertFragment(self):
        doc = TextDocument()
        with open(fixtures.get("numbers.txt"), "r") as f:
            doc.read(f)
        doc.createLineMetaInfo("whatever")
        doc.createLineMetaInfo("whatever2")

        fragment = doc.extractFragment(2)
        self.assertNotEqual(fragment.lineText(1), doc.lineText(15))
        doc.insertFragment(15, fragment)
        self.assertEqual(fragment.lineText(1), doc.lineText(15))

        fragment = doc.extractFragment(2, 4)
        self.assertNotEqual(fragment.lineText(1), doc.lineText(10))
        doc.insertFragment(10, fragment)

        self.assertEqual(fragment.lineText(1), doc.lineText(10))
        self.assertEqual(fragment.lineText(2), doc.lineText(11))
        self.assertEqual(fragment.lineText(3), doc.lineText(12))
        self.assertEqual(fragment.lineText(4), doc.lineText(13))
开发者ID:rsdenijs,项目名称:vai,代码行数:22,代码来源:test_TextDocument.py

示例14: testExtractFragment

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testExtractFragment(self):
        doc = TextDocument()
        with open(fixtures.get("bigfile.py"), "r") as f:
            doc.read(f)
        doc.createLineMetaInfo("whatever")
        doc.createLineMetaInfo("whatever2")

        fragment = doc.extractFragment(2)
        self.assertEqual(fragment.numLines(), 1)
        self.assertEqual(fragment.lineText(1), doc.lineText(2))
        self.assertTrue(fragment.hasLineMetaInfo("whatever"))
        self.assertTrue(fragment.hasLineMetaInfo("whatever2"))

        fragment = doc.extractFragment(2, 3)
        self.assertEqual(fragment.numLines(), 3)
        self.assertEqual(fragment.lineText(1), doc.lineText(2))
        self.assertEqual(fragment.lineText(2), doc.lineText(3))
        self.assertEqual(fragment.lineText(3), doc.lineText(4))
        self.assertTrue(fragment.hasLineMetaInfo("whatever"))
        self.assertTrue(fragment.hasLineMetaInfo("whatever2"))
开发者ID:rsdenijs,项目名称:vai,代码行数:22,代码来源:test_TextDocument.py

示例15: testDeleteLine2

# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import read [as 别名]
    def testDeleteLine2(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)

        self.assertEqual(doc.lineText(1), "hello\n")
        self.assertEqual(doc.lineText(2), "how are you?\n")
        self.assertEqual(doc.numLines(), 2)

        self.assertRaises(IndexError, lambda: doc.deleteLine(5))
        self.assertEqual(doc.lineText(1), "hello\n")
        self.assertEqual(doc.lineText(2), "how are you?\n")
        self.assertEqual(doc.numLines(), 2)

        doc.deleteLine(2)
        self.assertEqual(doc.lineText(1), "hello\n")
        self.assertEqual(doc.numLines(), 1)
        self.assertFalse(doc.isEmpty())

        doc.deleteLine(1)
        self.assertEqual(doc.lineText(1), "\n")
        self.assertEqual(doc.numLines(), 1)
        self.assertTrue(doc.isEmpty())
开发者ID:rsdenijs,项目名称:vai,代码行数:25,代码来源:test_TextDocument.py


注:本文中的vai.models.TextDocument.TextDocument.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。