当前位置: 首页>>代码示例>>Python>>正文


Python Mock.status方法代码示例

本文整理汇总了Python中unittest.mock.Mock.status方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.status方法的具体用法?Python Mock.status怎么用?Python Mock.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.Mock的用法示例。


在下文中一共展示了Mock.status方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mock_urlopen

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import status [as 别名]
 def mock_urlopen(url, data=None):
     headers = {"Replay-Nonce": "MockNonce"}
     response = Mock()
     response.status = 200
     if url.endswith("/new-reg"):
         headers["Location"] = "mock://reg-location"
         response.status = 201
     response.headers = headers
     response.read = Mock(return_value=b'{"mock": true}')
     return response
开发者ID:drdaeman,项目名称:le_client,代码行数:12,代码来源:tests.py

示例2: test_git_io_error_status_response

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import status [as 别名]
 def test_git_io_error_status_response(self):
     error_status_response = Mock()
     error_status_response.status = 500
     error_status_response.read.return_value = b'some_error'
     with patch('gitio.urlopen', return_value=error_status_response) as mocked_urlopen:
         result = gitio.gitio(GITIO_TEST_URL)
         mocked_urlopen.assert_called_with(gitio.gitio_url, GITIO_TEST_DATA)
         self.assertEqual(result, ('some_error', None))
开发者ID:condemil,项目名称:Gist,代码行数:10,代码来源:test_gitio.py

示例3: test_git_io

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import status [as 别名]
 def test_git_io(self):
     response = Mock()
     response.status = 200
     response.read.return_value = b'some_data'
     with patch('gitio.urlopen', return_value=response) as mocked_urlopen:
         result = gitio.gitio(GITIO_TEST_URL)
         mocked_urlopen.assert_called_with(gitio.gitio_url, GITIO_TEST_DATA)
         self.assertEqual(result, (None, 'https://git.io/some_data'))
开发者ID:condemil,项目名称:Gist,代码行数:10,代码来源:test_gitio.py

示例4: test_can_retrieve_the_game_status_from_game_data

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import status [as 别名]
    def test_can_retrieve_the_game_status_from_game_data(self, mock_loads):
        game = Game()
        game_data = Mock()
        game_data.status = 'status string'
        mock_loads.return_value = game_data

        game_status = game.status

        assert game_status == 'status string'
开发者ID:Wilfcastle,项目名称:colonies,代码行数:11,代码来源:test_models.py

示例5: get_datasource_mock

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import status [as 别名]
 def get_datasource_mock(self):
     datasource = Mock()
     results = Mock()
     results.query = Mock()
     results.status = Mock()
     results.error_message = None
     results.df = pd.DataFrame()
     datasource.type = 'table'
     datasource.query = Mock(return_value=results)
     mock_dttm_col = Mock()
     datasource.get_col = Mock(return_value=mock_dttm_col)
     datasource.query = Mock(return_value=results)
     datasource.database = Mock()
     datasource.database.db_engine_spec = Mock()
     datasource.database.db_engine_spec.mutate_expression_label = lambda x: x
     return datasource
开发者ID:tan31989,项目名称:caravel,代码行数:18,代码来源:base_tests.py

示例6: __mockConnection

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import status [as 别名]
def __mockConnection(connection_mock, response_data='', response_status=200, response_reason='OK', raise_=None):
    # http response mock
    response_mock = Mock(spec=http.client.HTTPResponse)
    response_mock.read = io.BytesIO(response_data.encode()).read
    response_mock.status = response_status
    response_mock.reason = response_reason

    # connectionmock
    connection_mock.getresponse.return_value = response_mock
    if raise_:
        connection_mock.request = __createRaiser(raise_)

    # class mock
    class_mock = Mock()
    class_mock.return_value = connection_mock

    return class_mock
开发者ID:Turgon37,项目名称:DynUpdate,代码行数:19,代码来源:connexionmock.py

示例7: TestMelissa

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import status [as 别名]
class TestMelissa(unittest.TestCase):
    """Tests for Melissa climate."""

    def setUp(self):  # pylint: disable=invalid-name
        """Set up test variables."""
        self.hass = get_test_home_assistant()
        self._serial = '12345678'

        self.api = Mock()
        self.api.fetch_devices.return_value = json.loads(load_fixture(
            'melissa_fetch_devices.json'
        ))
        self.api.status.return_value = json.loads(load_fixture(
            'melissa_status.json'
        ))

        self.api.TEMP = 'temp'
        self.api.HUMIDITY = 'humidity'
        device = self.api.fetch_devices()[self._serial]
        self.temp = MelissaTemperatureSensor(device, self.api)
        self.hum = MelissaHumiditySensor(device, self.api)

    def tearDown(self):  # pylint: disable=invalid-name
        """Teardown this test class. Stop hass."""
        self.hass.stop()

    def test_setup_platform(self):
        """Test setup_platform."""
        self.hass.data[DATA_MELISSA] = self.api

        config = {}
        add_entities = Mock()
        discovery_info = {}

        melissa.setup_platform(self.hass, config, add_entities, discovery_info)

    def test_name(self):
        """Test name property."""
        device = self.api.fetch_devices()[self._serial]
        self.assertEqual(self.temp.name, '{0} {1}'.format(
            device['name'],
            self.temp._type
        ))
        self.assertEqual(self.hum.name, '{0} {1}'.format(
            device['name'],
            self.hum._type
        ))

    def test_state(self):
        """Test state property."""
        device = self.api.status()[self._serial]
        self.temp.update()
        self.assertEqual(self.temp.state, device[self.api.TEMP])
        self.hum.update()
        self.assertEqual(self.hum.state, device[self.api.HUMIDITY])

    def test_unit_of_measurement(self):
        """Test unit of measurement property."""
        self.assertEqual(self.temp.unit_of_measurement, TEMP_CELSIUS)
        self.assertEqual(self.hum.unit_of_measurement, '%')

    def test_update(self):
        """Test for update."""
        self.temp.update()
        self.assertEqual(self.temp.state, 27.4)
        self.hum.update()
        self.assertEqual(self.hum.state, 18.7)

    def test_update_keyerror(self):
        """Test for faulty update."""
        self.temp._api.status.return_value = {}
        self.temp.update()
        self.assertEqual(None, self.temp.state)
        self.hum._api.status.return_value = {}
        self.hum.update()
        self.assertEqual(None, self.hum.state)
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:78,代码来源:test_melissa.py


注:本文中的unittest.mock.Mock.status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。