本文整理汇总了Python中workflow.Workflow.clear_cache方法的典型用法代码示例。如果您正苦于以下问题:Python Workflow.clear_cache方法的具体用法?Python Workflow.clear_cache怎么用?Python Workflow.clear_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类workflow.Workflow
的用法示例。
在下文中一共展示了Workflow.clear_cache方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RatesFmtTest
# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import clear_cache [as 别名]
class RatesFmtTest(unittest.TestCase):
def setUp(self):
self.wf = Workflow()
self.wf.clear_settings()
self.wf.clear_data()
self.wf.clear_cache()
self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'BRL'
rates.log = self.wf.logger
def tearDown(self):
pass
def testFmtNumberComma(self):
self.wf.settings[rates.SETTINGS_DEFAULT_NUMBER_DIVISOR] = ','
result = rates.format_result(self.wf, Decimal('1001.0123'))
self.assertEquals(result, '1.001,0123')
def testFmtNumberDot(self):
self.wf.settings[rates.SETTINGS_DEFAULT_NUMBER_DIVISOR] = '.'
result = rates.format_result(self.wf, Decimal('1001.0123'))
self.assertEquals(result, '1,001.0123')
示例2: RatesCurrencyTest
# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import clear_cache [as 别名]
class RatesCurrencyTest(unittest.TestCase):
def setUp(self):
self.wf = Workflow()
self.wf.clear_settings()
self.wf.clear_data()
self.wf.clear_cache()
rates.log = self.wf.logger
def tearDown(self):
pass
def testLoadCurrencyInfo(self):
currency_info = rates.get_currencies()
# Checks if all itens have all info that is used by the script
for currency, info in currency_info.iteritems():
self.assertIn('Id', info, 'No ID for currency {}'.format(info))
self.assertTrue(info['Id'], 'None ID specified for currency {}'.format(info))
self.assertIn('Name', info, 'No Name for currency {}'.format(info))
self.assertTrue(info['Name'], 'No Name for currency {}'.format(info))
self.assertIn('Code', info, 'No Code for currency {}'.format(info))
self.assertTrue(info['Code'], 'No Code for currency {}'.format(info))
self.assertIn('Simbol', info, 'No Simbol for currency {}'.format(info))
self.assertTrue(info['Simbol'], 'No Simbol for currency {}'.format(info))
self.assertIn('Country', info, 'No Country for currency {}'.format(info))
self.assertTrue(info['Country'], 'No Country for currency {}'.format(info))
self.assertIn('Flag', info, 'No Flag for currency {}'.format(info))
def test_is_float(self):
tests = [(1, True),
('asd', False),
(1.5, True),
('1', True),
('1', True)]
for test in tests:
self.assertEqual(rates.is_float(test[0]), test[1])
def test_validate_currencies(self):
currencies = rates.get_currencies()
self.assertTrue(rates.validate_currencies([], 'BRL', 'USD', currencies, self.wf))
self.assertFalse(rates.validate_currencies([], 'BRL', 'USDD', currencies, self.wf))
self.assertFalse(rates.validate_currencies([], 'BRLL', 'USD', currencies, self.wf))
def test_clear_caches(self):
self.wf.cache_data('test_cache', 'testing cache')
self.wf.store_data('test_store', 'testing store')
with patch.object(sys, 'argv', 'program --clear'.split()):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertEqual(self.wf._items[0].title, 'Caches cleared!')
self.assertIsNone(self.wf.stored_data('test_store'))
self.assertIsNone(self.wf.cached_data('test_cache'))
def test_evaluate_math(self):
tests = [
(['100*3', '100'], ['300', '100']),
(['135.3*2', '234.5-5'], ['270.6', '229.5']),
(['123/2', '61.5*50'], ['61.5', '3075.0']),
(['123.5*2.5'], ['308.75']),
# (['123', '/2', '61.5*50'], ['61.5', '3075.0']),
# (['123', '/', '2', '61.5*50'], ['61.5', '3075.0']),
# (['123', '/2', '/', '2', '61.5*50'], ['30.75', '3075.0']),
# (['123', '/2', '/', '2', '61.5*50', '/3', '*2'], ['30.75', '2050.0'])
# (['123*', '2'], ['246'])
# (['100*2', 'usd', 'brl'], ['200', 'usd', 'brl'])
]
for t in tests:
result = rates.evaluate_math(t[0])
self.assertEqual(result, t[1])
def test_fmt_number(self):
tests = [
('100.00', '.', '100.00'),
('100.00', ',', '100,00'),
('1.000,00', '.', '1,000.00'),
('100', None, '100')
]
for t in tests:
result = rates.fmt_number(t[0], t[1])
self.assertEqual(result, t[2])
示例3: Workflow
# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import clear_cache [as 别名]
# !/usr/bin/python
# encoding: utf-8
from workflow import Workflow
wf = Workflow()
wf.clear_cache()
wf.add_item(u'清除完毕')
wf.send_feedback();
示例4: TestRatesConvert
# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import clear_cache [as 别名]
class TestRatesConvert(unittest.TestCase):
def setUp(self):
self.wf = Workflow()
self.wf.clear_settings()
self.wf.clear_data()
self.wf.clear_cache()
self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'BRL'
rates.log = self.wf.logger
def tearDown(self):
pass
def test_full_convert(self):
with patch.object(sys, 'argv', ['program', '100', 'BRL', 'CLP']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('BRL (Brazilian real) -> CLP (Chilean peso) with rate'), -1)
def test_inverted_full_convert(self):
with patch.object(sys, 'argv', ['program', '100', 'CLP', 'BRL']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('CLP (Chilean peso) -> BRL (Brazilian real) with rate'), -1)
def test_convert_from_default_to_other(self):
with patch.object(sys, 'argv', ['program', '100', 'CLP']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('BRL (Brazilian real) -> CLP (Chilean peso) with rate'), -1)
def test_convert_from_other_to_default(self):
with patch.object(sys, 'argv', ['program', 'CLP', '100']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('CLP (Chilean peso) -> BRL (Brazilian real) with rate'), -1)
def test_convert_from_default_to_other_without_values(self):
self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'USD'
with patch.object(sys, 'argv', ['program', 'BRL']):
rates.main(self.wf)
self.assertTrue(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('USD (United States dollar) -> BRL (Brazilian real)'), -1)
def test_invalid_currency_number_to_convert(self):
with patch.object(sys, 'argv', 'program zupa BRL USD'.split()):
ret = rates.main(self.wf)
self.assertTrue(ret, 100)
def test_invalid_currency_number_to_convert_using_default(self):
with patch.object(sys, 'argv', 'program zupa BRL'.split()):
ret = rates.main(self.wf)
self.assertTrue(ret, 100)
def test_invalid_argument(self):
with patch.object(sys, 'argv', 'program zupa'.split()):
ret = rates.main(self.wf)
# 100 means auto complete
self.assertEqual(ret, 100)
def test_convert_case_insensitive(self):
with patch.object(sys, 'argv', 'program 1 brl clp'.split()):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('BRL (Brazilian real) -> CLP (Chilean peso) with rate'), -1)
def test_convert_eur(self):
# This test is because of a bug with displaying EUR symbol
with patch.object(sys, 'argv', 'program 1 USD EUR'.split()):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('USD (United States dollar) -> EUR (Euro) with rate'), -1)
def test_extract_filter_params(self):
currencies = rates.get_currencies()
# List of tuple (Params, Expected Result)
test_itens = [('100 Braz'.split(), ['Braz']),
(['Braz'], ['Braz']),
('100 CLP United States'.split(), ['United', 'States']),
([''], []),
([], [])]
for test in test_itens:
resp = rates.extract_filter_params(test[0], currencies)
self.assertEqual(resp, test[1])
示例5: TestRatesConvert
# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import clear_cache [as 别名]
class TestRatesConvert(unittest.TestCase):
def setUp(self):
self.wf = Workflow()
self.wf.clear_settings()
self.wf.clear_data()
self.wf.clear_cache()
self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'BRL'
rates.log = self.wf.logger
def tearDown(self):
pass
def test_full_convert(self):
with patch.object(sys, 'argv', ['program', '100 BRL CLP']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
def test_full_convert_multi_query(self):
with patch.object(sys, 'argv', ['program', '100 BRL CLP; 100 USD BRL; 100 GBP CAD']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 3)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
self.assertNotEqual(self.wf._items[1].subtitle.find('(United States dollar) -> (Brazilian real) with rate'), -1)
self.assertNotEqual(self.wf._items[2].subtitle.find('(British pound [B]) -> (Canadian dollar) with rate'), -1)
def test_inverted_full_convert(self):
with patch.object(sys, 'argv', ['program', '100 CLP BRL']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Chilean peso) -> (Brazilian real) with rate'), -1)
def test_convert_from_default_to_other(self):
with patch.object(sys, 'argv', ['program', '100 CLP']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
def test_convert_from_default_to_other_multi_query(self):
with patch.object(sys, 'argv', ['program', '100 BRL CLP; 100 GBP; 100 GBP CAD']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 3)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
self.assertNotEqual(self.wf._items[1].subtitle.find('(Brazilian real) -> (British pound [B]) with rate'), -1)
self.assertNotEqual(self.wf._items[2].subtitle.find('(British pound [B]) -> (Canadian dollar) with rate'), -1)
def test_convert_from_other_to_default(self):
with patch.object(sys, 'argv', ['program', 'CLP 100']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Chilean peso) -> (Brazilian real) with rate'), -1)
def test_convert_from_other_to_default_multi_query(self):
with patch.object(sys, 'argv', ['program', '100 BRL CLP; GBP 100; 100 GBP CAD']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 3)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
self.assertNotEqual(self.wf._items[1].subtitle.find('(British pound [B]) -> (Brazilian real) with rate'), -1)
self.assertNotEqual(self.wf._items[2].subtitle.find('(British pound [B]) -> (Canadian dollar) with rate'), -1)
def test_convert_from_default_to_other_without_values(self):
self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'USD'
with patch.object(sys, 'argv', ['program', 'BRL']):
rates.main(self.wf)
self.assertTrue(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('(United States dollar) -> (Brazilian real)'), -1)
def test_convert_from_detault_to_other_without_values_multi_query(self):
self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'USD'
with patch.object(sys, 'argv', ['program', '100 BRL CLP; GBP; 100 GBP CAD']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 3)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
self.assertNotEqual(self.wf._items[1].subtitle.find('(United States dollar) -> (British pound [B]) with rate'), -1)
self.assertNotEqual(self.wf._items[2].subtitle.find('(British pound [B]) -> (Canadian dollar) with rate'), -1)
def test_invalid_currency_number_to_convert(self):
with patch.object(sys, 'argv', ['program', 'zupa BRL USD']):
ret = rates.main(self.wf)
self.assertTrue(ret, 100)
def test_invalid_currency_number_to_convert_using_default(self):
with patch.object(sys, 'argv', ['program', 'zupa BRL']):
ret = rates.main(self.wf)
self.assertTrue(ret, 100)
def test_invalid_argument(self):
with patch.object(sys, 'argv', ['program', 'zupa']):
ret = rates.main(self.wf)
# 100 means auto complete
self.assertEqual(ret, 100)
def test_convert_case_insensitive(self):
with patch.object(sys, 'argv', ['program', '1 brl clp']):
rates.main(self.wf)
self.assertEqual(len(self.wf._items), 1)
self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
#.........这里部分代码省略.........
示例6: set_api_key
# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import clear_cache [as 别名]
open_parser.add_argument('repo_url', action='store', help='Repository URL')
open_parser = subparsers.add_parser('cache', help='Cache operation')
open_parser.add_argument('operation', action='store', help='Command to run')
return parser.parse_args()
def set_api_key(api_key, workflow):
workflow.save_password('api_key', api_key)
notify('Alfred Github', 'API key successfully set')
sys.exit()
def open_repository(url):
print webbrowser.open(url, new=2, autoraise=True)
if __name__ == '__main__':
args = parse_args()
workflow = Workflow()
if args.command == 'key':
set_api_key(args.api_key, workflow)
if args.command == 'open':
open_repository(args.repo_url)
if args.command == 'cache':
if args.operation == 'clear':
workflow.clear_cache()
notify('Alfred Github', 'Cache was cleared')