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


Python call.write方法代码示例

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


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

示例1: test_check__checksum_new

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_check__checksum_new(self, nowflt, fp):
        # Prepare test
        self.key = self.test_check__checksum_new.__name__
        nowflt.return_value = self.now
        self.cache.fp = fp
        # Execute test
        result = self.cache.check(self.key, self.path, self.part)

        # Evaluate internal state (attributes values)
        self.assertIsNone(self.cache.cache_hit, ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_hit'))
        self.assertTrue(result, ASSERT_INVALID_RETURNED_VALUE_FMT.format('sr_cache.check'))
        expected = {self.key: self.cache_entry}
        assert_msg = ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_dict')
        self.assertDictEqual(expected, self.cache.cache_dict, assert_msg)
        assert_msg = ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache.count')
        self.assertEqual(self.count + 1, self.cache.count, assert_msg)

        # Evaluate external calls
        expected = [call.write(WRITE_LINE_FMT.format(self.key, nowflt.return_value, self.file, self.part))]
        self.assertEqual(expected, fp.mock_calls, ASSERT_MOCK_CALLS) 
开发者ID:MetPX,项目名称:sarracenia,代码行数:22,代码来源:test_sr_cache.py

示例2: test_check__checksum_same__value_same__cache_hit

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_check__checksum_same__value_same__cache_hit(self, nowflt, fp):
        # Prepare test
        self.key = self.test_check__checksum_same__value_same__cache_hit.__name__
        nowflt.return_value = self.now + 1
        self.cache.fp = fp
        self.cache.cache_dict[self.key] = self.cache_entry
        self.cache.count += 1
        # Execute test
        result = self.cache.check(self.key, self.path, self.part)

        # Evaluate internal state (attributes values)
        self.assertFalse(result, ASSERT_INVALID_RETURNED_VALUE_FMT.format('sr_cache.check'))
        assert_msg = ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_hit')
        self.assertEqual(self.cache_entry.popitem()[0], self.cache.cache_hit, assert_msg)
        expected = {self.key: self.cache_entry}
        self.assertDictEqual(expected, self.cache.cache_dict, ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_dict'))
        self.assertEqual(self.count + 2, self.cache.count, ASSERT_INVALID_VALUE_FMT.format('sr_cache.count'))

        # Evaluate external calls
        expected = [call.write(WRITE_LINE_FMT.format(self.key, nowflt.return_value, self.file, self.part))]
        self.assertEqual(expected, fp.mock_calls, ASSERT_MOCK_CALLS) 
开发者ID:MetPX,项目名称:sarracenia,代码行数:23,代码来源:test_sr_cache.py

示例3: test_check__checksum_same__part_none__cache_new

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_check__checksum_same__part_none__cache_new(self, nowflt, fp):
        # Prepare test
        self.key = self.test_check__checksum_same__part_none__cache_new.__name__
        self.part = None
        nowflt.return_value = self.now + 1
        self.cache.fp = fp
        self.cache.cache_dict[self.key] = self.cache_entry
        self.cache.count += 1
        # Execute test
        result = self.cache.check(self.key, self.path, self.part)

        # Evaluate internal state (attributes values)
        self.assertIsNone(self.cache.cache_hit, ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_hit'))
        self.assertTrue(result, ASSERT_INVALID_RETURNED_VALUE_FMT.format('sr_cache.check'))
        expected = {self.key: self.cache_entry}
        self.assertDictEqual(expected, self.cache.cache_dict, ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_dict'))
        self.assertEqual(self.count + 2, self.cache.count, ASSERT_INVALID_VALUE_FMT.format('sr_cache.count'))

        # Evaluate external calls
        expected = [call.write(WRITE_LINE_FMT.format(self.key, nowflt.return_value, self.file, self.part))]
        self.assertEqual(expected, fp.mock_calls, ASSERT_MOCK_CALLS) 
开发者ID:MetPX,项目名称:sarracenia,代码行数:23,代码来源:test_sr_cache.py

示例4: test_check__checksum_same__part_weird__cache_new

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_check__checksum_same__part_weird__cache_new(self, nowflt, fp):
        # Prepare test
        self.key = self.test_check__checksum_same__part_weird__cache_new.__name__
        weird_part = 'p,457,1'
        nowflt.return_value = self.now + 1
        self.cache.fp = fp
        self.cache.cache_dict[self.key] = self.cache_entry
        self.cache.count += 1
        # Execute test
        result = self.cache.check(self.key, self.path, weird_part)

        # Evaluate internal state (attributes values)
        self.assertTrue(result, ASSERT_INVALID_RETURNED_VALUE_FMT.format('sr_cache.check'))
        self.assertIsNone(self.cache.cache_hit, ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_hit'))
        expected = {self.key: self.cache_entry}
        self.assertDictEqual(expected, self.cache.cache_dict, ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_dict'))
        self.assertEqual(self.count + 2, self.cache.count, ASSERT_INVALID_VALUE_FMT.format('sr_cache.count'))

        # Evaluate external calls
        expected = [call.write(WRITE_LINE_FMT.format(self.key, nowflt.return_value, self.file, weird_part))]
        self.assertEqual(expected, fp.mock_calls, ASSERT_MOCK_CALLS) 
开发者ID:MetPX,项目名称:sarracenia,代码行数:23,代码来源:test_sr_cache.py

示例5: test_check__checksum_same__part_differ__cache_hit

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_check__checksum_same__part_differ__cache_hit(self, nowflt, fp):
        # Prepare test
        self.key = self.test_check__checksum_same__part_differ__cache_hit.__name__
        different_part = 'p,457,3,46,1'
        nowflt.return_value = self.now + 1
        self.cache.fp = fp
        self.cache.cache_dict[self.key] = self.cache_entry
        self.cache.count += 1
        # Execute test
        result = self.cache.check(self.key, self.path, different_part)

        # Evaluate internal state (attributes values)
        self.assertFalse(result, ASSERT_INVALID_RETURNED_VALUE_FMT.format('sr_cache.check'))
        assert_msg = ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_hit')
        self.assertEqual(f'{self.file}*{different_part[:-5]}', self.cache.cache_hit[:-5], assert_msg)
        expected = {self.key: self.cache_entry}
        assert_msg = ASSERT_INVALID_VALUE_FMT.format('sr_cache.cache_dict')
        self.assertDictEqual(expected, self.cache.cache_dict, assert_msg)
        assert_msg = ASSERT_INVALID_VALUE_FMT.format('sr_cache.count')
        self.assertEqual(self.count + 2, self.cache.count, assert_msg)

        # Evaluate external calls
        expected = [call.write(WRITE_LINE_FMT.format(self.key, nowflt.return_value, self.file, different_part))]
        self.assertEqual(expected, fp.mock_calls, ASSERT_MOCK_CALLS) 
开发者ID:MetPX,项目名称:sarracenia,代码行数:26,代码来源:test_sr_cache.py

示例6: test_clean__fp

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_clean__fp(self, nowflt, fp):
        # Prepare test
        self.cache.fp = fp
        self.key = self.test_clean__fp.__name__
        nowflt.return_value = self.now
        self.cache.expire = 50
        self.then = self.now - 100
        self.then_key = KEY_FMT.format(self.key, 'expired')
        self.cache.cache_dict[self.key] = self.cache_entry
        self.cache.cache_dict[self.then_key] = {ENTRY_KEY_FMT.format(self.file, self.part): self.then}
        # Execute test
        self.cache.clean(persist=True)

        # Evaluate results
        expected = [call.write('{} {:f} {} {}\n'.format(self.key, self.now, self.file, self.part))]
        self.assertEqual(expected, fp.mock_calls, ASSERT_MOCK_CALLS) 
开发者ID:MetPX,项目名称:sarracenia,代码行数:18,代码来源:test_sr_cache.py

示例7: test_log_storage

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_log_storage(*mocks):
    open_mock = Mock()
    with patch('builtins.open', open_mock):
        metric = Metric(name='foo', value=8)
        log_storage = LogStorage(output_filename='mocked_file_name.log')
        log_storage.store([metric])
    assert open_mock.return_value.write.call_count == 2
    assert open_mock.return_value.method_calls[0] == call.write('foo 8 1\n') 
开发者ID:intel,项目名称:workload-collocation-agent,代码行数:10,代码来源:test_log_storage.py

示例8: test_log_storage_overwrite_mode

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_log_storage_overwrite_mode(logfile_mock, get_current_time_mock, pathlib_rename_mock):
    metric = Metric(name='foo', value=8)
    log_storage = LogStorage(output_filename='mocked_file_name.log', overwrite=True)
    log_storage.store([metric])
    logfile_mock.assert_has_calls([call().__enter__().write('foo 8\n')])
    pathlib_rename_mock.assert_called_once() 
开发者ID:intel,项目名称:workload-collocation-agent,代码行数:8,代码来源:test_log_storage.py

示例9: test_dump_file_object

# 需要导入模块: from unittest.mock import call [as 别名]
# 或者: from unittest.mock.call import write [as 别名]
def test_dump_file_object(self):
        with open('dummy', 'w') as f:
            pvl.dump(self.module, f)
            self.assertEqual([call.write(self.string.encode())],
                             f.method_calls) 
开发者ID:planetarypy,项目名称:pvl,代码行数:7,代码来源:test_init.py


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