本文整理汇总了Python中mockito.mockito.when函数的典型用法代码示例。如果您正苦于以下问题:Python when函数的具体用法?Python when怎么用?Python when使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了when函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cleanup_quits_webdrivers
def test_cleanup_quits_webdrivers(self):
"Tests that clean up is performed on webdrivers created by WebdriverManger"
config_reader = mock(ConfigReader)
when(config_reader).get(
WebDriverManager.SHUTDOWN_HOOK_CONFIG, True).thenReturn(True)
when(config_reader).get(
WebDriverManager.REUSE_BROWSER, True).thenReturn(False)
when(config_reader).get(
WebDriverManager.REUSE_BROWSER, True).thenReturn(False)
when(config_reader).get(
WebDriverManager.ENABLE_THREADING_SUPPORT, False).thenReturn(True)
webdriver_mock1 = mock(WebDriver)
webdriverfactory_mock = mock(WebDriverFactory)
when(webdriverfactory_mock).create_webdriver(
testname=None).thenReturn(webdriver_mock1)
webdriver_provider = WebDriverManager(webdriver_factory=webdriverfactory_mock,
config=config_reader)
# Spawn thread to check if driver is unique per thread.
driver = webdriver_provider.get_driver()
del webdriver_provider
# verify decontructor cleans up the webdriver.
verify(driver).quit()
示例2: test_retryWhenTryingToGetStoriesAndException
def test_retryWhenTryingToGetStoriesAndException(self):
tracker = self.makeValidTracker()
trackerInstance = self.trackerInstance_
when(trackerInstance).GetStories(any()).thenRaise(Exception("")).thenReturn([Story(),Story()])
when(trackerInstance).GetComments(any()).thenReturn([])
next(tracker.items())
verify(trackerInstance, times=2).GetStories(any())
示例3: test_CanRetrieveDevicesListFiltered
def test_CanRetrieveDevicesListFiltered():
pertinoSdk, _, response = setupSdk()
json = {"devices": [{"ipv4Address": "123.456.789.10", "hostName": "host", "id": 1234}]}
when(response).json().thenReturn(json)
closure = mock()
pertinoSdk.listDevicesIn({"id":1}, closure.function)
verify(closure).function(json["devices"][0])
示例4: setupSync
def setupSync(self, syncDirection=ForwardSync):
toTracker = mock()
itemToSyncTo = mock()
itemToSyncFrom = mock()
syncCommentsFor = TrackerSyncBy.syncingItem(Direction=syncDirection)
when(toTracker).items(None).thenReturn(Testing.MockIterator([itemToSyncTo]))
return toTracker, itemToSyncTo, itemToSyncFrom, syncCommentsFor
示例5: test_onlyTakeCommentsFromIssueForByFilter
def test_onlyTakeCommentsFromIssueForByFilter(self):
toTracker = mock()
aTestItemFilter = mock()
syncCommentsFor = TrackerSyncBy.syncingItem(aTestItemFilter.calledWith)
when(toTracker).items(None).thenRaise(StopIteration)
syncCommentsFor(None, toTracker)
verify(aTestItemFilter).calledWith(None)
示例6: test_doNotAddItemWhenNoItemToAdd
def test_doNotAddItemWhenNoItemToAdd(self):
toTracker = mock()
fromTracker = mock()
when(fromTracker).items(any()).thenReturn([])
syncByAddingItems = TrackerSyncBy.addingItemsOfType(None)
syncByAddingItems(fromTracker, toTracker)
verify(toTracker, never).update()
示例7: test_doNotAddCommentsWhenItemNotFound
def test_doNotAddCommentsWhenItemNotFound(self):
toTracker = mock()
item = mock()
syncCommentsFor = TrackerSyncBy.syncingItem()
when(toTracker).items(None).thenRaise(StopIteration)
syncCommentsFor(item, toTracker)
verify(toTracker, never).update(item)
示例8: test_should_return_empty_running_environment_if_nothing_is_running
def test_should_return_empty_running_environment_if_nothing_is_running(self):
mock_command_helper = mock()
when(mock_command_helper).run_command("sudo lxc-ls -c1").thenReturn("")
provider = LXCNodeProvider(None, None, mock_command_helper)
environment = provider.get_running_environment("test", "test", all_credentials)
self.assertIsNotNone(environment)
self.assertEqual(0, len(environment.get_locations()))
示例9: test_user_can_login_with_password
def test_user_can_login_with_password(self):
cli = mock()
user = User("username", "password", cli)
when(cli).compareReceivedAgainst(any(),any(), indexOfSuccessfulResult=any()).thenReturn(0).thenReturn(1)
user.login()
verify(cli).send("su username")
verify(cli).send("password")
示例10: test_should_throw_exception_when_node_is_not_up_and_running
def test_should_throw_exception_when_node_is_not_up_and_running(self):
mock_connection_provider = mock()
tags = {
'services' : """
'apache' :
80: 80""",
'credentials_name': 'test',
'env_name' : 'test',
'env_def_name' : 'Single-AZ Deployment',
}
fake_boto_instance1 = mock()
fake_boto_instance1.tags = tags
stub_region = mock()
stub_region.name = 'eu-west'
fake_boto_instance1.region = stub_region
fake_boto_instance1.id = 'id1234'
fake_boto_instance1.ip_address = 'test_ip'
fake_boto_instance1.state = 'running'
fake_boto_instance1.placement='us-east-1'
aws_node = AWSRunningNode(fake_boto_instance1, None, mock_connection_provider)
when(mock_connection_provider).connected_to_node('test_ip', 22).thenReturn(False)
with self.assertRaisesRegexp(Exception, "Node id1234 is not running"):
aws_node.wait_for_ready(lambda : None, 5)
示例11: test_CanRetrieveOrganizationListFiltered
def test_CanRetrieveOrganizationListFiltered():
pertinoSdk, _, response = setupSdk()
json = {"orgs": [{"name": "organization", "id": 1234}]}
when(response).json().thenReturn(json)
closure = mock()
pertinoSdk.listOrgs(closure=closure.function)
verify(closure).function(json["orgs"][0])
示例12: test_multithreadMode
def test_multithreadMode(self):
"""
Tests that when we call get_driver() it returns a unique driver for each thread,
but for the same thread returns the same driver.
"""
config_reader = mock(ConfigReader)
when(config_reader).get(WebDriverManager.SHUTDOWN_HOOK_CONFIG, any()).thenReturn(True)
when(config_reader).get(WebDriverManager.REUSE_BROWSER, any()).thenReturn(False)
when(config_reader).get(WebDriverManager.REUSE_BROWSER, any()).thenReturn(False)
when(config_reader).get(WebDriverManager.ENABLE_THREADING_SUPPORT, any()).thenReturn(True)
webdriverfactory_mock = mock(WebDriverFactory)
when(webdriverfactory_mock).create_webdriver(testname=None).thenReturn(mock(WebDriver))\
.thenReturn(mock(WebDriver)).thenReturn(mock(WebDriver))
webdriver_provider = WebDriverManager(webdriver_factory=webdriverfactory_mock,
config = config_reader)
# Spawn thread to check if driver is unique per thread.
driver1 = webdriver_provider.get_driver()
t = threading.Thread(target=lambda: self.__multithreaded_7est_thread2(driver1, webdriver_provider))
t.start()
t.join()
self.assertFalse(self._driver_from_thread_is_same)
# Check that driver is same for the same thread.
driver3 = webdriver_provider.get_driver()
self.assertEqual(driver1, driver3, "Same thread should return same driver.")
示例13: test_whenJiraIdIsZeroNameIsNone
def test_whenJiraIdIsZeroNameIsNone(self):
jiraStatus = mock()
mapObject = mock()
when(jiraStatus).status().thenReturn("")
status = TrackerItemStatus(jiraStatus, mapObject)
verify(mapObject, never).translateStatusTo(any(), any())
self.assertEqual(status.jira(), None)
示例14: test_noDeletionsWhenNoItems
def test_noDeletionsWhenNoItems(self):
tracker = self.makeValidTracker()
trackerInstance = self.trackerInstance_
when(trackerInstance).GetStories(any()).thenReturn([])
tracker.deleteAllItems()
verify(trackerInstance, never).DeleteStory(any())
pass
示例15: test_mode_exited
def test_mode_exited(self):
cli = self.makeCli()
when(cli).compareReceivedAgainst(any(),any()).thenReturn(0)
testMode = Mode(cli)
testMode.exit()
verify(cli).exitMode(testMode)
verify(cli).send("exit")