1# Copyright 2016 Google Inc. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# This is a mock third-party controller module used for unit testing Mobly. 16 17import logging 18 19MOBLY_CONTROLLER_CONFIG_NAME = "MagicDevice" 20 21 22def create(configs): 23 objs = [] 24 for c in configs: 25 if isinstance(c, dict): 26 c.pop("serial") 27 objs.append(MagicDevice(c)) 28 return objs 29 30 31def destroy(objs): 32 print("Destroying magic") 33 34 35def get_info(objs): 36 infos = [] 37 for obj in objs: 38 infos.append(obj.who_am_i()) 39 return infos 40 41 42class MagicDevice: 43 44 def __init__(self, config): 45 self.magic = config 46 47 def get_magic(self): 48 logging.info("My magic is %s.", self.magic) 49 return self.magic 50 51 def who_am_i(self): 52 return {"MyMagic": self.magic} 53