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 second mock third-party controller module used for testing Mobly's 16# handling of multiple controller modules. 17 18import logging 19 20MOBLY_CONTROLLER_CONFIG_NAME = "AnotherMagicDevice" 21 22 23def create(configs): 24 objs = [] 25 for c in configs: 26 if isinstance(c, dict): 27 c.pop("serial") 28 objs.append(AnotherMagicDevice(c)) 29 return objs 30 31 32def destroy(objs): 33 print("Destroying other magic") 34 35 36def get_info(objs): 37 infos = [] 38 for obj in objs: 39 infos.append(obj.who_am_i()) 40 return infos 41 42 43class AnotherMagicDevice: 44 """This controller supports adding controller's info during test. 45 46 It is used for testing that this info is correctly recorded by Mobly. 47 """ 48 49 def __init__(self, config): 50 self.magic = config 51 52 def get_magic(self): 53 logging.info("My other magic is %s.", self.magic) 54 return self.magic 55 56 def set_magic(self, extra_magic): 57 self.magic['extra_magic'] = extra_magic 58 59 def who_am_i(self): 60 return {"MyOtherMagic": self.magic} 61