本文整理匯總了Python中click.testing方法的典型用法代碼示例。如果您正苦於以下問題:Python click.testing方法的具體用法?Python click.testing怎麽用?Python click.testing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類click
的用法示例。
在下文中一共展示了click.testing方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_oneInputNoLast
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_oneInputNoLast(self, ping_matomo):
"""
# build a fake click command so that the click.prompt will be emulated
# https://click.palletsprojects.com/en/7.x/testing/?highlight=test#input-streams
"""
import click
@click.command()
def cmd():
from isitfit.utils import PromptToEmailIfNotRequested
pte = PromptToEmailIfNotRequested()
import tempfile
with tempfile.NamedTemporaryFile() as fh:
pte.last_email_cl.fn = fh.name # overwrite file to save last-used email
pte.prompt(None)
# trigger
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cmd, input='me@example.com\n')
print(result.__dict__) # in case of exception, this will show details
assert not result.exception
assert '[skip]' in result.output
示例2: test_oneInputSetLast
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_oneInputSetLast(self, ping_matomo):
"""
# build a fake click command so that the click.prompt will be emulated
# https://click.palletsprojects.com/en/7.x/testing/?highlight=test#input-streams
"""
import click
@click.command()
def cmd():
from isitfit.utils import PromptToEmailIfNotRequested
pte = PromptToEmailIfNotRequested()
import tempfile
with tempfile.NamedTemporaryFile() as fh:
pte.last_email_cl.fn = fh.name # overwrite file to save last-used email
pte.last_email_cl.set('me@example.com')
pte.prompt(None)
# trigger
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cmd, input='\n')
print(result.__dict__) # in case of exception, this will show details
assert not result.exception
assert '[skip]' not in result.output
assert '[me@example.com]' in result.output
示例3: test_pdSubsetLatest
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_pdSubsetLatest():
import pandas as pd
df_in = pd.DataFrame(
{
'a': [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13],
'b': [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 2],
},
index = [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13]
)
df_expected = pd.DataFrame(
{
'a': [10,11,12,13],
'b': [ 2, 2, 2, 2]
},
index = [10,11,12,13]
)
from isitfit.utils import pd_subset_latest
df_actual = pd_subset_latest(df_in, 'b', 'a')
pd.testing.assert_frame_equal(df_actual, df_expected)
assert len(set(df_actual.b.to_list())) == 1
示例4: sendemail_fac
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def sendemail_fac(MockEmailManFactory):
def factory(response_list):
# build a fake click command so that the click.prompt will be emulated
# https://click.palletsprojects.com/en/7.x/testing/?highlight=test#input-streams
import click
@click.command()
def cmd():
em = MockEmailManFactory(response_list)
em.send(['foo@bar.com'])
return cmd
return factory
示例5: test_send_verificationInProgress_okAfter1stAttempt
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_send_verificationInProgress_okAfter1stAttempt(self, sendemail_fac):
r1 = isitfit_return_helper('Email verification in progress', 'foo', None)
r2 = isitfit_return_helper('ok', 'foo', {'from': 'bla'})
sendemail_cmd = sendemail_fac([r1,r2])
# trigger
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(sendemail_cmd, input='\n')
print(result.__dict__) # in case of exception, this will show details
assert not result.exception
assert True # no exception
示例6: test_send_verificationInProgress_failsAfter3Attempts
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_send_verificationInProgress_failsAfter3Attempts(self, sendemail_fac):
r1 = isitfit_return_helper('Email verification in progress', 'foo', None)
sendemail_cmd = sendemail_fac([r1,r1,r1])
# trigger
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(sendemail_cmd, input='\n\n\n')
print(result.__dict__) # in case of exception, this will show details
assert result.exception
assert type(result.exception).__name__ == 'ValueError'
示例7: runner
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def runner():
from click.testing import CliRunner
runner = CliRunner()
return runner
示例8: test_mergeSeriesOnTimestampRange
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_mergeSeriesOnTimestampRange():
import pandas as pd
df_cpu = pd.DataFrame({'Timestamp': [1,2,3,4], 'field_1': [5,6,7,8]})
df_type = pd.DataFrame({'Timestamp': [1,3], 'field_2': ['a','b']})
# update 2019-11-20 had initially written example as field_2: a, a, b, b
# but maybe that was an outdated example
expected = pd.DataFrame({'Timestamp': [1,2,3,4], 'field_1': [5,6,7,8], 'field_2': ['a','b','b','b']})
# reverse sort
df_cpu = df_cpu.sort_values(['Timestamp'], ascending=False)
df_type = df_type.sort_values(['Timestamp'], ascending=False)
# set index
df_type = df_type.set_index('Timestamp')
# test
from ..utils import mergeSeriesOnTimestampRange
actual = mergeSeriesOnTimestampRange(df_cpu, df_type, ['field_2'])
# straight sort
actual = actual.sort_values(['Timestamp'], ascending=True)
#print(expected)
#print(actual)
pd.testing.assert_frame_equal(expected, actual)
示例9: test_pandasSets_differentIndex
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_pandasSets_differentIndex():
from isitfit.utils import pd_series_frozenset_union
import pandas as pd
fset = frozenset
s1=pd.Series([fset([1]), fset([1,2])], index=[0,1])
s2=pd.Series([fset([1])], index=[0])
actual = pd_series_frozenset_union(s1, s2)
expected = pd.DataFrame({'a3': [fset([1]), fset([1,2])]})
pd.testing.assert_series_equal(actual, expected.a3)
示例10: test_userInput
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_userInput(self):
import click
from click.testing import CliRunner
class MyWrap:
def dummyFac(self, emailIn, emailPrompt):
self.emailOut = None
@click.command()
def dummyCmd():
from isitfit.utils import PromptToEmailIfNotRequested
pte = PromptToEmailIfNotRequested()
import tempfile
with tempfile.NamedTemporaryFile() as fh:
pte.last_email_cl.fn = fh.name # overwrite file to save last-used email
# dont set to leave blank # pte.last_email_cl.set('me@example.com')
self.emailOut = pte.prompt(emailIn)
# https://stackoverflow.com/q/38143366/4126114
runner = CliRunner()
result = runner.invoke(dummyCmd, input=emailPrompt)
return self.emailOut
mw = MyWrap()
actual = mw.dummyFac(None, '\n')
assert actual is None
actual = mw.dummyFac(None, 'n\n')
assert actual is None
actual = mw.dummyFac(None, 'y\nshadi@abc.com')
assert actual == ['shadi@abc.com']
actual = mw.dummyFac(None, 'y\nbla\nshadi@abc.com')
assert actual == ['shadi@abc.com']
示例11: invoke_cli
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def invoke_cli(self, args: List[str]):
self.runner = click.testing.CliRunner()
return self.runner.invoke(cli, args, catch_exceptions=False)
示例12: invoke_cli
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def invoke_cli(cls, args: List[str]):
runner = click.testing.CliRunner()
return runner.invoke(cli, args)
示例13: test_compile
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_compile():
result = runner.invoke(pb_tool.cli, ['compile'])
assert result.exit_code == 0
# results.append("Command validate failed: {}".format(result.output))
#print("testing validate: {}".format(result))
#result = runner.invoke(pb_tool.cli, ['zip', '-q'])
#print("testing zip: {}".format(result))
#print results
示例14: test_alert_monitor_cmd
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def test_alert_monitor_cmd(self, mock_appenv, mock_load):
"""Test alert_monitor_cmd().
"""
mock_backend = mock_load.return_value
with tempfile.TemporaryDirectory() as dir_name:
mock_appenv.AppEnvironment.return_value.alerts_dir = dir_name
alert_monitor_cli = alert_monitor.init()
run = click.testing.CliRunner().invoke(
alert_monitor_cli, ['--approot', os.getcwd()]
)
self.assertEqual(run.exit_code, 0, str(run))
示例15: setUp
# 需要導入模塊: import click [as 別名]
# 或者: from click import testing [as 別名]
def setUp(self):
context.GLOBAL.dns_domain = 'xxx.com'
self.module = treadmill.cli.admin.show
self.runner = click.testing.CliRunner()
self.cli = self.module.init()