Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: telemetry/telemetry/internal/backends/browser_backend_unittest.py

Issue 2053313002: [telemetry] Expose log file contents in telemetry.internal.browser.Browser (Closed) Base URL: git@github.com:catapult-project/catapult.git@master
Patch Set: Change decorator name Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: telemetry/telemetry/internal/backends/browser_backend_unittest.py
diff --git a/telemetry/telemetry/internal/backends/browser_backend_unittest.py b/telemetry/telemetry/internal/backends/browser_backend_unittest.py
index 549de2118d502c27d4f645db16b2044ab69a62f5..038349179b059213e49c182aaa15cb9fd8445b93 100644
--- a/telemetry/telemetry/internal/backends/browser_backend_unittest.py
+++ b/telemetry/telemetry/internal/backends/browser_backend_unittest.py
@@ -1,6 +1,9 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+
+import os
+import tempfile
import unittest
from telemetry.internal.backends import browser_backend
@@ -10,23 +13,32 @@ import mock
class BrowserBackendLogsUploadingUnittest(unittest.TestCase):
def testUploadingToCLoudStorage(self):
- # pylint: disable=abstract-method
- class FakeBrowserBackend(browser_backend.BrowserBackend):
- @property
- def supports_uploading_logs(self):
- return True
-
- @property
- def log_file_path(self):
- return '/foo/bar'
-
- options = options_for_unittests.GetCopy()
- options.browser_options.enable_logging = True
- options.browser_options.logs_cloud_bucket = 'ABC'
- options.browser_options.logs_cloud_remote_path = 'def'
-
- b = FakeBrowserBackend(None, False, options.browser_options, None)
- with mock.patch('catapult_base.cloud_storage.Insert') as mock_insert:
- b.UploadLogsToCloudStorage()
- mock_insert.assert_called_with(
- bucket='ABC', remote_path='def', local_path='/foo/bar')
+ temp_file = tempfile.NamedTemporaryFile(delete=False)
+ temp_file_name = temp_file.name
+ try:
+ temp_file.write('This is a\ntest log file.\n')
+ temp_file.close()
+
+ # pylint: disable=abstract-method
+ class FakeBrowserBackend(browser_backend.BrowserBackend):
+ @property
+ def supports_uploading_logs(self):
+ return True
+
+ @property
+ def log_file_path(self):
+ return temp_file_name
+
+ options = options_for_unittests.GetCopy()
+ options.browser_options.enable_logging = True
+ options.browser_options.logs_cloud_bucket = 'ABC'
+ options.browser_options.logs_cloud_remote_path = 'def'
+
+ b = FakeBrowserBackend(None, False, options.browser_options, None)
+ self.assertEquals(b.GetLogFileContents(), 'This is a\ntest log file.\n')
+ with mock.patch('catapult_base.cloud_storage.Insert') as mock_insert:
+ b.UploadLogsToCloudStorage()
+ mock_insert.assert_called_with(
+ bucket='ABC', remote_path='def', local_path=temp_file_name)
+ finally:
+ os.remove(temp_file_name)

Powered by Google App Engine
This is Rietveld 408576698