本文整理汇总了Python中editxt.project.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
def test(c):
def objcstr(value):
value = ak.NSString.alloc().initWithString_(value)
isinstance(value, objc.pyobjc_unicode), (type(value), value)
return value
def check(flag, key, serial, value=None):
if flag:
assert key in serial, (key, serial)
if value is not None:
eq_(serial[key], value)
else:
assert key not in serial, key
proj = Project(None)
recent = [objcstr("/file.txt"), objcstr("/doc.xml")]
if c.recent:
proj.recent.extend(Recent(p) for p in recent)
if c.name:
proj.name = objcstr("<name>")
if c.docs:
proj.editors = [MockDoc(1)]
proj.expanded = c.expn
serial = proj.serialize()
check(False, "path", serial, proj.path)
check(c.name, "name", serial, proj.name)
check(c.docs, "documents", serial)
check(True, "expanded", serial, c.expn)
check(c.recent, "recent", serial, recent)
dump_yaml(serial) # verify that it does not crash
示例2: test_create_editor_with_state
def test_create_editor_with_state():
with test_app() as app:
window = TestConfig(app=app)
project = Project(window)
state = {"path": "Untitled"}
result = project.create_editor_with_state(state)
eq_(result.project, project)
assert result in project.editors, project.editors
示例3: iter_dropped_paths
def iter_dropped_paths(self, pasteboard):
from editxt.document import TextDocument
if not pasteboard.types().containsObject_(ak.NSFilenamesPboardType):
raise StopIteration()
for path in pasteboard.propertyListForType_(ak.NSFilenamesPboardType):
if Project.is_project_path(path):
proj = self.app.find_project_with_path(path)
if proj is None:
proj = Project.create_with_path(path)
yield proj
else:
yield TextDocument.get_with_path(path)
示例4: test_set_main_view_of_window
def test_set_main_view_of_window():
window = TestConfig(command="<command>")
project = Project(window)
eq_(project.main_view, None)
m = Mocker()
view = m.mock()
view.bounds() >> "<frame>"
win = m.mock()
with m:
project.set_main_view_of_window(view, win)
assert project.main_view is not None
eq_(project.command_view.editor, project)
eq_(project.command_view.command, "<command>")
示例5: test_close
def test_close():
m = Mocker()
window = m.mock(name="window")
proj = Project(window)
proj.editors = docs = []
for i in range(2):
dv = m.mock(Editor)
docs.append(dv)
dv.close()
with m:
proj.close()
eq_(proj.proxy, None)
eq_(proj.window, None)
eq_(proj.editors, None)
示例6: test
def test(serial):
m = Mocker()
proj = Project.create()
log = m.replace("editxt.project.log", passthrough=False)
nsdat = m.replace(NSData, passthrough=False)
nspls = m.replace(NSPropertyListSerialization, passthrough=False)
create_document_view_with_state = m.method(Project.create_document_view_with_state)
create_document_view = m.method(Project.create_document_view)
proj._documents = docs = m.mock(KVOList)
if "path" in serial:
data = nsdat.dataWithContentsOfFile_(serial["path"]) >> m.mock()
serial_, format, error = nspls. \
propertyListFromData_mutabilityOption_format_errorDescription_( \
data, NSPropertyListImmutable, None, None) >> ({}, m.mock(), None)
else:
serial_ = serial
docs_ = serial_.get("documents", [])
for item in docs_:
create_document_view_with_state(item)
if item == "doc_not_found":
m.throw(Exception("document not found"))
log.warn("cannot open document: %r" % item)
#proj._is_dirty = True
bool(docs); m.result(bool(docs_))
if not docs_:
create_document_view()
#proj._is_dirty = True
with m:
proj.deserialize(serial)
if "path" in serial:
eq_(proj.path, serial["path"])
assert "name" not in serial
else:
eq_(proj.name, serial.get("name", const.UNTITLED_PROJECT_NAME))
eq_(proj.expanded, serial.get("expanded", True))
示例7: test_append_document_view_already_in_project
def test_append_document_view_already_in_project():
class Fake(object): pass
proj = Project.create()
dv = Fake()
proj.append_document_view(dv)
proj.append_document_view(dv)
assert len(proj.documents()) == 2, proj.documents()
示例8: test_set_main_view_of_window
def test_set_main_view_of_window():
proj = Project.create()
m = Mocker()
view = m.mock(NSView)
win = m.mock(NSWindow)
with m:
proj.set_main_view_of_window(view, win) # for now this does nothing
示例9: test_displayName
def test_displayName():
proj = Project.create()
eq_(proj.displayName(), const.UNTITLED_PROJECT_NAME)
proj.setDisplayName_("name")
eq_(proj.displayName(), "name")
proj.path = path = "/tmp/test.edxt"
eq_(proj.displayName(), "test")
示例10: test_create_with_path
def test_create_with_path():
path = "/temp/non-existent/project.edxt"
assert not os.path.exists(path)
result = Project.create_with_path(path)
try:
eq_(result.path, path)
finally:
result.close()
示例11: test_append_document_view
def test_append_document_view():
proj = Project.create()
#assert not proj.is_dirty
m = Mocker()
doc = m.mock(TextDocumentView)
doc.project = proj
with m:
proj.append_document_view(doc)
assert doc in proj.documents()
示例12: test_init_with_serial
def test_init_with_serial():
m = Mocker()
kvo_class = m.replace(mod, 'KVOList')
deserialize = m.method(Project.deserialize)
reset_cache = m.method(Project.reset_serial_cache)
docs = kvo_class.alloc().init() >> []
deserialize("<serial>")
reset_cache(); m.count(2)
with m:
proj = Project.alloc().init_with_serial("<serial>")
示例13: test_create_with_serial
def test_create_with_serial():
m = Mocker()
serial = {"path": "/temp/non-existent/project.edxt"}
assert not os.path.exists(serial["path"])
with m:
result = Project.create_with_serial(serial)
try:
eq_(result.path, serial["path"])
finally:
result.close()
示例14: do_save_project
def do_save_project(path):
proj = Project.create()
m = Mocker()
doc = m.mock(TextDocumentView)
doc.edit_state >> {"path": "xyz"}
doc.project = proj
with m:
proj.append_document_view(doc)
proj.save_with_path(path)
assert os.path.exists(path), "project not saved: %s" % path
示例15: do_test
def do_test(template):
proj = Project(None)
temp_docs = proj.editors
try:
m = Mocker()
all_docs = []
dirty_docs = []
for item in template:
doc = m.mock(Editor)
all_docs.append(doc)
doc.is_dirty >> (item == "d")
if item == "d":
dirty_docs.append(doc)
proj.editors = all_docs
with m:
result = list(proj.dirty_editors())
assert len(dirty_docs) == template.count("d")
assert dirty_docs == result, "%r != %r" % (dirty_docs, result)
finally:
proj.editors = temp_docs