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


Python MagicMock.stdout方法代码示例

本文整理汇总了Python中mock.mock.MagicMock.stdout方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.stdout方法的具体用法?Python MagicMock.stdout怎么用?Python MagicMock.stdout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.mock.MagicMock的用法示例。


在下文中一共展示了MagicMock.stdout方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_action_create_nonexistent

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_action_create_nonexistent(self, getpwnam_mock, popen_mock):
    subproc_mock = MagicMock()
    subproc_mock.returncode = 0
    subproc_mock.stdout = subproc_stdout
    popen_mock.return_value = subproc_mock
    getpwnam_mock.return_value = None
    with Environment('/') as env:
      user = User("mapred", action = "create", shell = "/bin/bash")

    popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "ambari-sudo.sh  PATH=/bin -H -E useradd -m -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None, close_fds=True)
    self.assertEqual(popen_mock.call_count, 1)
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:13,代码来源:TestUserResource.py

示例2: test_attribute_try_sleep_tries

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_attribute_try_sleep_tries(self, popen_mock, time_mock, select_mock, os_read_mock):
    expected_call = "call('Retrying after %d seconds. Reason: %s', 1, 'Fail')"
    
    subproc_mock_one = MagicMock()
    subproc_mock_one.returncode = 1
    subproc_mock_one.stdout = MagicMock()
    subproc_mock_zero = MagicMock()
    subproc_mock_zero.stdout = MagicMock()
    subproc_mock_zero.returncode = 0
    #subproc_mock.stdout.readline = MagicMock(side_effect = [Fail("Fail"), "OK"])
    popen_mock.side_effect = [subproc_mock_one, subproc_mock_zero]
    select_mock.side_effect = [([subproc_mock_one.stdout], None, None),([subproc_mock_zero.stdout], None, None)]
    os_read_mock.return_value = None

    with Environment("/") as env:
      Execute('echo "1"',
              tries=2,
              try_sleep=10
      )
    pass

    self.assertTrue(call(10) in time_mock.call_args_list)
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:24,代码来源:TestExecuteResource.py

示例3: test_attribute_groups

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_attribute_groups(self, getpwnam_mock, popen_mock, user_groups_mock):
    subproc_mock = MagicMock()
    subproc_mock.returncode = 0
    user_groups_mock.return_value = ['hadoop']
    subproc_mock.stdout = subproc_stdout
    popen_mock.return_value = subproc_mock
    getpwnam_mock.return_value = _get_user_entity()

    with Environment('/') as env:
      user = User("mapred", action = "create", groups = ['1','2','3'], 
          shell = "/bin/bash")

    popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', 'ambari-sudo.sh  PATH=/bin -H -E usermod -s /bin/bash -G 1,2,3,hadoop mapred'], shell=False, preexec_fn=None, env={'PATH': '/bin'}, close_fds=True, stdout=-1, stderr=-2, cwd=None)
    self.assertEqual(popen_mock.call_count, 1)
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:16,代码来源:TestUserResource.py

示例4: test_attribute_path

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
 def test_attribute_path(self, popen_mock, select_mock, os_read_mock):
   subproc_mock = MagicMock()
   subproc_mock.wait.return_value = MagicMock()
   subproc_mock.stdout = MagicMock()
   subproc_mock.returncode = 0
   popen_mock.return_value = subproc_mock
   select_mock.return_value = ([subproc_mock.stdout], None, None)
   os_read_mock.return_value = None
   
   with Environment("/") as env:
     execute_resource = Execute('echo "1"',
                                path=["/test/one", "test/two"]
     )
   expected_command = ['/bin/bash', '--login', '--noprofile', '-c', 'echo "1"']
   self.assertEqual(popen_mock.call_args_list[0][0][0], expected_command)
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:17,代码来源:TestExecuteResource.py

示例5: test_attribute_command_one_line

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_attribute_command_one_line(self, popen_mock, select_mock, os_read_mock):
    expected_command = "rm -rf /somedir"

    subproc_mock = MagicMock()
    subproc_mock.wait.return_value = MagicMock()
    subproc_mock.stdout = MagicMock()
    subproc_mock.returncode = 0
    popen_mock.return_value = subproc_mock
    select_mock.return_value = ([subproc_mock.stdout], None, None)
    os_read_mock.return_value = None

    with Environment("/") as env:
      Execute(expected_command)

    self.assertEqual(popen_mock.call_args_list[0][0][0][4], expected_command)
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:17,代码来源:TestExecuteResource.py

示例6: test_action_create_nonexistent

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_action_create_nonexistent(self, popen_mock, getgrnam_mock):
    subproc_mock = MagicMock()
    subproc_mock.returncode = 0
    subproc_mock.stdout = subproc_stdout
    popen_mock.return_value = subproc_mock
    getgrnam_mock.side_effect = KeyError()

    with Environment('/') as env:
      Group('hadoop',
            action='create',
            password='secure'
      )
    

    self.assertEqual(popen_mock.call_count, 1)
    popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "ambari-sudo.sh  PATH=/bin -H -E groupadd -p secure hadoop"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None, close_fds=True)
    getgrnam_mock.assert_called_with('hadoop')
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:19,代码来源:TestGroupResource.py

示例7: test_action_remove

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_action_remove(self, popen_mock, getgrnam_mock):

    subproc_mock = MagicMock()
    subproc_mock.returncode = 0
    subproc_mock.stdout = subproc_stdout
    popen_mock.return_value = subproc_mock
    getgrnam_mock.return_value = _get_group()

    with Environment('/') as env:
      Group('mapred',
            action='remove'
      )
    

    self.assertEqual(popen_mock.call_count, 1)
    popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', 'ambari-sudo.sh  PATH=/bin -H -E groupdel mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None, close_fds=True)
    getgrnam_mock.assert_called_with('mapred')
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:19,代码来源:TestGroupResource.py

示例8: test_attribute_logoutput

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_attribute_logoutput(self, popen_mock, info_mock, select_mock, os_read_mock):
    subproc_mock = MagicMock()
    subproc_mock.wait.return_value = MagicMock()
    subproc_mock.stdout = MagicMock()
    subproc_mock.returncode = 0
    popen_mock.return_value = subproc_mock
    select_mock.return_value = ([subproc_mock.stdout], None, None)
    os_read_mock.return_value = None

    with Environment("/") as env:
      Execute('echo "1"',
              logoutput=True)
      Execute('echo "2"',
              logoutput=False)

    info_mock.assert_called('1')
    self.assertTrue("call('2')" not in str(info_mock.mock_calls))
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:19,代码来源:TestExecuteResource.py

示例9: test_attribute_cwd

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_attribute_cwd(self, popen_mock, select_mock, os_read_mock):
    expected_cwd = "/test/work/directory"

    subproc_mock = MagicMock()
    subproc_mock.wait.return_value = MagicMock()
    subproc_mock.stdout = MagicMock()
    subproc_mock.returncode = 0
    popen_mock.return_value = subproc_mock
    select_mock.return_value = ([subproc_mock.stdout], None, None)
    os_read_mock.return_value = None

    with Environment("/") as env:
      Execute('echo "1"',
              cwd=expected_cwd
      )

    self.assertEqual(popen_mock.call_args_list[0][1]["cwd"], expected_cwd)
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:19,代码来源:TestExecuteResource.py

示例10: test_attribute_environment

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_attribute_environment(self, popen_mock, select_mock, os_read_mock):
    expected_dict = {"JAVA_HOME": "/test/java/home"}

    subproc_mock = MagicMock()
    subproc_mock.wait.return_value = MagicMock()
    subproc_mock.stdout = MagicMock()
    subproc_mock.returncode = 0
    popen_mock.return_value = subproc_mock
    select_mock.return_value = ([subproc_mock.stdout], None, None)
    os_read_mock.return_value = None

    with Environment("/") as env:
      Execute('echo "1"',
              environment=expected_dict
      )

    self.assertEqual(popen_mock.call_args_list[0][1]["env"], expected_dict)
    pass
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:20,代码来源:TestExecuteResource.py

示例11: test_action_create_fail

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_action_create_fail(self, popen_mock, getgrnam_mock):
    subproc_mock = MagicMock()
    subproc_mock.returncode = 1
    subproc_mock.stdout = subproc_stdout
    popen_mock.return_value = subproc_mock
    getgrnam_mock.return_value = _get_group()

    try:
      with Environment('/') as env:
        Group('mapred',
              action='create',
              gid=2,
              password='secure'
        )
      
      self.fail("Action 'create' should fail when checked_call fails")
    except Fail:
      pass
    self.assertEqual(popen_mock.call_count, 1)
    popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "ambari-sudo.sh  PATH=/bin -H -E groupmod -p secure -g 2 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None, close_fds=True)
    getgrnam_mock.assert_called_with('mapred')
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:23,代码来源:TestGroupResource.py

示例12: test_attribute_environment_non_root

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_attribute_environment_non_root(self, popen_mock, select_mock, os_read_mock):
    expected_user = 'test_user'

    subproc_mock = MagicMock()
    subproc_mock.wait.return_value = MagicMock()
    subproc_mock.stdout = MagicMock()
    subproc_mock.returncode = 0
    popen_mock.return_value = subproc_mock
    select_mock.return_value = ([subproc_mock.stdout], None, None)
    os_read_mock.return_value = None

    with Environment("/") as env:
      execute_resource = Execute('echo "1"',
                                 user=expected_user,
                                 environment={'JAVA_HOME': '/test/java/home',
                                              'PATH': "/bin"}
      )
      

    expected_command = ['/bin/bash', '--login', '--noprofile', '-c', 'ambari-sudo.sh su test_user -l -s /bin/bash -c ' + quote_bash_args('export  PATH=' + quote_bash_args(os.environ['PATH'] + ':/bin') + ' JAVA_HOME=/test/java/home ; echo "1"')]
    self.assertEqual(popen_mock.call_args_list[0][0][0], expected_command)
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:23,代码来源:TestExecuteResource.py

示例13: test_attribute_command_escaping

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import stdout [as 别名]
  def test_attribute_command_escaping(self, popen_mock, select_mock, os_read_mock):
    expected_command0 = "arg1 arg2 'quoted arg'"
    expected_command1 = "arg1 arg2 'command \"arg\"'"
    expected_command2 = 'arg1 arg2 \'command \'"\'"\'arg\'"\'"\'\''
    expected_command3 = "arg1 arg2 'echo `ls /root`'"
    expected_command4 = "arg1 arg2 '$ROOT'"
    expected_command5 = "arg1 arg2 '`ls /root`'"

    subproc_mock = MagicMock()
    subproc_mock.wait.return_value = MagicMock()
    subproc_mock.stdout = MagicMock()
    subproc_mock.returncode = 0
    popen_mock.return_value = subproc_mock
    select_mock.return_value = ([subproc_mock.stdout], None, None)
    os_read_mock.return_value = None

    with Environment("/") as env:
      Execute(('arg1', 'arg2', 'quoted arg'),
      )
      Execute(('arg1', 'arg2', 'command "arg"'),
      )
      Execute(('arg1', 'arg2', "command 'arg'"),
      )
      Execute(('arg1', 'arg2', "echo `ls /root`"),
      )
      Execute(('arg1', 'arg2', "$ROOT"),
      )
      Execute(('arg1', 'arg2', "`ls /root`"),
      )

    self.assertEqual(popen_mock.call_args_list[0][0][0][4], expected_command0)
    self.assertEqual(popen_mock.call_args_list[1][0][0][4], expected_command1)
    self.assertEqual(popen_mock.call_args_list[2][0][0][4], expected_command2)
    self.assertEqual(popen_mock.call_args_list[3][0][0][4], expected_command3)
    self.assertEqual(popen_mock.call_args_list[4][0][0][4], expected_command4)
    self.assertEqual(popen_mock.call_args_list[5][0][0][4], expected_command5)
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:38,代码来源:TestExecuteResource.py


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