本文整理汇总了Python中scaffold.mock_restore函数的典型用法代码示例。如果您正苦于以下问题:Python mock_restore函数的具体用法?Python mock_restore怎么用?Python mock_restore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock_restore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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())
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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())
示例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)
示例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)
示例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)