本文整理汇总了Python中mocker.Mocker.mock方法的典型用法代码示例。如果您正苦于以下问题:Python Mocker.mock方法的具体用法?Python Mocker.mock怎么用?Python Mocker.mock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mocker.Mocker
的用法示例。
在下文中一共展示了Mocker.mock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_match_matched
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_find_match_matched(self):
key = "chr1:154000-230000"
mocker = Mocker()
junction = mocker.mock()
junction.coverage
mocker.result(40)
mocker.count(1, None)
container = mocker.mock()
container.keys()
mocker.result([key])
container[key]
mocker.result(junction)
mocker.count(1, None)
mocker.replay()
self.common, self.diff = jc.findMatch(container, container)
self.assertEqual(self.common.keys(), ["chr1:154000-230000"])
self.assertEqual(self.diff.keys(), [])
mocker.restore()
mocker.verify()
示例2: test_move
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_move(self):
"""Move."""
mocker = Mocker()
# node, with a generation attribute
node = mocker.mock()
expect(node.generation).result(123)
expect(node.mimetype).result("mime")
# user, with the chained calls to the operation
user = mocker.mock()
new_parent_id = uuid.uuid4()
expect(user.volume("vol_id").node("node_id").move(new_parent_id, "new_name")).result(node)
self.dal._get_user = lambda *a: user
with mocker:
kwargs = dict(
user_id="user_id",
volume_id="vol_id",
node_id="node_id",
new_parent_id=new_parent_id,
new_name="new_name",
session_id="session_id",
)
result = self.dal.move(**kwargs)
self.assertEqual(result, dict(generation=123, mimetype="mime"))
示例3: test_list_volumes_root_and_quota
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_list_volumes_root_and_quota(self):
"""List volumes, check root and quota."""
mocker = Mocker()
# root
root = mocker.mock()
expect(root.generation).result(123)
expect(root.root_id).result("root_id")
# quota
quota = mocker.mock()
expect(quota.free_bytes).result(4567890)
# user
user = mocker.mock()
self.dal._get_user = lambda *a: user
expect(user.volume().get_volume()).result(root)
expect(user.get_shared_to(accepted=True)).result([])
expect(user.get_udfs()).result([])
expect(user.get_quota()).result(quota)
with mocker:
result = self.dal.list_volumes("user_id")
self.assertEqual(sorted(result), ["free_bytes", "root", "shares", "udfs"])
self.assertEqual(result["root"], dict(generation=123, root_id="root_id"))
self.assertEqual(result["free_bytes"], 4567890)
示例4: test
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test(c):
with test_app() as app:
m = Mocker()
fc = FindController(app)
flog = m.replace("editxt.command.find.log")
beep = m.replace(mod, "beep")
get_editor = m.method(fc.get_editor)
sender = m.mock()
(sender.tag() << c.tag).count(1, 2)
func = None
for tag, meth in list(fc.action_registry.items()):
fc.action_registry[tag] = temp = m.mock(meth)
if tag == c.tag:
func = temp
if c.fail:
flog.info(ANY, c.tag)
else:
if c.error:
err = mod.CommandError("error!")
expect(func(sender)).throw(err)
beep()
editor = get_editor() >> (m.mock() if c.target else None)
if c.target:
editor.message("error!", msg_type=const.ERROR)
else:
flog.warn(err)
else:
func(sender)
with m:
fc.perform_action(sender)
示例5: test
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test(c):
if c.eol != "\n":
c.input = c.input.replace("\n", c.eol)
c.output = c.output.replace("\n", c.eol)
result = []
m = Mocker()
tv = m.mock(NSTextView)
reset = (c.new == "\t")
if c.old != c.new or reset:
tv.string() >> c.input
rng = NSMakeRange(0, len(c.input))
tv.shouldChangeTextInRange_replacementString_(rng, c.output) >> True
if reset:
doc = tv.doc_view.document >> m.mock(TextDocument)
doc.reset_text_attributes(c.size)
if c.input != c.output:
sel = tv.selectedRange() >> NSRange(*c.sel)
ts = tv.textStorage() >> m.mock(NSTextStorage)
ts.replaceCharactersInRange_withString_(rng, c.output)
if sel.location > len(c.output):
sel = NSRange(len(c.output), 0)
elif sel.location + sel.length > len(c.output):
sel = NSRange(sel.location, len(c.output) - sel.location)
tv.setSelectedRange_(sel)
tv.didChangeText()
with m:
mod.change_indentation(tv, c.old, c.new, c.size)
示例6: test_parsing_files_with_proper_header_returns_parsed_scenario
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_parsing_files_with_proper_header_returns_parsed_scenario():
mocker = Mocker()
settings = Settings()
files = ["some path"]
story_text = """As a someone
I want to do something
So that I'm happy"""
filemock = mocker.mock()
filemock.list_files(directories=settings.tests_dirs, pattern=settings.file_pattern)
mocker.result(files)
filemock.read_file(files[0])
mocker.result(story_text)
language_mock = mocker.mock()
language_mock.get("as_a")
mocker.result("As a")
language_mock.get("i_want_to")
mocker.result("I want to")
language_mock.get("so_that")
mocker.result("So that")
with mocker:
parser = FileParser(language=language_mock, file_object=filemock)
fixture = parser.get_stories(settings=settings)
assert len(fixture.stories) == 1
assert fixture.stories[0].as_a == "someone"
assert fixture.stories[0].i_want_to == "do something"
assert fixture.stories[0].so_that == "I'm happy"
示例7: test
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test(c):
if c.eol != "\n":
c.input = c.input.replace("\n", c.eol)
c.output = c.output.replace("\n", c.eol)
result = TestConfig()
default = False
m = Mocker()
tv = m.mock(ak.NSTextView)
(tv.doc_view.document.indent_mode << c.mode).count(0, None)
(tv.doc_view.document.indent_size << c.size).count(0, None)
(tv.doc_view.document.eol << c.eol).count(0, None)
sel = fn.NSMakeRange(*c.oldsel); (tv.selectedRange() << sel).count(0, None)
(tv.string() << fn.NSString.stringWithString_(c.input)).count(0, None)
(tv.shouldChangeTextInRange_replacementString_(ANY, ANY) << True).count(0, None)
ts = m.mock(ak.NSTextStorage); (tv.textStorage() << ts).count(0, None)
c.setup(m, c, TestConfig(locals()))
def do_text(sel, repl):
result.text = c.input[:sel[0]] + repl + c.input[sel[0] + sel[1]:]
expect(ts.replaceCharactersInRange_withString_(ANY, ANY)).call(do_text).count(0, None)
def do_sel(sel):
result.sel = sel
expect(tv.setSelectedRange_(ANY)).call(do_sel).count(0, None)
expect(tv.didChangeText()).count(0, None)
if c.scroll:
tv.scrollRangeToVisible_(ANY)
with m:
c.method(tv, None, None)
if "text" in result:
eq_(result.text, c.output)
else:
eq_(c.output, SAME)
if "sel" in result:
eq_(result.sel, c.newsel)
示例8: test_execute_action_will_not_execute_itself
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_execute_action_will_not_execute_itself():
mocker = Mocker()
class DoSomethingRecursiveAction(ActionBase):
regex = r'^(And )?I do "(?P<what>\w+)" stuff$'
def execute(self, context, getter_mock, *args, **kwargs):
self.execute_action('And I do "recursive" stuff', context, getter=getter_mock)
language_getter_mock = mocker.mock()
language_getter_mock.get(ANY)
mocker.count(min=1, max=None)
mocker.result("^$")
context_mock = Object(settings=mocker.mock())
context_mock.settings.default_culture
mocker.result("en-us")
with mocker:
dosaction = DoSomethingRecursiveAction()
args = []
kwargs = dict(what="nothing")
dosaction.execute(context_mock, getter_mock=language_getter_mock, *args, **kwargs)
示例9: test_pyccuracy_core_run_tests_works_when_None_Result_returned_from_story_runner
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_pyccuracy_core_run_tests_works_when_None_Result_returned_from_story_runner():
mocker = Mocker()
context_mock, fso_mock = make_context_and_fso_mocks(mocker)
context_mock.settings.write_report
mocker.result(False)
suite_mock = mocker.mock()
suite_mock.no_story_header
mocker.result([])
suite_mock.stories
mocker.result(['some story'])
runner_mock = mocker.mock()
parser_mock = mocker.mock()
parser_mock.used_actions
mocker.count(min=1, max=None)
mocker.result([])
parser_mock.get_stories(ANY)
mocker.result(suite_mock)
runner_mock.run_stories(KWARGS)
mocker.result(None)
with mocker:
pc = PyccuracyCore(parser_mock, runner_mock)
assert pc.run_tests(should_throw=False, context=context_mock, fso=fso_mock) == None
示例10: test_set_main_view_of_window
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_set_main_view_of_window():
proj = Project.create()
m = Mocker()
view = m.mock(NSView)
win = m.mock(NSWindow)
with m:
proj.set_main_view_of_window(view, win) # for now this does nothing
示例11: test
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test(c):
proj = Project.create()
m = Mocker()
dsd_class = m.replace("editxt.application.DocumentSavingDelegate")
app = m.replace("editxt.app", type=Application)
ed = m.mock(Editor)
app.find_editors_with_project(proj) >> [ed for x in xrange(c.num_eds)]
if c.num_eds == 1:
docs = [m.mock(TextDocumentView)]
doc = docs[0].document >> m.mock(TextDocument)
app.iter_editors_with_view_of_document(doc) >> \
(ed for x in xrange(c.num_doc_views))
dirty_documents = m.method(proj.dirty_documents)
dirty_documents() >> docs
def check_docs(_docs):
d = docs if c.num_doc_views == 1 else []
eq_(list(_docs), d + [proj])
return True
callback = []
def get_callback(func):
callback.append(func)
return True
def do_callback():
callback[0](c.should_close)
saver = m.mock(DocumentSavingDelegate)
dsd_class.alloc() >> saver
saver.init_callback_(MATCH(check_docs), MATCH(get_callback)) >> saver
expect(saver.save_next_document()).call(do_callback)
if c.should_close:
ed.discard_and_focus_recent(proj)
else:
ed.discard_and_focus_recent(proj)
with m:
proj.perform_close(ed)
示例12: test_collect_process_info_new_report
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_collect_process_info_new_report(self):
"""Check how the process info is collected first time."""
mocker = Mocker()
assert not self.worker.process_cache
# patch Process to return our mock for test pid
Process = mocker.mock()
self.patch(stats_worker.psutil, 'Process', Process)
proc = mocker.mock()
pid = 1234
expect(Process(pid)).result(proc)
# patch ProcessReport to return or mock for given proc
ProcessReport = mocker.mock()
self.patch(stats_worker, 'ProcessReport', ProcessReport)
proc_report = mocker.mock()
expect(ProcessReport(proc)).result(proc_report)
# expect to get called with some info, return some results
name = 'test_proc'
result = object()
expect(proc_report.get_memory_and_cpu(prefix=name)).result(result)
with mocker:
real = self.worker._collect_process(pid, name)
self.assertIdentical(real, result)
示例13: test_find_match_not_matched
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_find_match_not_matched(self):
key1 = "chr1:154000-230000"
mocker = Mocker()
junction = mocker.mock()
junction.coverage
mocker.result(40)
container1 = mocker.mock()
container2 = mocker.mock()
container1.keys()
mocker.result([key1])
container1[key1]
mocker.result(junction)
container2[key1]
mocker.throw(KeyError)
mocker.count(1)
mocker.replay()
self.common, self.diff = jc.findMatch(container1, container2)
self.assertEqual(self.common.keys(), [])
self.assertEqual(self.diff.keys(), [key1])
mocker.restore()
mocker.verify()
示例14: test_get_share
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_get_share(self):
"""Get a share."""
mocker = Mocker()
# the share
share = mocker.mock()
expect(share.id).result('share_id')
expect(share.root_id).result('share_root_id')
expect(share.name).result('name')
expect(share.shared_by_id).result('shared_by_id')
expect(share.shared_to_id).result('shared_to_id')
expect(share.accepted).result(True)
expect(share.access).result(1)
# user
user = mocker.mock()
self.dal._get_user = lambda *a: user
expect(user.get_share('share_id')).result(share)
with mocker:
result = self.dal.get_share('user_id', 'share_id')
should = dict(share_id='share_id', share_root_id='share_root_id',
name='name', shared_by_id='shared_by_id', accepted=True,
shared_to_id='shared_to_id', access=1)
self.assertEqual(result, should)
示例15: test_pyccuracy_core_run_tests
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import mock [as 别名]
def test_pyccuracy_core_run_tests():
mocker = Mocker()
context_mock, fso_mock = make_context_and_fso_mocks(mocker)
context_mock.settings.write_report
mocker.result(False)
suite_mock = mocker.mock()
suite_mock.no_story_header
mocker.result([])
suite_mock.stories
mocker.result(['some story'])
runner_mock = mocker.mock()
parser_mock = mocker.mock()
parser_mock.used_actions
mocker.count(min=1, max=None)
mocker.result([])
results_mock = mocker.mock()
results_mock.summary_for('en-us')
mocker.result('my results')
parser_mock.get_stories(ANY)
mocker.result(suite_mock)
runner_mock.run_stories(KWARGS)
mocker.result(results_mock)
with mocker:
pc = PyccuracyCore(parser_mock, runner_mock)
#TODO: falha
results = pc.run_tests(should_throw=False, context=context_mock, fso=fso_mock)
assert results == results_mock, results