adb revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1#!/usr/bin/env 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 8This file is meant to be put in front of the PATH during integration tests, in 9order to route all the adb calls here and serve them using a pre-configured 10dictionary (epxected commands -> planned responses). 11mock_adb.py is the counterpart of this file, and is meant to be used in the 12unittests for configuring the behavior (i.e. the dictionary) of this script. 13""" 14 15import json 16import optparse 17import os 18import sys 19 20 21def 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 39if __name__ == '__main__': 40 main(sys.argv)