本文整理匯總了Python中workflow.workflow.Workflow.add_item方法的典型用法代碼示例。如果您正苦於以下問題:Python Workflow.add_item方法的具體用法?Python Workflow.add_item怎麽用?Python Workflow.add_item使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類workflow.workflow.Workflow
的用法示例。
在下文中一共展示了Workflow.add_item方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import add_item [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),
]
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)
tags = [elem.tag for elem in list(item)]
for tag in ['icon', 'arg']:
self.assert_(tag not in tags)
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
def test_info_plist(self):
"""info.plist"""
self.assertEqual(self.wf.name, WORKFLOW_NAME)
self.assertEqual(self.wf.bundleid, BUNDLE_ID)
#.........這裏部分代碼省略.........
示例2: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import add_item [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)
#.........這裏部分代碼省略.........
示例3: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import add_item [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')
#.........這裏部分代碼省略.........