本文整理汇总了Python中vai.models.TextDocument.TextDocument类的典型用法代码示例。如果您正苦于以下问题:Python TextDocument类的具体用法?Python TextDocument怎么用?Python TextDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUpdateCharMeta
def testUpdateCharMeta(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
doc.updateCharMeta( (1, 3), { "foo" : ["a", "a"],
"bar" : ['b', None, 'b'],
}
)
示例2: testSaveUnnamed
def testSaveUnnamed(self):
doc = TextDocument()
self.assertRaises(TextDocument.MissingFilenameException, lambda: doc.save())
path = fixtures.tempFile("testSaveUnnamed")
doc.saveAs(path)
self.assertTrue(os.path.exists(path))
self.assertEqual(doc.filename(), path)
示例3: testDeleteLineMeta
def testDeleteLineMeta(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
doc.updateLineMeta(1, {"hello": 5})
self.assertEqual(doc.lineMeta(1)["hello"], 5)
doc.deleteLineMeta(1, ["hello"])
self.assertNotIn("hello", doc.lineMeta(1))
self.assertRaises(IndexError, lambda : doc.deleteLineMeta(20, "hello"))
示例4: testDeleteDocumentMeta
def testDeleteDocumentMeta(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
doc.updateDocumentMeta({"Hello": 5})
self.assertEqual(doc.documentMeta()["Hello"], 5)
doc.deleteDocumentMeta("Hello")
self.assertNotIn("Hello", doc.documentMeta())
示例5: testBasic
def testBasic(self):
doc = TextDocument()
doc.createLineMetaInfo("whatever")
meta_info = doc.lineMetaInfo("whatever")
self.assertEqual(meta_info.document, doc)
self.assertEqual(meta_info.meta_type, "whatever")
self.assertEqual(meta_info.numLines(), 1)
self.assertEqual(meta_info.data(1), None)
meta_info.setData("hello",1)
self.assertEqual(meta_info.data(1), "hello")
示例6: testDocumentMeta
def testDocumentMeta(self):
doc = TextDocument()
with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
doc.read(f)
doc.createDocumentMetaInfo("Hello")
self.assertEqual(doc.documentMetaInfo("Hello").data(), None)
doc.createDocumentMetaInfo("Hello2", 2)
self.assertEqual(doc.documentMetaInfo("Hello2").data(), 2)
示例7: testReplaceChars
def testReplaceChars(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
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')
示例8: testCharMeta
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])
示例9: testReplaceChars
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: testJoinWithNextLine2
def testJoinWithNextLine2(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
doc.joinWithNextLine(2)
self.assertEqual(doc.lineText(1), 'hello\n')
self.assertEqual(doc.lineText(2), 'how are you?\n')
self.assertEqual(doc.numLines(), 2)
self.assertFalse(doc.isModified())
示例11: testUpdateLineMeta
def testUpdateLineMeta(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
doc.updateLineMeta(1, {"hello": 5})
self.assertEqual(type(doc.lineMeta(1)), dict)
self.assertEqual(doc.lineMeta(1)["hello"], 5)
self.assertRaises(IndexError, lambda : doc.updateLineMeta(20, {}))
示例12: testLastModified
def testLastModified(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
last_modified = doc.lastModified()
self.assertEqual(doc.lastModified(), last_modified)
time.sleep(0.1)
doc.insertLine(1,"")
self.assertNotEqual(doc.lastModified(), last_modified)
示例13: testLineLength
def testLineLength(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
self.assertEqual(doc.lineLength(1), 6)
self.assertEqual(doc.lineLength(2), 13)
doc = TextDocument()
doc.open(fixtures.get("empty_file.txt"))
self.assertEqual(doc.lineLength(1), 1)
示例14: testInitFromNonEmptyFile
def testInitFromNonEmptyFile(self):
doc = TextDocument()
doc.open(fixtures.get("basic_nonempty_file.txt"))
self.assertFalse(doc.isEmpty())
self.assertEqual(doc.filename(), fixtures.get("basic_nonempty_file.txt"))
self.assertFalse(doc.isModified())
self.assertEqual(doc.numLines(), 2)
self.assertEqual(doc.documentText(), 'hello\nhow are you?\n')
示例15: testInitFromEmptyFile
def testInitFromEmptyFile(self):
doc = TextDocument()
doc.open(fixtures.get("empty_file.txt"))
self.assertTrue(doc.isEmpty())
self.assertEqual(doc.filename(), fixtures.get("empty_file.txt"))
self.assertFalse(doc.isModified())
self.assertEqual(doc.numLines(), 1)
self.assertEqual(doc.documentText(), '\n')