michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import types michael@0: import unittest michael@0: michael@0: import mozlog michael@0: michael@0: from mozdevice import devicemanager michael@0: from mozdevice import devicemanagerSUT michael@0: michael@0: ip = '' michael@0: port = 0 michael@0: heartbeat_port = 0 michael@0: log_level = mozlog.ERROR michael@0: michael@0: class DeviceManagerTestCase(unittest.TestCase): michael@0: """DeviceManager tests should subclass this. michael@0: """ michael@0: michael@0: """Set to False in your derived class if this test michael@0: should not be run on the Python agent. michael@0: """ michael@0: runs_on_test_device = True michael@0: michael@0: def _setUp(self): michael@0: """ Override this if you want set-up code in your test.""" michael@0: return michael@0: michael@0: def setUp(self): michael@0: self.dm = devicemanagerSUT.DeviceManagerSUT(host=ip, port=port, michael@0: logLevel=log_level) michael@0: self.dmerror = devicemanager.DMError michael@0: self._setUp() michael@0: michael@0: michael@0: class DeviceManagerTestLoader(unittest.TestLoader): michael@0: michael@0: def __init__(self, isTestDevice=False): michael@0: self.isTestDevice = isTestDevice michael@0: michael@0: def loadTestsFromModuleName(self, module_name): michael@0: """Loads tests from modules unless the SUT is a test device and michael@0: the test case has runs_on_test_device set to False michael@0: """ michael@0: tests = [] michael@0: module = __import__(module_name) michael@0: for name in dir(module): michael@0: obj = getattr(module, name) michael@0: if (isinstance(obj, (type, types.ClassType)) and michael@0: issubclass(obj, unittest.TestCase)) and \ michael@0: (not self.isTestDevice or obj.runs_on_test_device): michael@0: tests.append(self.loadTestsFromTestCase(obj)) michael@0: return self.suiteClass(tests)