OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Client side of the mock adb (i.e. the one called instead of the actual adb). |
| 7 |
| 8 This file is meant to be put in front of the PATH during integration tests, in |
| 9 order to route all the adb calls here and serve them using a pre-configured |
| 10 dictionary (epxected commands -> planned responses). |
| 11 mock_adb.py is the counterpart of this file, and is meant to be used in the |
| 12 unittests for configuring the behavior (i.e. the dictionary) of this script. |
| 13 """ |
| 14 |
| 15 import json |
| 16 import optparse |
| 17 import os |
| 18 import sys |
| 19 |
| 20 |
| 21 def main(argv): |
| 22 # Load the dictionary of expected_cmd -> planned_response from the json file |
| 23 # which mock_adb.py creates. |
| 24 with open(os.environ['MOCK_ADB_CFG']) as f: |
| 25 responses = json.load(f) |
| 26 |
| 27 # Swallow the irrelevant adb extra arguments (e.g., device id). |
| 28 parser = optparse.OptionParser() |
| 29 parser.add_option('-s') |
| 30 options, args = parser.parse_args(argv[1:]) |
| 31 adb_args = ' '.join(args) |
| 32 |
| 33 response = '' |
| 34 for (cmd, planned_response) in responses.iteritems(): |
| 35 if adb_args.startswith(cmd): |
| 36 response = planned_response |
| 37 print response |
| 38 |
| 39 if __name__ == '__main__': |
| 40 main(sys.argv) |
OLD | NEW |