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


Python MagicMock.assert_called_with方法代码示例

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


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

示例1: test_list_command

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_list_command(self):
        eggs = [
            "M2Crypto==0.21.1",
            "-e [email protected]:s0undt3ch/[email protected]#egg=SaltTesting-dev",
            "bbfreeze==1.1.0",
            "bbfreeze-loader==1.1.0",
            "pycrypto==2.6",
        ]
        mock = MagicMock(
            side_effect=[{"retcode": 0, "stdout": "pip MOCKED_VERSION"}, {"retcode": 0, "stdout": "\n".join(eggs)}]
        )
        with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
            ret = pip.list_()
            mock.assert_called_with("pip freeze", runas=None, cwd=None)
            self.assertEqual(
                ret,
                {
                    "SaltTesting-dev": "[email protected]:s0undt3ch/[email protected]",
                    "M2Crypto": "0.21.1",
                    "bbfreeze-loader": "1.1.0",
                    "bbfreeze": "1.1.0",
                    "pip": "MOCKED_VERSION",
                    "pycrypto": "2.6",
                },
            )

        # Non zero returncode raises exception?
        mock = MagicMock(return_value={"retcode": 1, "stderr": "CABOOOOMMM!"})
        with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
            self.assertRaises(CommandExecutionError, pip.list_)
开发者ID:AccelerationNet,项目名称:salt,代码行数:32,代码来源:pip_test.py

示例2: test_list_command_with_prefix

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
 def test_list_command_with_prefix(self):
     eggs = [
         'M2Crypto==0.21.1',
         '-e [email protected]:s0undt3ch/[email protected]#egg=SaltTesting-dev',
         'bbfreeze==1.1.0',
         'bbfreeze-loader==1.1.0',
         'pycrypto==2.6'
     ]
     mock = MagicMock(
         return_value={
             'retcode': 0,
             'stdout': '\n'.join(eggs)
         }
     )
     with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
         ret = pip.list_(prefix='bb')
         mock.assert_called_with(
             'pip freeze',
             runas=None,
             cwd=None,
             python_shell=False,
         )
         self.assertEqual(
             ret, {
                 'bbfreeze-loader': '1.1.0',
                 'bbfreeze': '1.1.0',
             }
         )
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:30,代码来源:pip_test.py

示例3: test_package_removed_failure

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_package_removed_failure(self):
        '''
            Test removing a package which fails with DISM
        '''
        expected = {
            'comment': "Failed to remove Pack2: Failed",
            'changes': {},
            'name': 'Pack2',
            'result': False}

        mock_removed = MagicMock(
            side_effect=[['Pack1', 'Pack2'], ['Pack1', 'Pack2']])
        mock_remove = MagicMock(
            return_value={'retcode': 67, 'stdout': 'Failed'})
        mock_info = MagicMock(
            return_value={'Package Identity': 'Pack2'})

        with patch.dict(
            dism.__salt__, {'dism.installed_packages': mock_removed,
                            'dism.remove_package': mock_remove,
                            'dism.package_info': mock_info}):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.package_removed('Pack2')

                mock_removed.assert_called_with()
                mock_remove.assert_called_once_with(
                    'Pack2', None, False)
                self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:31,代码来源:win_dism_test.py

示例4: test_capability_installed_failure

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_capability_installed_failure(self):
        '''
            Test installing a capability which fails with DISM
        '''
        expected = {
            'comment': "Failed to install Capa2: Failed",
            'changes': {},
            'name': 'Capa2',
            'result': False}

        mock_installed = MagicMock(
            side_effect=[['Capa1'], ['Capa1']])
        mock_add = MagicMock(
            return_value={'retcode': 67, 'stdout': 'Failed'})

        with patch.dict(
            dism.__salt__, {'dism.installed_capabilities': mock_installed,
                            'dism.add_capability': mock_add}):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.capability_installed('Capa2', 'somewhere', True)

                mock_installed.assert_called_with()
                mock_add.assert_called_once_with(
                    'Capa2', 'somewhere', True, None, False)
                self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:win_dism_test.py

示例5: test_feature_removed_failure

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_feature_removed_failure(self):
        '''
            Test removing a feature which fails with DISM
        '''
        expected = {
            'comment': "Failed to remove Feat2: Failed",
            'changes': {},
            'name': 'Feat2',
            'result': False}

        mock_removed = MagicMock(
            side_effect=[['Feat1', 'Feat2'], ['Feat1', 'Feat2']])
        mock_remove = MagicMock(
            return_value={'retcode': 67, 'stdout': 'Failed'})

        with patch.dict(
            dism.__salt__, {'dism.installed_features': mock_removed,
                            'dism.remove_feature': mock_remove}):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.feature_removed('Feat2')

                mock_removed.assert_called_with()
                mock_remove.assert_called_once_with(
                    'Feat2', False, None, False)
                self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:win_dism_test.py

示例6: test_package_installed

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_package_installed(self):
        '''
            Test installing a package with DISM
        '''
        expected = {
            'comment': "Installed Pack2",
            'changes': {'package': {'new': 'Pack2'},
                        'retcode': 0},
            'name': 'Pack2',
            'result': True}

        mock_installed = MagicMock(
            side_effect=[['Pack1'], ['Pack1', 'Pack2']])
        mock_add = MagicMock(
            return_value={'retcode': 0})
        mock_info = MagicMock(
            return_value={'Package Identity': 'Pack2'})

        with patch.dict(
            dism.__salt__, {'dism.installed_packages': mock_installed,
                            'dism.add_package': mock_add,
                            'dism.package_info': mock_info}):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.package_installed('Pack2')

                mock_installed.assert_called_with()
                mock_add.assert_called_once_with(
                    'Pack2', False, False, None, False)
                self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:32,代码来源:win_dism_test.py

示例7: test_feature_installed

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_feature_installed(self):
        '''
            Test installing a feature with DISM
        '''
        expected = {
            'comment': "Installed Feat2",
            'changes': {'feature': {'new': 'Feat2'},
                        'retcode': 0},
            'name': 'Feat2',
            'result': True}

        mock_installed = MagicMock(
            side_effect=[['Feat1'], ['Feat1', 'Feat2']])
        mock_add = MagicMock(
            return_value={'retcode': 0})

        with patch.dict(
            dism.__salt__, {'dism.installed_features': mock_installed,
                            'dism.add_feature': mock_add}):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.feature_installed('Feat2')

                mock_installed.assert_called_with()
                mock_add.assert_called_once_with(
                    'Feat2', None, None, False, False, None, False)
                self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:29,代码来源:win_dism_test.py

示例8: test_capability_installed

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_capability_installed(self):
        '''
            Test capability installed state
        '''
        expected = {
            'comment': "Installed Capa2",
            'changes': {'capability': {'new': 'Capa2'},
                        'retcode': 0},
            'name': 'Capa2',
            'result': True}

        mock_installed = MagicMock(
            side_effect=[['Capa1'], ['Capa1', 'Capa2']])
        mock_add = MagicMock(
            return_value={'retcode': 0})

        with patch.dict(
            dism.__salt__, {'dism.installed_capabilities': mock_installed,
                            'dism.add_capability': mock_add}):
            with patch.dict(dism.__opts__, {'test': False}):

                out = dism.capability_installed('Capa2', 'somewhere', True)

                mock_installed.assert_called_with()
                mock_add.assert_called_once_with(
                    'Capa2', 'somewhere', True, None, False)
                self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:29,代码来源:win_dism_test.py

示例9: test_get_virtualenv_version_from_shell

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_get_virtualenv_version_from_shell(self):
        with ForceImportErrorOn("virtualenv"):

            # ----- virtualenv binary not available ------------------------->
            mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                self.assertRaises(CommandExecutionError, virtualenv_mod.create, "/tmp/foo")
            # <---- virtualenv binary not available --------------------------

            # ----- virtualenv binary present but > 0 exit code ------------->
            mock = MagicMock(
                side_effect=[{"retcode": 1, "stdout": "", "stderr": "This is an error"}, {"retcode": 0, "stdout": ""}]
            )
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                self.assertRaises(CommandExecutionError, virtualenv_mod.create, "/tmp/foo", venv_bin="virtualenv")
            # <---- virtualenv binary present but > 0 exit code --------------

            # ----- virtualenv binary returns 1.9.1 as its version --------->
            mock = MagicMock(side_effect=[{"retcode": 0, "stdout": "1.9.1"}, {"retcode": 0, "stdout": ""}])
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                virtualenv_mod.create("/tmp/foo", never_download=True)
                mock.assert_called_with(["virtualenv", "--never-download", "/tmp/foo"], runas=None, python_shell=False)
            # <---- virtualenv binary returns 1.9.1 as its version ----------

            # ----- virtualenv binary returns 1.10rc1 as its version ------->
            mock = MagicMock(side_effect=[{"retcode": 0, "stdout": "1.10rc1"}, {"retcode": 0, "stdout": ""}])
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                virtualenv_mod.create("/tmp/foo", never_download=True)
                mock.assert_called_with(["virtualenv", "/tmp/foo"], runas=None, python_shell=False)
开发者ID:bryson,项目名称:salt,代码行数:31,代码来源:virtualenv_test.py

示例10: test_install_pre_argument_in_resulting_command

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_install_pre_argument_in_resulting_command(self):
        # Lower than 1.4 versions don't end-up with `--pre` in the resulting
        # output
        mock = MagicMock(side_effect=[
            {'retcode': 0, 'stdout': 'pip 1.2.0 /path/to/site-packages/pip'},
            {'retcode': 0, 'stdout': ''}
        ])
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.install(
                'pep8', pre_releases=True
            )
            mock.assert_called_with(
                'pip install \'pep8\'',
                saltenv='base',
                runas=None,
                cwd=None,
                python_shell=False,
            )

        mock = MagicMock(side_effect=[
            {'retcode': 0, 'stdout': 'pip 1.4.0 /path/to/site-packages/pip'},
            {'retcode': 0, 'stdout': ''}
        ])
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.install(
                'pep8', pre_releases=True
            )
            mock.assert_called_with(
                'pip install --pre \'pep8\'',
                saltenv='base',
                runas=None,
                cwd=None,
                python_shell=False,
            )
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:36,代码来源:pip_test.py

示例11: test_get_saved_rules

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
 def test_get_saved_rules(self):
     '''
     Test if it return a data structure of the rules in the conf file
     '''
     mock = MagicMock(return_value=False)
     with patch.object(iptables, '_parse_conf', mock):
         self.assertFalse(iptables.get_saved_rules())
         mock.assert_called_with(conf_file=None, family='ipv4')
开发者ID:bryson,项目名称:salt,代码行数:10,代码来源:iptables_test.py

示例12: test_get_rules

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
 def test_get_rules(self):
     '''
     Test if it return a data structure of the current, in-memory rules
     '''
     mock = MagicMock(return_value=False)
     with patch.object(iptables, '_parse_conf', mock):
         self.assertFalse(iptables.get_rules())
         mock.assert_called_with(in_mem=True, family='ipv4')
开发者ID:bryson,项目名称:salt,代码行数:10,代码来源:iptables_test.py

示例13: test_get_virtualenv_version_from_shell

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_get_virtualenv_version_from_shell(self):
        with ForceImportErrorOn('virtualenv'):

            # ----- virtualenv binary not available ------------------------->
            mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                self.assertRaises(
                    CommandExecutionError,
                    virtualenv_mod.create,
                    '/tmp/foo',
                )
            # <---- virtualenv binary not available --------------------------

            # ----- virtualenv binary present but > 0 exit code ------------->
            mock = MagicMock(side_effect=[
                {'retcode': 1, 'stdout': '', 'stderr': 'This is an error'},
                {'retcode': 0, 'stdout': ''}
            ])
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                self.assertRaises(
                    CommandExecutionError,
                    virtualenv_mod.create,
                    '/tmp/foo',
                    venv_bin='virtualenv',
                )
            # <---- virtualenv binary present but > 0 exit code --------------

            # ----- virtualenv binary returns 1.9.1 as its version --------->
            mock = MagicMock(side_effect=[
                {'retcode': 0, 'stdout': '1.9.1'},
                {'retcode': 0, 'stdout': ''}
            ])
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                virtualenv_mod.create(
                    '/tmp/foo', never_download=True
                )
                mock.assert_called_with(
                    ['virtualenv', '--never-download', '/tmp/foo'],
                    runas=None,
                    python_shell=False
                )
            # <---- virtualenv binary returns 1.9.1 as its version ----------

            # ----- virtualenv binary returns 1.10rc1 as its version ------->
            mock = MagicMock(side_effect=[
                {'retcode': 0, 'stdout': '1.10rc1'},
                {'retcode': 0, 'stdout': ''}
            ])
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                virtualenv_mod.create(
                    '/tmp/foo', never_download=True
                )
                mock.assert_called_with(
                    ['virtualenv', '/tmp/foo'],
                    runas=None,
                    python_shell=False
                )
开发者ID:shineforever,项目名称:ops,代码行数:59,代码来源:virtualenv_test.py

示例14: test_extracted_tar

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_extracted_tar(self):
        '''
        archive.extracted tar options
        '''

        source = '/tmp/file.tar.gz'
        tmp_dir = os.path.join(tempfile.gettempdir(), 'test_archive', '')
        test_tar_opts = [
            '--no-anchored foo',
            'v -p --opt',
            '-v -p',
            '--long-opt -z',
            'z -v -weird-long-opt arg',
        ]
        ret_tar_opts = [
            ['tar', 'x', '--no-anchored', 'foo', '-f'],
            ['tar', 'xv', '-p', '--opt', '-f'],
            ['tar', 'x', '-v', '-p', '-f'],
            ['tar', 'x', '--long-opt', '-z', '-f'],
            ['tar', 'xz', '-v', '-weird-long-opt', 'arg', '-f'],
        ]

        mock_true = MagicMock(return_value=True)
        mock_false = MagicMock(return_value=False)
        ret = {'stdout': ['saltines', 'cheese'], 'stderr': 'biscuits', 'retcode': '31337', 'pid': '1337'}
        mock_run = MagicMock(return_value=ret)
        mock_source_list = MagicMock(return_value=(source, None))
        state_single_mock = MagicMock(return_value={'local': {'result': True}})
        list_mock = MagicMock(return_value={
            'dirs': [],
            'files': ['saltines', 'cheese'],
            'top_level_dirs': [],
            'top_level_files': ['saltines', 'cheese'],
        })

        with patch.dict(archive.__opts__, {'test': False,
                                           'cachedir': tmp_dir}):
            with patch.dict(archive.__salt__, {'file.directory_exists': mock_false,
                                               'file.file_exists': mock_false,
                                               'state.single': state_single_mock,
                                               'file.makedirs': mock_true,
                                               'cmd.run_all': mock_run,
                                               'archive.list': list_mock,
                                               'file.source_list': mock_source_list}):
                filename = os.path.join(
                    tmp_dir,
                    'files/test/_tmp_file.tar.gz'
                )
                for test_opts, ret_opts in zip(test_tar_opts, ret_tar_opts):
                    ret = archive.extracted(tmp_dir,
                                            source,
                                            options=test_opts,
                                            enforce_toplevel=False)
                    ret_opts.append(filename)
                    mock_run.assert_called_with(ret_opts, cwd=tmp_dir, python_shell=False)
开发者ID:bryson,项目名称:salt,代码行数:57,代码来源:archive_test.py

示例15: test_list_installed_command

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_with [as 别名]
    def test_list_installed_command(self):
        # Given
        r_output = "com.apple.pkg.iTunes"

        # When
        mock_cmd = MagicMock(return_value=r_output)
        with patch.dict(darwin_pkgutil.__salt__, {'cmd.run_stdout': mock_cmd}):
            output = darwin_pkgutil.list_()

        # Then
        mock_cmd.assert_called_with("/usr/sbin/pkgutil --pkgs")
开发者ID:DaveQB,项目名称:salt,代码行数:13,代码来源:darwin_pkgutil_test.py


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