當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。