本文整理汇总了Python中scaffold.mock_restore函数的典型用法代码示例。如果您正苦于以下问题:Python mock_restore函数的具体用法?Python mock_restore怎么用?Python mock_restore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock_restore函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_returns_none_when_file_nonexist
def test_returns_none_when_file_nonexist(self):
""" Should return None when the PID file does not exist. """
set_pidlockfile_scenario(self, 'not-exist')
pidfile_path = self.scenario['path']
pid = pidlockfile.read_pid_from_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessIs(None, pid)
开发者ID:AlliedSecurityTrust,项目名称:python-daemon,代码行数:7,代码来源:test_pidlockfile.py
示例2: test_reads_pid_from_file
def test_reads_pid_from_file(self):
""" Should read the PID from the specified file. """
pidfile_path = self.scenario['path']
expect_pid = self.scenario['pidfile_pid']
pid = pidlockfile.read_pid_from_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessEqual(expect_pid, pid)
开发者ID:getsomeual,项目名称:pylockfile,代码行数:7,代码来源:test_pidlockfile.py
示例3: test_reads_pid_from_file
def test_reads_pid_from_file(self):
""" Should read the PID from the specified file. """
set_pidlockfile_scenario(self, "exist-other-pid")
pidfile_path = self.scenario["path"]
expect_pid = self.scenario["pidfile_pid"]
pid = pidlockfile.read_pid_from_pidfile(pidfile_path)
scaffold.mock_restore()
self.assertEqual(expect_pid, pid)
开发者ID:philtweir,项目名称:python-daemon,代码行数:8,代码来源:test_pidlockfile.py
示例4: test_writes_pid_to_file
def test_writes_pid_to_file(self):
""" Should write the current PID to the specified file. """
pidfile_path = self.scenario["path"]
self.scenario["pidfile"].close = scaffold.Mock("PIDLockFile.close", tracker=self.mock_tracker)
expect_line = "%(pid)d\n" % self.scenario
pidlockfile.write_pid_to_pidfile(pidfile_path)
scaffold.mock_restore()
self.assertEqual(expect_line, self.scenario["pidfile"].getvalue())
开发者ID:philtweir,项目名称:python-daemon,代码行数:8,代码来源:test_pidlockfile.py
示例5: test_removes_specified_filename
def test_removes_specified_filename(self):
""" Should attempt to remove specified PID file filename. """
pidfile_path = self.scenario['path']
expect_mock_output = """\
Called os.remove(%(pidfile_path)r)
""" % vars()
pidlockfile.remove_existing_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:getsomeual,项目名称:pylockfile,代码行数:9,代码来源:test_pidlockfile.py
示例6: test_opens_specified_filename
def test_opens_specified_filename(self):
""" Should attempt to open specified pidfile filename. """
pidfile_path = self.scenario['path']
expect_mock_output = """\
Called __builtin__.open(%(pidfile_path)r, 'r')
""" % vars()
dummy = pidlockfile.read_pid_from_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:getsomeual,项目名称:pylockfile,代码行数:9,代码来源:test_pidlockfile.py
示例7: tearDown
def tearDown(self):
""" Tear down test fixtures. """
scaffold.mock_restore()
""" Should return True if PID file exists. """
instance = self.test_instance
expect_result = True
self.scenario = self.scenarios['exist-currentpid']
result = instance.is_locked()
self.failUnlessEqual(expect_result, result)
开发者ID:getsomeual,项目名称:pylockfile,代码行数:10,代码来源:test_pidlockfile.py
示例8: test_removes_existing_pidfile
def test_removes_existing_pidfile(self):
""" Should request removal of specified PID file. """
instance = self.test_instance
pidfile_path = self.scenario['path']
expect_mock_output = """\
...
Called pidlockfile.remove_existing_pidfile(%(pidfile_path)r)
""" % vars()
instance.break_lock()
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:getsomeual,项目名称:pylockfile,代码行数:11,代码来源:test_pidlockfile.py
示例9: test_writes_pid_to_specified_file
def test_writes_pid_to_specified_file(self):
""" Should request writing current PID to specified file. """
instance = self.test_instance
pidfile_path = self.scenario['path']
expect_mock_output = """\
...
Called pidlockfile.write_pid_to_pidfile(%(pidfile_path)r)
""" % vars()
instance.acquire()
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:AlliedSecurityTrust,项目名称:python-daemon,代码行数:11,代码来源:test_pidlockfile.py
示例10: test_ignores_file_not_exist_error
def test_ignores_file_not_exist_error(self):
""" Should ignore error if file does not exist. """
pidfile_path = self.scenario['path']
mock_error = OSError(errno.ENOENT, "Not there", pidfile_path)
os.remove.mock_raises = mock_error
expect_mock_output = """\
Called os.remove(%(pidfile_path)r)
""" % vars()
pidlockfile.remove_existing_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:getsomeual,项目名称:pylockfile,代码行数:11,代码来源:test_pidlockfile.py
示例11: test_opens_specified_filename
def test_opens_specified_filename(self):
""" Should attempt to open specified PID file filename. """
pidfile_path = self.scenario['path']
expect_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY)
expect_mode = 0644
expect_mock_output = """\
Called os.open(%(pidfile_path)r, %(expect_flags)r, %(expect_mode)r)
...
""" % vars()
pidlockfile.write_pid_to_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:AlliedSecurityTrust,项目名称:python-daemon,代码行数:12,代码来源:test_pidlockfile.py
示例12: test_writes_pid_to_file
def test_writes_pid_to_file(self):
""" Should write the current PID to the specified file. """
pidfile_path = self.scenario['path']
pidfile = self.scenario['pidfile']
pidfile_pid = self.scenario['pidfile_pid']
pidfile.close = scaffold.Mock(
"mock_pidfile.close",
tracker=self.mock_tracker)
expect_line = "%(pidfile_pid)d\n" % vars()
pidlockfile.write_pid_to_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessEqual(expect_line, pidfile.getvalue())
开发者ID:getsomeual,项目名称:pylockfile,代码行数:12,代码来源:test_pidlockfile.py
示例13: test_sends_terminate_signal_to_process_from_pidfile
def test_sends_terminate_signal_to_process_from_pidfile(self):
""" Should send SIGTERM to the daemon process. """
instance = self.test_instance
test_pid = self.scenario['pidlockfile_scenario']['pidfile_pid']
expect_signal = signal.SIGTERM
expect_mock_output = """\
...
Called os.kill(%(test_pid)r, %(expect_signal)r)
""" % vars()
instance.do_action()
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:LukeCarrier,项目名称:py3k-daemon,代码行数:12,代码来源:test_runner.py
示例14: test_creates_lock_with_specified_parameters
def test_creates_lock_with_specified_parameters(self):
""" Should create a TimeoutPIDLockFile with specified params. """
pidfile_path = self.scenario['pidfile_path']
pidfile_timeout = self.scenario['pidfile_timeout']
lockfile_class_name = self.lockfile_class_name
expect_mock_output = """\
...
Called %(lockfile_class_name)s(
%(pidfile_path)r,
%(pidfile_timeout)r)
""" % vars()
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:LukeCarrier,项目名称:py3k-daemon,代码行数:13,代码来源:test_runner.py
示例15: test_opens_specified_filename
def test_opens_specified_filename(self):
""" Should attempt to open specified pidfile filename. """
set_pidlockfile_scenario(self, "exist-other-pid")
pidfile_path = self.scenario["path"]
expect_mock_output = (
"""\
Called builtins.open(%(pidfile_path)r, 'r')
"""
% vars()
)
dummy = pidlockfile.read_pid_from_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:philtweir,项目名称:python-daemon,代码行数:13,代码来源:test_pidlockfile.py
示例16: test_breaks_lock_if_pidfile_stale
def test_breaks_lock_if_pidfile_stale(self):
""" Should break lock if PID file is stale. """
instance = self.test_instance
pidfile_path = self.scenario['pidfile_path']
test_pid = self.scenario['pidlockfile_scenario']['pidfile_pid']
expect_signal = signal.SIG_DFL
error = OSError(errno.ESRCH, "Not running")
os.kill.mock_raises = error
lockfile_class_name = self.lockfile_class_name
expect_mock_output = """\
...
Called %(lockfile_class_name)s.break_lock()
""" % vars()
instance.do_action()
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:LukeCarrier,项目名称:py3k-daemon,代码行数:16,代码来源:test_runner.py
示例17: test_closes_file_after_write
def test_closes_file_after_write(self):
""" Should close the specified file after writing. """
pidfile_path = self.scenario["path"]
self.scenario["pidfile"].write = scaffold.Mock("PIDLockFile.write", tracker=self.mock_tracker)
self.scenario["pidfile"].close = scaffold.Mock("PIDLockFile.close", tracker=self.mock_tracker)
expect_mock_output = (
"""\
...
Called PIDLockFile.write(...)
Called PIDLockFile.close()
"""
% vars()
)
pidlockfile.write_pid_to_pidfile(pidfile_path)
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:philtweir,项目名称:python-daemon,代码行数:16,代码来源:test_pidlockfile.py
示例18: test_raises_error_if_cannot_send_signal_to_process
def test_raises_error_if_cannot_send_signal_to_process(self):
""" Should raise error if cannot send signal to daemon process. """
instance = self.test_instance
test_pid = self.scenario['pidlockfile_scenario']['pidfile_pid']
pidfile_path = self.scenario['pidfile_path']
error = OSError(errno.EPERM, "Nice try")
os.kill.mock_raises = error
expect_error = runner.DaemonRunnerStopFailureError
expect_message_content = str(test_pid)
exc = None
try:
instance.do_action()
except expect_error as exc_:
exc = exc_
else:
raise self.failureException(
"Failed to raise " + expect_error.__name__)
scaffold.mock_restore()
self.failUnlessIn(str(exc), expect_message_content)
开发者ID:jbvsmo,项目名称:python-daemon,代码行数:19,代码来源:test_runner.py
示例19: test_breaks_lock_if_no_such_process
def test_breaks_lock_if_no_such_process(self):
""" Should request breaking lock if PID file process is not running. """
set_runner_scenario(self, 'pidfile-locked')
instance = self.test_instance
self.mock_runner_lock.read_pid.mock_returns = (
self.scenario['pidlockfile_scenario']['pidfile_pid'])
pidfile_path = self.scenario['pidfile_path']
test_pid = self.scenario['pidlockfile_scenario']['pidfile_pid']
expect_signal = signal.SIG_DFL
error = OSError(errno.ESRCH, "Not running")
os.kill.mock_raises = error
lockfile_class_name = self.lockfile_class_name
expect_mock_output = """\
...
Called os.kill(%(test_pid)r, %(expect_signal)r)
Called %(lockfile_class_name)s.break_lock()
...
""" % vars()
instance.do_action()
scaffold.mock_restore()
self.failUnlessMockCheckerMatch(expect_mock_output)
开发者ID:LukeCarrier,项目名称:py3k-daemon,代码行数:21,代码来源:test_runner.py
示例20: test_raises_error_if_pidfile_not_locked
def test_raises_error_if_pidfile_not_locked(self):
""" Should raise error if PID file is not locked. """
set_runner_scenario(self, 'simple')
instance = self.test_instance
self.mock_runner_lock.is_locked.mock_returns = False
self.mock_runner_lock.i_am_locking.mock_returns = False
self.mock_runner_lock.read_pid.mock_returns = (
self.scenario['pidlockfile_scenario']['pidfile_pid'])
pidfile_path = self.scenario['pidfile_path']
expect_error = runner.DaemonRunnerStopFailureError
expect_message_content = pidfile_path
exc_text = ''
try:
instance.do_action()
except expect_error as exc:
exc_text = str(exc)
else:
raise self.failureException(
"Failed to raise " + expect_error.__name__)
scaffold.mock_restore()
self.failUnlessIn(exc_text, expect_message_content)
开发者ID:LukeCarrier,项目名称:py3k-daemon,代码行数:21,代码来源:test_runner.py
注:本文中的scaffold.mock_restore函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论