本文整理汇总了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], "")
示例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)
示例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")
示例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])
示例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)
示例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")
示例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")
示例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)
示例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")
示例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))
示例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)
示例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")
示例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))
示例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"))
示例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())