MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / test_write_to_file

Method test_write_to_file

tests/usage/test_usage_lib.py:346–360  ·  view source on GitHub ↗

Test writing usage data to file

(self, mock_file, mock_touch, mock_makedirs)

Source from the content-addressed store, hash-verified

344 @patch("fastdeploy.usage.usage_lib.Path.touch")
345 @patch("fastdeploy.usage.usage_lib.open", new_callable=mock_open)
346 def test_write_to_file(self, mock_file, mock_touch, mock_makedirs):
347 """Test writing usage data to file"""
348 usage_message = UsageMessage()
349 data = {"uuid": "test-uuid", "timestamp": 1234567890}
350
351 usage_message._write_to_file(data)
352
353 # Verify file operations
354 mock_makedirs.assert_called_once()
355 mock_touch.assert_called_once()
356
357 # Verify JSON was written
358 all_writes = [call.args[0] for call in mock_file().write.call_args_list]
359 full_content = "".join(all_writes)
360 self.assertEqual(json.loads(full_content), data)
361
362
363class TestReportUsageWorker(unittest.TestCase):

Callers

nothing calls this directly

Calls 3

_write_to_fileMethod · 0.95
UsageMessageClass · 0.90
joinMethod · 0.80

Tested by

no test coverage detected