Python click.testing() Examples
The following are 30
code examples of click.testing().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
click
, or try the search function
.
Example #1
Source File: test_utils.py From isitfit with Apache License 2.0 | 6 votes |
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
Example #2
Source File: test_utils.py From isitfit with Apache License 2.0 | 6 votes |
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
Example #3
Source File: test_utils.py From isitfit with Apache License 2.0 | 6 votes |
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
Example #4
Source File: allocation_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Setup common test variables""" self.runner = click.testing.CliRunner() self.alloc_mod = plugin_manager.load( 'treadmill.cli.admin.ldap', 'allocation' ) self.alloc_cli = self.alloc_mod.init()
Example #5
Source File: treadmill_cli_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): context.GLOBAL.dns_domain = 'xxx.com' self.module = treadmill.cli.admin.blackout self.runner = click.testing.CliRunner() self.cli = self.module.init()
Example #6
Source File: treadmill_cli_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): context.GLOBAL.dns_domain = 'xxx.com' self.module = treadmill.cli.admin.ldap self.runner = click.testing.CliRunner() self.cli = self.module.init()
Example #7
Source File: treadmill_cli_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): context.GLOBAL.dns_domain = 'xxx.com' self.module = treadmill.cli.discovery self.runner = click.testing.CliRunner() self.cli = self.module.init()
Example #8
Source File: treadmill_cli_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): context.GLOBAL.dns_domain = 'xxx.com' self.module = treadmill.cli.sproc self.runner = click.testing.CliRunner() self.cli = self.module.init()
Example #9
Source File: treadmill_cli_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): context.GLOBAL.dns_domain = 'xxx.com' self.module = treadmill.sproc.zk2fs self.runner = click.testing.CliRunner() self.cli = self.module.init()
Example #10
Source File: logs_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Setup common test variables""" self.runner = click.testing.CliRunner() self.log_mod = plugin_manager.load('treadmill.cli', 'logs') self.log_cli = self.log_mod.init()
Example #11
Source File: logs_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Setup common test variables""" self.runner = click.testing.CliRunner() self.log_mod = plugin_manager.load('treadmill.cli.admin', 'logs') self.log_cli = self.log_mod.init() context.GLOBAL.cell = 'test' context.GLOBAL.zk.url = 'zookeeper://xxx@yyy:123' context.GLOBAL.zk = mock.Mock()
Example #12
Source File: treadmill_cli_test.py From treadmill with Apache License 2.0 | 5 votes |
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()
Example #13
Source File: allocation_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Setup common test variables""" self.runner = click.testing.CliRunner() self.alloc_cli = plugin_manager.load('treadmill.cli', 'allocation').init()
Example #14
Source File: ssh_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Setup common test variables""" self.runner = click.testing.CliRunner() self.ssh_mod = plugin_manager.load('treadmill.cli', 'ssh') self.ssh_cli = self.ssh_mod.init()
Example #15
Source File: show_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Setup common test variables""" self.runner = click.testing.CliRunner() self.cli = plugin_manager.load('treadmill.cli', 'show').init()
Example #16
Source File: app_dns_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Setup common test variables""" self.runner = click.testing.CliRunner() self.app_dns = plugin_manager.load('treadmill.cli', 'app-dns').init()
Example #17
Source File: run_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Setup common test variables""" self.runner = click.testing.CliRunner() self.cli = plugin_manager.load('treadmill.cli', 'run').init()
Example #18
Source File: treadmill_cli_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): context.GLOBAL.dns_domain = 'xxx.com' self.module = treadmill.cli.admin.scheduler self.runner = click.testing.CliRunner() self.cli = self.module.init()
Example #19
Source File: test_emailMan_unit.py From isitfit with Apache License 2.0 | 5 votes |
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
Example #20
Source File: alert_monitor_test.py From treadmill with Apache License 2.0 | 5 votes |
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))
Example #21
Source File: test_pb_tool.py From plugin_build_tool with GNU General Public License v2.0 | 5 votes |
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
Example #22
Source File: test_grid.py From xcube with MIT License | 5 votes |
def invoke_cli(cls, args: List[str]): runner = click.testing.CliRunner() return runner.invoke(cli, args)
Example #23
Source File: helpers.py From xcube with MIT License | 5 votes |
def invoke_cli(self, args: List[str]): self.runner = click.testing.CliRunner() return self.runner.invoke(cli, args, catch_exceptions=False)
Example #24
Source File: test_utils.py From isitfit with Apache License 2.0 | 5 votes |
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']
Example #25
Source File: test_utils.py From isitfit with Apache License 2.0 | 5 votes |
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)
Example #26
Source File: test_utils.py From isitfit with Apache License 2.0 | 5 votes |
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)
Example #27
Source File: test_clickDescendents.py From isitfit with Apache License 2.0 | 5 votes |
def runner(): from click.testing import CliRunner runner = CliRunner() return runner
Example #28
Source File: test_emailMan_unit.py From isitfit with Apache License 2.0 | 5 votes |
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'
Example #29
Source File: test_emailMan_unit.py From isitfit with Apache License 2.0 | 5 votes |
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
Example #30
Source File: conftest.py From pythonfinder with MIT License | 4 votes |
def isolated_envdir(create_tmpdir): runner = click.testing.CliRunner() fake_root_path = create_tmpdir() fake_root = fake_root_path.as_posix() set_write_bit(fake_root) with temp_environ(), cd(fake_root): home_dir_path = fake_root_path.joinpath("home/pythonfinder") home_dir_path.mkdir(parents=True) home_dir = normalize_path(home_dir_path.as_posix()) os.chdir(home_dir) # This is pip's isolation approach, swipe it for now for time savings if sys.platform == "win32": home_drive, home_path = os.path.splitdrive(home_dir) os.environ.update( {"USERPROFILE": home_dir, "HOMEDRIVE": home_drive, "HOMEPATH": home_path} ) for env_var, sub_path in ( ("APPDATA", "AppData/Roaming"), ("LOCALAPPDATA", "AppData/Local"), ): path = os.path.join(home_dir, *sub_path.split("/")) os.environ[env_var] = path Path(path).mkdir(exist_ok=True, parents=True) else: os.environ["HOME"] = home_dir os.environ["XDG_DATA_HOME"] = os.path.join(home_dir, ".local", "share") os.environ["XDG_CONFIG_HOME"] = os.path.join(home_dir, ".config") os.environ["XDG_CACHE_HOME"] = os.path.join(home_dir, ".cache") os.environ["XDG_RUNTIME_DIR"] = os.path.join(home_dir, ".runtime") Path(os.path.join(home_dir, ".cache")).mkdir(exist_ok=True, parents=True) Path(os.path.join(home_dir, ".config")).mkdir(exist_ok=True, parents=True) Path(os.path.join(home_dir, ".local", "share")).mkdir(exist_ok=True, parents=True) Path(os.path.join(fake_root, "usr", "local", "share")).mkdir(exist_ok=True, parents=True) Path(os.path.join(fake_root, "usr", "share")).mkdir(exist_ok=True, parents=True) os.environ["XDG_DATA_DIRS"] = ":".join( [ os.path.join(fake_root, "usr", "local", "share"), os.path.join(fake_root, "usr", "share"), ] ) os.environ["PATH"] = os.defpath yield home_dir_path