本文整理汇总了Python中tests.support.mock.patch函数的典型用法代码示例。如果您正苦于以下问题:Python patch函数的具体用法?Python patch怎么用?Python patch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了patch函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_frontend_none
def test_frontend_none(self):
c_path, c_content = self._create_conf()
new_path, new_content = self._create_rpmnew()
with self.rpmconf_plugin as rpmconf, mock.patch(
"rpmconf.rpmconf.RpmConf.flush_input", return_value="M"
), mock.patch("sys.stdout", new_callable=StringIO), mock.patch.dict("os.environ"):
if os.environ.get("MERGE"):
del os.environ["MERGE"]
try:
rpmconf.frontent = "env"
rpmconf.run()
except SystemExit as e:
if e.code in (errno.ENOENT, errno.EINTR):
self.fail("rpmconf has exited prematurely in the merge phase")
else:
self.fail("rpmconf has exited prematurely" "with unknown exit code {0}".format(safe_repr(e.code)))
self.assertTrue(os.access(c_path, os.F_OK))
with open(c_path, "rb") as f:
c_result = f.read()
self.assertEqual(c_result, c_content)
self.assertTrue(os.access(new_path, os.F_OK))
with open(new_path, "rb") as f:
new_result = f.read()
self.assertEqual(new_result, new_content)
开发者ID:pghmcfc,项目名称:dnf-plugins-extras,代码行数:29,代码来源:test_rpmconf.py
示例2: test_multi
def test_multi(self):
now = 1379406823.9
fo = MockStdout()
with mock.patch('dnf.cli.progress._term_width', return_value=60), \
mock.patch('dnf.cli.progress.time', lambda: now):
p = dnf.cli.progress.MultiFileProgressMeter(fo)
p.start(2, 30)
pload1 = FakePayload('foo', 10.0)
pload2 = FakePayload('bar', 20.0)
for i in range(11):
p.progress(pload1, float(i))
if i == 10:
p.end(pload1, None, None)
now += 0.5
p.progress(pload2, float(i*2))
self.assertEqual(self._REFERENCE_TAB[i], fo.visible_lines())
if i == 10:
p.end(pload2, dnf.callback.STATUS_FAILED, 'some error')
now += 0.5
# check "end" events
self.assertEqual(fo.visible_lines(), [
'(1/2): foo 1.0 B/s | 10 B 00:10 ',
'[FAILED] bar: some error '])
self.assertTrue(2.0 < p.rate < 4.0)
开发者ID:haghabozorgi,项目名称:dnf,代码行数:27,代码来源:test_cli_progress.py
示例3: test_print_versions
def test_print_versions(self):
base = support.MockBase()
output = support.MockOutput()
with mock.patch("sys.stdout") as stdout, mock.patch("dnf.sack.rpmdb_sack", return_value=base.sack):
dnf.cli.cli.print_versions(["pepper", "tour"], base, output)
written = "".join([mc[1][0] for mc in stdout.method_calls if mc[0] == "write"])
self.assertEqual(written, VERSIONS_OUTPUT)
开发者ID:hutarova,项目名称:dnf,代码行数:7,代码来源:test_cli.py
示例4: test_print_versions
def test_print_versions(self):
output = tests.support.MockOutput()
with mock.patch('sys.stdout') as stdout,\
mock.patch('dnf.sack._rpmdb_sack', return_value=self.base.sack):
dnf.cli.cli.print_versions(['pepper', 'tour'], self.base, output)
written = ''.join([mc[1][0] for mc in stdout.method_calls
if mc[0] == 'write'])
self.assertEqual(written, VERSIONS_OUTPUT)
开发者ID:rpm-software-management,项目名称:dnf,代码行数:8,代码来源:test_cli.py
示例5: __enter__
def __enter__(self):
self._patches = [
mock.patch("rpm.TransactionSet.dbMatch", return_value=self.packages),
mock.patch("rpm.fi", return_value=((self._conf_file, None, None, None, 1),)),
]
for patch in self._patches:
patch.__enter__()
return self
开发者ID:pghmcfc,项目名称:dnf-plugins-extras,代码行数:9,代码来源:test_rpmconf.py
示例6: test_fit_lock_dir
def test_fit_lock_dir(self):
orig = '/some'
with mock.patch('dnf.util.am_i_root', return_value=True):
self.assertEqual(dnf.lock._fit_lock_dir(orig), '/some')
with mock.patch('dnf.util.am_i_root', return_value=False):
dir_ = dnf.lock._fit_lock_dir(orig)
match = re.match(
r'/run/user/\d+/dnf/8e58d9adbd213a8b602f30604a8875f2', dir_)
self.assertTrue(match)
开发者ID:IMFTC,项目名称:dnf,代码行数:9,代码来源:test_lock.py
示例7: test_motd
def test_motd(self):
m = mock_open()
with mock.patch('dnf.automatic.emitter.open', m, create=True):
emitter = dnf.automatic.emitter.MotdEmitter('myhost')
emitter.notify_available('packages...')
emitter.notify_downloaded()
with mock.patch('dnf.automatic.emitter.DOWNLOADED', 'downloaded on %s:'):
emitter.commit()
handle = m()
handle.write.assert_called_once_with(MSG)
开发者ID:mavit,项目名称:dnf,代码行数:10,代码来源:test_emitter.py
示例8: test_clean_files_local
def test_clean_files_local(self):
"""Do not delete files from a local repo."""
base = tests.support.MockBase("main")
repo = base.repos['main']
repo.baseurl = ['file:///dnf-bad-test']
repo.basecachedir = '/tmp/dnf-bad-test'
with mock.patch('dnf.cli.commands.clean._clean_filelist'),\
mock.patch('os.path.exists', return_value=True) as exists_mock:
dnf.cli.commands.clean._clean_files(base.repos, ['rpm'], 'pkgdir',
'package')
# local repo is not even checked for directory existence:
self.assertIsNone(exists_mock.call_args)
开发者ID:IMFTC,项目名称:dnf,代码行数:12,代码来源:test_clean.py
示例9: test_non_interactive
def test_non_interactive(self):
c_path, c_content = self._create_conf()
new_path, new_content = self._create_rpmnew()
with self.rpmconf_plugin as rpmconf, mock.patch(
"rpmconf.rpmconf.RpmConf.flush_input", return_value="S"
), mock.patch("sys.stdout", new_callable=StringIO) as stdout:
rpmconf._interactive = False
rpmconf.run()
lines = stdout.getvalue().splitlines()
self.assertEqual(len(lines), 0)
开发者ID:pghmcfc,项目名称:dnf-plugins-extras,代码行数:13,代码来源:test_rpmconf.py
示例10: test_clean_binary_cache
def test_clean_binary_cache(self):
base = tests.support.MockBase('main')
with mock.patch('os.access', return_value=True) as access,\
mock.patch('dnf.cli.commands.clean._clean_filelist'):
clean._clean_binary_cache(base.repos, base.conf.cachedir)
self.assertEqual(len(access.call_args_list), 3)
fname = access.call_args_list[0][0][0]
assert fname.startswith(dnf.const.TMPDIR)
assert fname.endswith(hawkey.SYSTEM_REPO_NAME + '.solv')
fname = access.call_args_list[1][0][0]
assert fname.endswith('main.solv')
fname = access.call_args_list[2][0][0]
assert fname.endswith('main-filenames.solvx')
开发者ID:IMFTC,项目名称:dnf,代码行数:13,代码来源:test_clean.py
示例11: test_pkg_option
def test_pkg_option(self):
args = ["--pkg", "foo"]
self.cmd.base.add_remote_rpms([os.path.join(self.path, "noarch/foo-4-6.noarch.rpm")])
with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
support.command_run(self.cmd, args)
expected_out = ["package: foo-4-6.noarch from @commandline",
" unresolved deps:",
" bar = 4-6"]
self.assertEqual(stdout.getvalue()[:-1], "\n".join(expected_out))
args = ["--pkg", "bar"]
with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
support.command_run(self.cmd, args)
self.assertEmpty(stdout.getvalue())
开发者ID:jsilhan,项目名称:dnf-plugins-core,代码行数:13,代码来源:test_repoclosure.py
示例12: test_check_option
def test_check_option(self):
args = ["--check", "@commandline"]
self.cmd.base.repos.add(support.RepoStub("main"))
self.cmd.base.add_remote_rpm(os.path.join(self.path, "noarch/foo-4-6.noarch.rpm"))
self.cmd.configure(args)
with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
self.cmd.run(args)
expected_out = ["package: foo-4-6.noarch from @commandline", " unresolved deps:", " bar = 4-6"]
self.assertEqual(stdout.getvalue()[:-1], "\n".join(expected_out))
args = ["--check", "main"]
self.cmd.configure(args)
with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
self.cmd.run(args)
self.assertEmpty(stdout.getvalue())
开发者ID:qtonthat,项目名称:dnf-plugins-extras,代码行数:14,代码来源:test_repoclosure.py
示例13: test_mirror
def test_mirror(self):
fo = MockStdout()
p = dnf.cli.progress.MultiFileProgressMeter(fo, update_period=-1)
p.start(1, 5)
pload = FakePayload('foo', 5.0)
now = 1379406823.9
with mock.patch('dnf.cli.progress._term_width', return_value=60), \
mock.patch('dnf.cli.progress.time', lambda: now):
p.progress(pload, 3)
p.end(pload, dnf.callback.STATUS_MIRROR, 'Timeout.')
p.progress(pload, 4)
self.assertEqual(fo.visible_lines(), [
'[MIRROR] foo: Timeout. ',
'foo 80% [======== ] --- B/s | 4 B --:-- ETA'])
开发者ID:haghabozorgi,项目名称:dnf,代码行数:15,代码来源:test_cli_progress.py
示例14: setUp
def setUp(self):
"""Prepare the test fixture."""
super(UpdateInfoCommandTest, self).setUp()
cachedir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, cachedir)
self.cli.base.conf.cachedir = cachedir
self.cli.base.add_test_dir_repo('rpm', self.cli.base.conf)
self._stdout = dnf.pycomp.StringIO()
self.addCleanup(mock.patch.stopall)
mock.patch(
'dnf.cli.commands.updateinfo._',
dnf.pycomp.NullTranslations().ugettext).start()
mock.patch(
'dnf.cli.commands.updateinfo.print',
self._stub_print, create=True).start()
开发者ID:mavit,项目名称:dnf,代码行数:15,代码来源:test_updateinfo.py
示例15: test_diff_output
def test_diff_output(self):
self._create_conf()
self._create_rpmnew()
self._create_rpmsave()
with self.rpmconf_plugin as rpmconf, mock.patch("sys.stdout", new_callable=StringIO) as stdout:
rpmconf.diff = True
rpmconf.run()
lines = stdout.getvalue().splitlines()
expected_lines = [
"--- {0}".format(*self.conf_file),
"+++ {0}".format(*self.conf_file_rpmnew),
"@@ -1,3 +1,2 @@",
" package = good",
" true = false",
'-what = "tahw"',
"--- {0}".format(*self.conf_file_rpmsave),
"+++ {0}".format(*self.conf_file),
"@@ -1,2 +1,3 @@",
"-package = bad",
"-true = true",
"+package = good",
"+true = false",
'+what = "tahw"',
]
msg_tmpl = "{0} does not start with {1}"
for line, expected_line in zip_longest(lines, expected_lines, fillvalue=""):
if not line.startswith(expected_line):
self.fail(msg_tmpl.format(safe_repr(line), safe_repr(expected_line)))
开发者ID:pghmcfc,项目名称:dnf-plugins-extras,代码行数:32,代码来源:test_rpmconf.py
示例16: setUp
def setUp(self):
"""Prepare the test fixture."""
super(RepoPkgsReinstallSubCommandTest, self).setUp()
self.mock = mock.Mock()
old_run_patcher = mock.patch(
'dnf.cli.commands.RepoPkgsCommand.ReinstallOldSubCommand.run_on_repo',
self.mock.reinstall_old_run)
move_run_patcher = mock.patch(
'dnf.cli.commands.RepoPkgsCommand.MoveToSubCommand.run_on_repo',
self.mock.move_to_run)
old_run_patcher.start()
self.addCleanup(old_run_patcher.stop)
move_run_patcher.start()
self.addCleanup(move_run_patcher.stop)
开发者ID:mavit,项目名称:dnf,代码行数:16,代码来源:test_commands.py
示例17: test_macro
def test_macro(self):
with mock.patch('builddep.BuildDepCommand.base', MockBase()) as base:
self.cmd.configure(('--define', 'enable_optional_module 1', SPEC,))
self.cmd.run(('--define', 'enable_optional_module 1', SPEC,))
self.assertEqual(base.marked,
['emacs-extras', 'emacs-goodies >= 100',
'emacs-module'])
开发者ID:evilkost,项目名称:dnf-plugins-core,代码行数:7,代码来源:test_builddep.py
示例18: test_header
def test_header(self):
args = []
self.cmd.configure(args)
with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
self.cmd.run(args)
expected_graph = ["digraph packages {", repograph.DOT_HEADER, "}\n"]
self.assertEqual(stdout.getvalue(), "\n".join(expected_graph))
开发者ID:beermix,项目名称:dnf-plugins-extras,代码行数:7,代码来源:test_repograph.py
示例19: test_configure_badargs
def test_configure_badargs(self):
"""Test whether the command fail in case of wrong args."""
with self.assertRaises(SystemExit) as exit, \
support.patch_std_streams() as (stdout, stderr), \
mock.patch('logging.Logger.critical') as clog:
support.command_configure(self.cmd, [])
self.assertEqual(exit.exception.code, 1)
开发者ID:Conan-Kudo,项目名称:dnf,代码行数:7,代码来源:test_commands.py
示例20: test_configure_verbose
def test_configure_verbose(self):
with mock.patch('dnf.rpm.detect_releasever', return_value=69):
self.cli.configure(['-v', 'update', '-c', self.conffile])
self.assertEqual(self.cli.cmdstring, "dnf -v update -c %s " %
self.conffile)
self.assertEqual(self.base.conf.debuglevel, 6)
self.assertEqual(self.base.conf.errorlevel, 6)
开发者ID:hanzz,项目名称:dnf,代码行数:7,代码来源:test_cli.py
注:本文中的tests.support.mock.patch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论