当前位置: 首页>>代码示例>>Python>>正文


Python click.testing方法代码示例

本文整理汇总了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 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:24,代码来源:test_utils.py

示例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 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:26,代码来源:test_utils.py

示例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 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:24,代码来源:test_utils.py

示例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 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:15,代码来源:test_emailMan_unit.py

示例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 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:14,代码来源:test_emailMan_unit.py

示例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' 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:13,代码来源:test_emailMan_unit.py

示例7: runner

# 需要导入模块: import click [as 别名]
# 或者: from click import testing [as 别名]
def runner():
  from click.testing import CliRunner
  runner = CliRunner()
  return runner 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:6,代码来源:test_clickDescendents.py

示例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) 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:28,代码来源:test_utils.py

示例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) 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:12,代码来源:test_utils.py

示例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'] 
开发者ID:autofitcloud,项目名称:isitfit,代码行数:34,代码来源:test_utils.py

示例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) 
开发者ID:dcs4cop,项目名称:xcube,代码行数:5,代码来源:helpers.py

示例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) 
开发者ID:dcs4cop,项目名称:xcube,代码行数:5,代码来源:test_grid.py

示例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 
开发者ID:g-sherman,项目名称:plugin_build_tool,代码行数:11,代码来源:test_pb_tool.py

示例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)) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:16,代码来源:alert_monitor_test.py

示例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() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:7,代码来源:treadmill_cli_test.py


注:本文中的click.testing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。