本文整理汇总了Python中editxt.application.Application类的典型用法代码示例。如果您正苦于以下问题:Python Application类的具体用法?Python Application怎么用?Python Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
def test(eds_config):
app = Application()
m = Mocker()
create_window = m.method(app.create_window)
open_error_log = m.method(app.open_error_log)
nsapp = m.mock(ak.NSApplication)
ud_class = m.replace(fn, 'NSUserDefaults')
m.method(app.iter_saved_window_states)() >> iter(eds_config)
tc = m.replace(app, 'text_commander', spec=CommandManager)
dc = m.mock(DocumentController)
tc.load_commands(dc.textMenu >> m.mock(ak.NSMenu))
tc.load_shortcuts(dc.shortcutsMenu >> m.mock(ak.NSMenu))
if eds_config:
error = False
for ed_config in eds_config:
if isinstance(ed_config, mod.StateLoadFailure):
error = True
else:
create_window(ed_config)
if error:
open_error_log(set_current=False)
else:
create_window()
with m:
app.application_will_finish_launching(nsapp, dc)
eq_(app.text_commander, tc)
示例2: do_test
def do_test(windows_template):
app = Application()
m = Mocker()
seen = set()
dirty_docs = []
eds = []
for ecfg in windows_template:
projects = []
for pcfg in ecfg:
proj = m.mock(Project)
projects.append(proj)
editors = []
has_dirty = False
for doc_id in pcfg:
editor = m.mock(Editor)
editors.append(editor)
(editor.document.id << doc_id).count(1, 2)
if doc_id not in seen:
seen.add(doc_id)
dirty_docs.append(editor)
has_dirty = True
proj.dirty_editors() >> editors
if has_dirty:
dirty_docs.append(proj)
ed = m.mock(Window)
ed.projects >> projects
eds.append(ed)
m.method(app.iter_windows)() >> eds
with m:
result = list(app.iter_dirty_editors())
eq_(result, dirty_docs)
示例3: test
def test(ed_config):
ac = Application()
m = Mocker()
df_class = m.replace("editxt.application.NSUserDefaults")
iter_editors = m.method(ac.iter_editors)
save_open_projects = m.method(ac.save_open_projects)
discard_editor = m.method(ac.discard_editor)
nsapp = m.mock()
ac.editors = eds = []
all_settings = []
for i in ed_config:
ed = m.mock(Editor)
eds.append(ed)
ed.window_settings_loaded >> (i != 2)
if i != 2:
settings = "<settings %s>" % i
all_settings.append(settings)
ed.window_settings >> settings
iter_editors(nsapp) >> reversed(eds)
defaults = df_class.standardUserDefaults() >> MockUserDefaults()
save_open_projects(defaults)
with m:
ac.app_will_terminate(nsapp)
result = defaults.arrayForKey_(const.WINDOW_SETTINGS_DEFAULTS_KEY)
eq_(result, all_settings)
assert defaults.synced
示例4: test_setup_profile_at_file
def test_setup_profile_at_file():
with tempdir() as tmp:
path = os.path.join(tmp, 'profile')
with open(path, 'w') as fh: pass
app = Application(path)
eq_(app.setup_profile(), False)
assert os.path.isfile(path), path
示例5: test_save_window_settings_with_unknown_editor
def test_save_window_settings_with_unknown_editor():
ac = Application()
m = Mocker()
df_class = m.replace("editxt.application.NSUserDefaults")
ed = m.mock(Editor)
with m:
ac.save_window_settings(ed)
示例6: __enter__
def __enter__(self):
from editxt.application import Application
self.tempdir = tempdir()
self.tmp = os.path.realpath(self.tempdir.__enter__())
profile_path = os.path.join(self.tmp, ".profile")
app = Application(profile_path)
app.syntax_factory = {}
if self.config is not None:
def update(data, key, value):
if "." in key:
base, sub = key.split(".", 1)
if base not in data:
data[base] = {}
update(data[base], sub, value)
else:
data[key] = value
for key, value in self.config.items():
assert isinstance(key, str), key
update(app.config.data, key, value)
self.items = {}
self.news = 0
self.app = app
self._setup(app)
app.__test_app = self
return app
示例7: test_add_editor
def test_add_editor():
ac = Application()
m = Mocker()
ed = m.mock(Editor)
assert not ac.editors
with m:
ac.add_editor(ed)
assert ed in ac.editors
示例8: test_add_window
def test_add_window():
ac = Application()
m = Mocker()
ed = m.mock(Window)
assert not ac.windows
with m:
ac.add_window(ed)
assert ed in ac.windows
示例9: test_set_current_document_view
def test_set_current_document_view():
ac = Application()
m = Mocker()
dv = m.mock(TextDocumentView)
ac.find_editor_with_document_view = m.method(ac.find_editor_with_document_view)
ed = ac.find_editor_with_document_view(dv) >> m.mock(Editor)
ed.current_view = dv
with m:
ac.set_current_document_view(dv)
示例10: test_set_current_editor
def test_set_current_editor():
ac = Application()
m = Mocker()
editor = m.mock(Editor)
ac.find_window_with_editor = m.method(ac.find_window_with_editor)
ed = ac.find_window_with_editor(editor) >> m.mock(Window)
ed.current_editor = editor
with m:
ac.set_current_editor(editor)
示例11: test_Application_logger
def test_Application_logger():
root = logging.getLogger()
app = Application()
handler = app.errlog_handler
assert hasattr(app, "errlog"), app.errlog
assert handler not in root.handlers, root.handlers
with app.logger() as errlog:
handler = app.errlog_handler
assert handler in root.handlers, root.handlers
assert handler not in root.handlers, root.handlers
示例12: test
def test(c):
m = Mocker()
app = Application()
ed = m.mock(Editor)
if c.ed_in_eds:
app.editors.append(ed)
def verify():
assert ed not in app.editors, "ed cannot be in app.editors at this point"
expect(ed.close()).call(verify)
with m:
app.discard_editor(ed)
示例13: test_init_syntax_definitions
def test_init_syntax_definitions():
import editxt.syntax as syntax
m = Mocker()
app = Application(profile='/editxtdev')
rsrc_path = m.method(app.resource_path)() >> "/tmp/resources"
SyntaxFactory = m.replace(syntax, 'SyntaxFactory', spec=False)
sf = SyntaxFactory() >> m.mock(syntax.SyntaxFactory)
app_log = m.replace("editxt.application.log")
for path, info in [(rsrc_path, False), ('/editxtdev', True)]:
sf.load_definitions(join(path, const.SYNTAX_DEFS_DIR), info)
sf.index_definitions()
with m:
app.init_syntax_definitions()
示例14: do_save_window_settings
def do_save_window_settings(ed_count, close_ed, wsets, default_settings, all_settings):
m = Mocker()
ac = Application()
df_class = m.replace("editxt.application.NSUserDefaults")
defaults = MockUserDefaults()
defaults.setObject_forKey_(default_settings, const.WINDOW_SETTINGS_DEFAULTS_KEY)
ac.editors = eds = [m.mock(Editor) for x in xrange(ed_count)]
if close_ed < 6:
df_class.standardUserDefaults() >> defaults
eds[close_ed-1].window_settings >> wsets
with m:
ac.save_window_settings(eds[close_ed-1])
saved = defaults.arrayForKey_(const.WINDOW_SETTINGS_DEFAULTS_KEY)
eq_(saved, all_settings)
示例15: main
def main(argv=list(sys.argv)):
try:
if "--test" in argv or "--pdb" in argv:
DEFAULT_LOGGING_CONFIG['handlers']['console']['level'] = 'DEBUG'
use_pdb = "--pdb" in argv
if use_pdb:
argv.remove("--pdb")
objc.setVerbose(1)
# make PyObjC use our exception handler
Debugging.installExceptionHandler = install_exception_handler
if "--test" in argv:
from editxt.test.runner import TestApplication
app = TestApplication(argv)
else:
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
from editxt.application import Application
argv = argv[1:] # drop program name
doc = __doc__.replace('Profile directory.',
'Profile directory [default: {}].'
.format(Application.default_profile()))
opts = docopt.docopt(doc, argv, version=editxt.__version__)
app = Application(opts.get('--profile'))
editxt.app = app
run(app, argv, use_pdb)
except Exception as err:
if len(logging.root.handlers) == 0:
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
log.error('unhandled error', exc_info=True)
sys.exit(1)