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

Unified Diff: tools/memory_inspector/tests/mock_adb/mock_adb.py

Issue 158993002: Add Android-backend to the memory_inspector (prerequisites). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self-nits Created 6 years, 10 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: tools/memory_inspector/tests/mock_adb/mock_adb.py
diff --git a/tools/memory_inspector/tests/mock_adb/mock_adb.py b/tools/memory_inspector/tests/mock_adb/mock_adb.py
new file mode 100644
index 0000000000000000000000000000000000000000..dc8eee230e013016aef2b3b88a1347ca28185f23
--- /dev/null
+++ b/tools/memory_inspector/tests/mock_adb/mock_adb.py
@@ -0,0 +1,36 @@
+# Copyright 2014 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 json
+import os
+import tempfile
+
+
+class MockAdb(object):
+ """Simple and effective mock for Android adb.
+
+ This module is meant to be used in integration tests in conjunction with the
+ other script named 'adb' living in the same directory.
+ Essentially this class is used prepare a dictionary of mocked responses to adb
Philippe 2014/02/10 16:41:03 Nit: s/prepare/prepare to
Primiano Tucci (use gerrit) 2014/02/11 12:10:51 Done.
+ commands. The dictionary is stored into a json file and read by the mock 'adb'
+ script at each invocation. The path of the json dict is held in MOCK_ADB_CFG.
+ """
+
+ def __init__(self):
+ self._responses = {} # Maps expected_cmd (str) -> prepared_response (str).
+ self._cfg_file = None
+
+ def Start(self):
+ (fd_num, self._cfg_file) = tempfile.mkstemp()
+ with os.fdopen(fd_num, 'w') as f:
+ json.dump(self._responses, f)
+ f.close()
Philippe 2014/02/10 16:41:03 Nit: not sure this line is needed with the 'with'
Primiano Tucci (use gerrit) 2014/02/11 12:10:51 I found this in some code snippets. I'm afraid tha
+ os.environ['MOCK_ADB_CFG'] = self._cfg_file
+
+ def Stop(self):
+ assert(self._cfg_file), 'Stop called before Start.'
+ os.unlink(self._cfg_file)
+
+ def PrepareResponse(self, cmd, response):
+ self._responses[cmd] = response

Powered by Google App Engine
This is Rietveld 408576698