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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import os
7 import tempfile
8
9
10 class MockAdb(object):
11 """Simple and effective mock for Android adb.
12
13 This module is meant to be used in integration tests in conjunction with the
14 other script named 'adb' living in the same directory.
15 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.
16 commands. The dictionary is stored into a json file and read by the mock 'adb'
17 script at each invocation. The path of the json dict is held in MOCK_ADB_CFG.
18 """
19
20 def __init__(self):
21 self._responses = {} # Maps expected_cmd (str) -> prepared_response (str).
22 self._cfg_file = None
23
24 def Start(self):
25 (fd_num, self._cfg_file) = tempfile.mkstemp()
26 with os.fdopen(fd_num, 'w') as f:
27 json.dump(self._responses, f)
28 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
29 os.environ['MOCK_ADB_CFG'] = self._cfg_file
30
31 def Stop(self):
32 assert(self._cfg_file), 'Stop called before Start.'
33 os.unlink(self._cfg_file)
34
35 def PrepareResponse(self, cmd, response):
36 self._responses[cmd] = response
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698