當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。