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


Python MagicMock.assert_called_once_with方法代码示例

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


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

示例1: test_package_removed_failure

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_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

示例2: test_tar

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_tar(self):
        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.tar(
                'zcvf', 'foo.tar',
                ['/tmp/something-to-compress-1',
                 '/tmp/something-to-compress-2'],
                cwd=None, template=None
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                'tar -zcvf foo.tar /tmp/something-to-compress-1 '
                '/tmp/something-to-compress-2',
                cwd=None,
                template=None
            )

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.tar(
                'zcvf', 'foo.tar',
                '/tmp/something-to-compress-1,/tmp/something-to-compress-2',
                cwd=None, template=None
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                'tar -zcvf foo.tar /tmp/something-to-compress-1 '
                '/tmp/something-to-compress-2',
                cwd=None,
                template=None
            )
开发者ID:penta-srl,项目名称:salt,代码行数:33,代码来源:archive_test.py

示例3: test_issue_6030_deprecated_never_download

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_issue_6030_deprecated_never_download(self):
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})

        with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
            virtualenv_mod.create(
                '/tmp/foo', never_download=True
            )
            mock.assert_called_once_with(
                'virtualenv --never-download /tmp/foo',
                runas=None
            )

        with TestsLoggingHandler() as handler:
            mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
            # Let's fake a higher virtualenv version
            virtualenv_mock = MagicMock()
            virtualenv_mock.__version__ = '1.10rc1'
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                with patch.dict('sys.modules',
                                {'virtualenv': virtualenv_mock}):
                    virtualenv_mod.create(
                        '/tmp/foo', never_download=True
                    )
                    mock.assert_called_once_with('virtualenv /tmp/foo',
                                                 runas=None)

                # Are we logging the deprecation information?
                self.assertIn(
                    'INFO:The virtualenv \'--never-download\' option has been '
                    'deprecated in virtualenv(>=1.10), as such, the '
                    '\'never_download\' option to `virtualenv.create()` has '
                    'also been deprecated and it\'s not necessary anymore.',
                    handler.messages
                )
开发者ID:penta-srl,项目名称:salt,代码行数:36,代码来源:virtualenv_test.py

示例4: test_freeze_command

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_freeze_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(
            return_value={
                'retcode': 0,
                'stdout': '\n'.join(eggs)
            }
        )
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            ret = pip.freeze()
            mock.assert_called_once_with(
                'pip freeze',
                runas=None,
                cwd=None,
                python_shell=False,
            )
            self.assertEqual(ret, eggs)

        # 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.freeze,
            )
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:33,代码来源:pip_test.py

示例5: test_rar

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_rar(self):
        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.rar(
                '/tmp/rarfile.rar',
                '/tmp/sourcefile1,/tmp/sourcefile2'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                'rar a -idp /tmp/rarfile.rar '
                '/tmp/sourcefile1 /tmp/sourcefile2',
                template=None
            )

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.rar(
                '/tmp/rarfile.rar',
                ['/tmp/sourcefile1', '/tmp/sourcefile2']
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                'rar a -idp /tmp/rarfile.rar '
                '/tmp/sourcefile1 /tmp/sourcefile2',
                template=None
            )
开发者ID:penta-srl,项目名称:salt,代码行数:28,代码来源:archive_test.py

示例6: run_contents_pillar

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def run_contents_pillar(self, pillar_value, expected):
        returner = MagicMock(return_value=None)

        filestate.__salt__ = {"file.manage_file": returner}

        path = "/tmp/foo"
        pillar_path = "foo:bar"

        # the values don't matter here
        filestate.__salt__["config.manage_mode"] = MagicMock()
        filestate.__salt__["file.source_list"] = MagicMock(return_value=[None, None])
        filestate.__salt__["file.get_managed"] = MagicMock(return_value=[None, None, None])

        # pillar.get should return the pillar_value
        pillar_mock = MagicMock(return_value=pillar_value)
        filestate.__salt__["pillar.get"] = pillar_mock

        ret = filestate.managed(path, contents_pillar=pillar_path)

        # make sure the pillar_mock is called with the given path
        pillar_mock.assert_called_once_with(pillar_path)

        # make sure no errors are returned
        self.assertEqual(None, ret)

        # make sure the value is correct
        self.assertEqual(expected, returner.call_args[0][-2])
开发者ID:bemehow,项目名称:salt,代码行数:29,代码来源:file_test.py

示例7: test_install_multiple_editable

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_install_multiple_editable(self):
        editables = [
            'git+https://github.com/jek/blinker.git#egg=Blinker',
            'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
        ]

        # Passing editables as a list
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.install(editable=editables)
            mock.assert_called_once_with(
                'pip install '
                '--editable=git+https://github.com/jek/blinker.git#egg=Blinker '
                '--editable=git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting',
                saltenv='base',
                runas=None,
                cwd=None,
                python_shell=False,
            )

        # Passing editables as a comma separated list
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.install(editable=','.join(editables))
            mock.assert_called_once_with(
                'pip install '
                '--editable=git+https://github.com/jek/blinker.git#egg=Blinker '
                '--editable=git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting',
                saltenv='base',
                runas=None,
                cwd=None,
                python_shell=False,
            )
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:35,代码来源:pip_test.py

示例8: test_installed_pkg_version_succeeds

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_installed_pkg_version_succeeds(self, _mod_run_check_mock):
        '''
            Test installing a PKG file where the version number matches the current installed version
        '''
        expected = {
            'changes': {},
            'comment': 'Version already matches .*5\\.1\\.[0-9]',
            'name': '/path/to/file.pkg',
            'result': True
        }

        installed_mock = MagicMock(return_value=['com.apple.id', 'some.other.id'])
        get_pkg_id_mock = MagicMock(return_value=['some.other.id'])
        install_mock = MagicMock(return_value={'retcode': 0})
        cmd_mock = MagicMock(return_value='Version of this: 5.1.9')
        _mod_run_check_mock.return_value = True

        with patch.dict(macpackage.__salt__, {'macpackage.installed_pkgs': installed_mock,
                                              'macpackage.get_pkg_id': get_pkg_id_mock,
                                              'macpackage.install': install_mock,
                                              'cmd.run': cmd_mock}):
            out = macpackage.installed('/path/to/file.pkg', version_check=r'/usr/bin/runme --version=.*5\.1\.[0-9]')
            cmd_mock.assert_called_once_with('/usr/bin/runme --version', output_loglevel="quiet", ignore_retcode=True)
            assert not installed_mock.called
            assert not get_pkg_id_mock.called
            assert not install_mock.called
            self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:29,代码来源:mac_package_test.py

示例9: test_rar

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_rar(self):
        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.rar(
                '/tmp/rarfile.rar',
                '/tmp/sourcefile1,/tmp/sourcefile2'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['rar', 'a', '-idp', '/tmp/rarfile.rar',
                 '/tmp/sourcefile1', '/tmp/sourcefile2'],
                runas=None, python_shell=False, template=None, cwd=None
            )

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.rar(
                '/tmp/rarfile.rar',
                ['/tmp/sourcefile1', '/tmp/sourcefile2']
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['rar', 'a', '-idp', '/tmp/rarfile.rar',
                 '/tmp/sourcefile1', '/tmp/sourcefile2'],
                runas=None, python_shell=False, template=None, cwd=None
            )
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:archive_test.py

示例10: test_installed_activated

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_installed_activated(self):
        '''
            Test activating the given product key when its already activated
        '''
        expected = {
            'changes': {},
            'comment': 'Windows is already activated.',
            'name': 'AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE',
            'result': True
        }

        info = {
            'description': 'Prof',
            'licensed': True,
            'name': 'Win7',
            'partial_key': 'ABCDE'
        }

        info_mock = MagicMock(return_value=info)
        install_mock = MagicMock(return_value='Installed successfully')
        activate_mock = MagicMock(return_value='Activated successfully')
        with patch.dict(license.__salt__, {'license.info': info_mock,
                                           'license.install': install_mock,
                                           'license.activate': activate_mock}):
            out = license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE')
            info_mock.assert_called_once_with()
            assert not install_mock.called
            assert not activate_mock.called
            self.assertEqual(out, expected)
开发者ID:HowardMei,项目名称:saltstack,代码行数:31,代码来源:win_license_test.py

示例11: test_installed_dmg

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_installed_dmg(self, _mod_run_check_mock):
        '''
            Test installing a DMG file
        '''
        expected = {
            'changes': {'installed': ['some.other.id']},
            'comment': '/path/to/file.dmg installed',
            'name': '/path/to/file.dmg',
            'result': True
        }

        mount_mock = MagicMock(return_value=['success', '/tmp/dmg-X'])
        unmount_mock = MagicMock()
        installed_mock = MagicMock(return_value=['com.apple.id'])
        get_pkg_id_mock = MagicMock(return_value=['some.other.id'])
        install_mock = MagicMock(return_value={'retcode': 0})
        _mod_run_check_mock.return_value = True

        with patch.dict(macpackage.__salt__, {'macpackage.mount': mount_mock,
                                              'macpackage.unmount': unmount_mock,
                                              'macpackage.installed_pkgs': installed_mock,
                                              'macpackage.get_pkg_id': get_pkg_id_mock,
                                              'macpackage.install': install_mock}):
            out = macpackage.installed('/path/to/file.dmg', dmg=True)
            mount_mock.assert_called_once_with('/path/to/file.dmg')
            unmount_mock.assert_called_once_with('/tmp/dmg-X')
            installed_mock.assert_called_once_with()
            get_pkg_id_mock.assert_called_once_with('/tmp/dmg-X/*.pkg')
            install_mock.assert_called_once_with('/tmp/dmg-X/*.pkg', 'LocalSystem', False, False)
            self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:32,代码来源:mac_package_test.py

示例12: test_installed_activate_fail

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_installed_activate_fail(self):
        '''
            Test activating the given product key when the install fails
        '''
        expected = {
            'changes': {},
            'comment': 'Unable to activate the given product key.',
            'name': 'AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE',
            'result': False
        }

        info = {
            'description': 'Prof',
            'licensed': False,
            'name': 'Win7',
            'partial_key': 'ABCDE'
        }

        info_mock = MagicMock(return_value=info)
        install_mock = MagicMock()
        activate_mock = MagicMock(return_value='Failed to activate')
        with patch.dict(license.__salt__, {'license.info': info_mock,
                                           'license.install': install_mock,
                                           'license.activate': activate_mock}):
            out = license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE')
            info_mock.assert_called_once_with()
            assert not install_mock.called
            activate_mock.assert_called_once_with()
            self.assertEqual(out, expected)
开发者ID:HowardMei,项目名称:saltstack,代码行数:31,代码来源:win_license_test.py

示例13: test_capability_installed_failure

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_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

示例14: test_package_removed_removed

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_package_removed_removed(self):
        '''
            Test removing a package already removed
        '''
        expected = {
            'comment': "The package Pack2 is already removed",
            'changes': {},
            'name': 'Pack2',
            'result': True}

        mock_removed = MagicMock(
            side_effect=[['Pack1'], ['Pack1']])
        mock_remove = MagicMock()
        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}):

            out = dism.package_removed('Pack2')

            mock_removed.assert_called_once_with()
            assert not mock_remove.called
            self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:win_dism_test.py

示例15: test_installed

# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import assert_called_once_with [as 别名]
    def test_installed(self):
        gems = {'foo': ['1.0'], 'bar': ['2.0']}
        gem_list = MagicMock(return_value=gems)
        gem_install_succeeds = MagicMock(return_value=True)
        gem_install_fails = MagicMock(return_value=False)

        with patch.dict(gem.__salt__, {'gem.list': gem_list}):
            with patch.dict(gem.__salt__,
                            {'gem.install': gem_install_succeeds}):
                ret = gem.installed('foo')
                self.assertEqual(True, ret['result'])
                ret = gem.installed('quux')
                self.assertEqual(True, ret['result'])
                gem_install_succeeds.assert_called_once_with(
                    'quux', pre_releases=False, ruby=None, runas=None,
                    version=None, proxy=None, rdoc=False, source=None,
                    ri=False, gem_bin=None
                )

            with patch.dict(gem.__salt__,
                            {'gem.install': gem_install_fails}):
                ret = gem.installed('quux')
                self.assertEqual(False, ret['result'])
                gem_install_fails.assert_called_once_with(
                    'quux', pre_releases=False, ruby=None, runas=None,
                    version=None, proxy=None, rdoc=False, source=None,
                    ri=False, gem_bin=None
                )
开发者ID:DaveQB,项目名称:salt,代码行数:30,代码来源:gem_test.py


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