本文整理匯總了Python中workflow.workflow.Workflow.run方法的典型用法代碼示例。如果您正苦於以下問題:Python Workflow.run方法的具體用法?Python Workflow.run怎麽用?Python Workflow.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類workflow.workflow.Workflow
的用法示例。
在下文中一共展示了Workflow.run方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_run_fails
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import run [as 別名]
def test_run_fails(infopl):
"""Run fails"""
wf = Workflow()
def cb(wf2):
assert wf2 is wf
raise ValueError('Have an error')
wf.help_url = 'http://www.deanishe.net/alfred-workflow/'
ret = wf.run(cb)
assert ret == 1
# read name from info.plist
with env(alfred_workflow_name=None):
wf = Workflow()
wf.name
ret = wf.run(cb)
assert ret == 1
# named after bundleid
wf = Workflow()
wf.bundleid
ret = wf.run(cb)
assert ret == 1
wf.reset()
示例2: test_last_version_set_after_run
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import run [as 別名]
def test_last_version_set_after_run(alfred4, infopl):
"""Workflow: last_version set after `run()`"""
vstr = '1.9.7'
def cb(wf):
return
with env(alfred_workflow_version=vstr):
wf = Workflow()
assert wf.last_version_run is None
wf.run(cb)
wf = Workflow()
assert wf.last_version_run == Version(vstr)
wf.reset()
示例3: test_last_version_set_after_run
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import run [as 別名]
def test_last_version_set_after_run(self):
"""Workflow: last_version set after `run()`"""
vstr = '1.9.7'
def cb(wf):
return
with VersionFile(vstr):
with InfoPlist():
wf = Workflow()
self.assertTrue(wf.last_version_run is None)
wf.run(cb)
wf = Workflow()
self.assertEqual(wf.last_version_run, Version(vstr))
wf.reset()
示例4: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import run [as 別名]
class WorkflowTests(unittest.TestCase):
def setUp(self):
self.libs = [os.path.join(os.path.dirname(__file__), "lib")]
self.wf = Workflow(libraries=self.libs)
self.account = "this-is-my-test-account"
self.password = "this-is-my-safe-password"
self.password2 = "this-is-my-other-safe-password"
self.search_items = [
("Test Item One", MATCH_STARTSWITH),
("test item two", MATCH_STARTSWITH),
("TwoExtraSpecialTests", MATCH_CAPITALS),
("this-is-a-test", MATCH_ATOM),
("the extra special trials", MATCH_INITIALS_STARTSWITH),
("not the extra special trials", MATCH_INITIALS_CONTAIN),
("intestinal fortitude", MATCH_SUBSTRING),
("the splits", MATCH_ALLCHARS),
("nomatch", 0),
]
self.search_items_diacritics = [
# search key, query
("Änderungen vorbehalten", "av"),
("Änderungen", "anderungen"),
("überwiegend bewolkt", "ub"),
("überwiegend", "uberwiegend"),
("Öffnungszeiten an Feiertagen", "offnungszeiten"),
("Öffnungszeiten an Feiertagen", "oaf"),
("Fußpilz", "fuss"),
("salé", "sale"),
]
def tearDown(self):
self.wf.clear_cache()
self.wf.clear_settings()
try:
self.wf.delete_password(self.account)
except PasswordNotFound:
pass
for dirpath in (self.wf.cachedir, self.wf.datadir):
if os.path.exists(dirpath):
shutil.rmtree(dirpath)
def test_item_creation(self):
"""XML generation"""
self.wf.add_item(
"title",
"subtitle",
"arg",
autocomplete="autocomplete",
valid=True,
uid="uid",
icon="icon.png",
icontype="fileicon",
type="file",
)
stdout = sys.stdout
sio = StringIO()
sys.stdout = sio
self.wf.send_feedback()
sys.stdout = stdout
output = sio.getvalue()
sio.close()
# pprint(output)
root = ET.fromstring(output)
item = list(root)[0]
self.assertEqual(item.attrib["uid"], "uid")
self.assertEqual(item.attrib["autocomplete"], "autocomplete")
self.assertEqual(item.attrib["valid"], "yes")
self.assertEqual(item.attrib["uid"], "uid")
title, subtitle, arg, icon = list(item)
self.assertEqual(title.text, "title")
self.assertEqual(title.tag, "title")
self.assertEqual(subtitle.text, "subtitle")
self.assertEqual(subtitle.tag, "subtitle")
self.assertEqual(arg.text, "arg")
self.assertEqual(arg.tag, "arg")
self.assertEqual(icon.text, "icon.png")
self.assertEqual(icon.tag, "icon")
self.assertEqual(icon.attrib["type"], "fileicon")
def test_item_creation_no_optionals(self):
"""XML generation (no optionals)"""
self.wf.add_item("title", valid=False)
stdout = sys.stdout
sio = StringIO()
sys.stdout = sio
self.wf.send_feedback()
sys.stdout = stdout
output = sio.getvalue()
sio.close()
# pprint(output)
root = ET.fromstring(output)
item = list(root)[0]
for key in ["uid", "arg", "autocomplete"]:
self.assertFalse(key in item.attrib)
self.assertEqual(item.attrib["valid"], "no")
title, subtitle = list(item)
self.assertEqual(title.text, "title")
self.assertEqual(title.tag, "title")
self.assertEqual(subtitle.text, None)
#.........這裏部分代碼省略.........
示例5: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import run [as 別名]
#.........這裏部分代碼省略.........
self.assertTrue(called['called'])
def test_cache_fresh(self):
"""Cached data is fresh"""
data = 'This is my data'
d = self.wf.cached_data('test', lambda: data, max_age=1)
self.assertEqual(d, data)
self.assertTrue(self.wf.cached_data_fresh('test', max_age=10))
def test_cache_fresh_non_existent(self):
"""Non-existant cache data is not fresh"""
self.assertEqual(self.wf.cached_data_fresh('popsicle', max_age=10000),
False)
def test_keychain(self):
"""Save/get/delete password"""
self.assertRaises(PasswordNotFound,
self.wf.delete_password, self.account)
self.assertRaises(PasswordNotFound, self.wf.get_password, self.account)
self.wf.save_password(self.account, self.password)
self.assertEqual(self.wf.get_password(self.account), self.password)
self.assertEqual(self.wf.get_password(self.account, BUNDLE_ID),
self.password)
# try to set same password
self.wf.save_password(self.account, self.password)
self.assertEqual(self.wf.get_password(self.account), self.password)
# try to set different password
self.wf.save_password(self.account, self.password2)
self.assertEqual(self.wf.get_password(self.account), self.password2)
# bad call to _call_security
with self.assertRaises(KeychainError):
self.wf._call_security('pants', BUNDLE_ID, self.account)
def test_run_fails(self):
"""Run fails"""
def cb(wf):
self.assertEqual(wf, self.wf)
raise ValueError('Have an error')
self.wf.name # cause info.plist to be parsed
ret = self.wf.run(cb)
self.assertEqual(ret, 1)
# named after bundleid
self.wf = Workflow()
self.wf.bundleid
ret = self.wf.run(cb)
self.assertEqual(ret, 1)
def test_run_okay(self):
"""Run okay"""
def cb(wf):
self.assertEqual(wf, self.wf)
ret = self.wf.run(cb)
self.assertEqual(ret, 0)
def test_filter_all_rules(self):
"""Filter: all rules"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True)
self.assertEqual(len(results), 8)
# now with scores, rules
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
include_score=True)
self.assertEqual(len(results), 8)
for item, score, rule in results:
self.wf.logger.debug('{} : {}'.format(item, score))
for value, r in self.search_items:
示例6: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import run [as 別名]
class WorkflowTests(unittest.TestCase):
def setUp(self):
self.libs = [os.path.join(os.path.dirname(__file__), 'lib')]
self.wf = Workflow(libraries=self.libs)
self.account = 'this-is-my-test-account'
self.password = 'this-is-my-safe-password'
self.password2 = 'this-is-my-other-safe-password'
self.search_items = [
('Test Item One', MATCH_STARTSWITH),
('test item two', MATCH_STARTSWITH),
('TwoExtraSpecialTests', MATCH_CAPITALS),
('this-is-a-test', MATCH_ATOM),
('the extra special trials', MATCH_INITIALS_STARTSWITH),
('not the extra special trials', MATCH_INITIALS_CONTAIN),
('intestinal fortitude', MATCH_SUBSTRING),
('the splits', MATCH_ALLCHARS),
('nomatch', 0),
]
self.search_items_diacritics = [
# search key, query
('Änderungen vorbehalten', 'av'),
('Änderungen', 'anderungen'),
('überwiegend bewolkt', 'ub'),
('überwiegend', 'uberwiegend'),
('Öffnungszeiten an Feiertagen', 'offnungszeiten'),
('Öffnungszeiten an Feiertagen', 'oaf'),
('Fußpilz', 'fuss'),
('salé', 'sale')
]
self.env_data = {
'alfred_preferences':
os.path.expanduser('~/Dropbox/Alfred/Alfred.alfredpreferences'),
'alfred_preferences_localhash':
b'adbd4f66bc3ae8493832af61a41ee609b20d8705',
'alfred_theme': b'alfred.theme.yosemite',
'alfred_theme_background': b'rgba(255,255,255,0.98)',
'alfred_theme_subtext': b'3',
'alfred_version': b'2.4',
'alfred_version_build': b'277',
'alfred_workflow_bundleid': b'com.alfredapp.david.googlesuggest',
'alfred_workflow_cache':
os.path.expanduser('~/Library/Caches/com.runningwithcrayons.'
'Alfred-2/Workflow Data/com.alfredapp.david'
'.googlesuggest'),
'alfred_workflow_data':
os.path.expanduser('~/Library/Application Support/Alfred 2/'
'Workflow Data/com.alfredapp.david.'
'googlesuggest'),
'alfred_workflow_name': b'Google Suggest',
'alfred_workflow_uid':
b'user.workflow.B0AC54EC-601C-479A-9428-01F9FD732959',
}
def tearDown(self):
self.wf.reset()
try:
self.wf.delete_password(self.account)
except PasswordNotFound:
pass
for dirpath in (self.wf.cachedir, self.wf.datadir):
if os.path.exists(dirpath):
shutil.rmtree(dirpath)
for key in self.env_data:
if key in os.environ:
del os.environ[key]
def test_item_creation(self):
"""XML generation"""
self.wf.add_item('title', 'subtitle', arg='arg',
autocomplete='autocomplete',
valid=True, uid='uid', icon='icon.png',
icontype='fileicon',
type='file', largetext='largetext',
copytext='copytext')
stdout = sys.stdout
sio = StringIO()
sys.stdout = sio
self.wf.send_feedback()
sys.stdout = stdout
output = sio.getvalue()
sio.close()
from pprint import pprint
pprint(output)
root = ET.fromstring(output)
item = list(root)[0]
self.assertEqual(item.attrib['uid'], 'uid')
self.assertEqual(item.attrib['autocomplete'], 'autocomplete')
self.assertEqual(item.attrib['valid'], 'yes')
self.assertEqual(item.attrib['uid'], 'uid')
title, subtitle, arg, icon, largetext, copytext = list(item)
self.assertEqual(title.text, 'title')
#.........這裏部分代碼省略.........
示例7: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import run [as 別名]
class WorkflowTests(unittest.TestCase):
"""Test suite for workflow.workflow.Workflow."""
def setUp(self):
self.libs = [os.path.join(os.path.dirname(__file__), b'lib')]
self.account = 'this-is-my-test-account'
self.password = 'this-is-my-safe-password'
self.password2 = 'this-is-my-other-safe-password'
self.password3 = 'this-pässwörd-is\\"non-ASCII"'
self.search_items = [
('Test Item One', MATCH_STARTSWITH),
('test item two', MATCH_STARTSWITH),
('TwoExtraSpecialTests', MATCH_CAPITALS),
('this-is-a-test', MATCH_ATOM),
('the extra special trials', MATCH_INITIALS_STARTSWITH),
('not the extra special trials', MATCH_INITIALS_CONTAIN),
('intestinal fortitude', MATCH_SUBSTRING),
('the splits', MATCH_ALLCHARS),
('nomatch', 0),
]
self.search_items_diacritics = [
# search key, query
('Änderungen vorbehalten', 'av'),
('Änderungen', 'anderungen'),
('überwiegend bewolkt', 'ub'),
('überwiegend', 'uberwiegend'),
('Öffnungszeiten an Feiertagen', 'offnungszeiten'),
('Öffnungszeiten an Feiertagen', 'oaf'),
('Fußpilz', 'fuss'),
('salé', 'sale')
]
self.punctuation_data = [
('"test"', '"test"'),
('„wat denn?“', '"wat denn?"'),
('‚wie dat denn?‘', "'wie dat denn?'"),
('“test”', '"test"'),
('and—why—not', 'and-why-not'),
('10–20', '10-20'),
('Shady’s back', "Shady's back"),
]
self.env_data = {
'alfred_debug': b'1',
'alfred_preferences':
os.path.expanduser(b'~/Dropbox/Alfred/Alfred.alfredpreferences'),
'alfred_preferences_localhash':
b'adbd4f66bc3ae8493832af61a41ee609b20d8705',
'alfred_theme': b'alfred.theme.yosemite',
'alfred_theme_background': b'rgba(255,255,255,0.98)',
'alfred_theme_subtext': b'3',
'alfred_version': b'2.4',
'alfred_version_build': b'277',
'alfred_workflow_bundleid': str(BUNDLE_ID),
'alfred_workflow_cache':
os.path.expanduser(b'~/Library/Caches/com.runningwithcrayons.'
b'Alfred-2/Workflow Data/{0}'.format(BUNDLE_ID)),
'alfred_workflow_data':
os.path.expanduser(b'~/Library/Application Support/Alfred 2/'
b'Workflow Data/{0}'.format(BUNDLE_ID)),
'alfred_workflow_name': b'Alfred-Workflow Test',
'alfred_workflow_uid':
b'user.workflow.B0AC54EC-601C-479A-9428-01F9FD732959',
}
self._setup_env()
create_info_plist()
self.wf = Workflow(libraries=self.libs)
def tearDown(self):
create_info_plist()
self.wf.reset()
try:
self.wf.delete_password(self.account)
except PasswordNotFound:
pass
for dirpath in (self.wf.cachedir, self.wf.datadir):
if os.path.exists(dirpath):
shutil.rmtree(dirpath)
self._teardown_env()
delete_info_plist()
####################################################################
# Environment
####################################################################
def test_additional_libs(self):
"""Additional libraries"""
for path in self.libs:
self.assert_(path in sys.path)
self.assertEqual(sys.path[0:len(self.libs)], self.libs)
import youcanimportme
youcanimportme.noop()
def test_info_plist(self):
"""info.plist"""
#.........這裏部分代碼省略.........
示例8: add_to_host_cache
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import run [as 別名]
vault_raw = subprocess.check_output('/usr/local/bin/lpass ls -l', shell=True)
for row in vault_raw.split('\n'):
if row != '(none)':
try:
hostname = row.split('/')[1].split(' [id:')[0]
host_id = row.split(' [id: ')[1].split('] ')[0]
username = row.split(' [username: ')[1].split(']')[0]
add_to_host_cache(hostname, host_id, username)
add_to_username_cache(hostname, host_id, username)
except:
None
wf.cache_data('hostIdList', vaultHostMap)
wf.cache_data('usernameList', vaultUsernameMap)
def add_to_host_cache(hostname, host_id, username):
vaultHostMap[hostname].append([host_id, username])
def add_to_username_cache(hostname, host_id, username):
vaultUsernameMap[username].append([host_id, hostname])
def send_feedback():
wf.send_feedback()
if __name__ == u"__main__":
sys.exit(wf.run(main))