1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozdevice/sut_tests/dmunit.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +import types 1.9 +import unittest 1.10 + 1.11 +import mozlog 1.12 + 1.13 +from mozdevice import devicemanager 1.14 +from mozdevice import devicemanagerSUT 1.15 + 1.16 +ip = '' 1.17 +port = 0 1.18 +heartbeat_port = 0 1.19 +log_level = mozlog.ERROR 1.20 + 1.21 +class DeviceManagerTestCase(unittest.TestCase): 1.22 + """DeviceManager tests should subclass this. 1.23 + """ 1.24 + 1.25 + """Set to False in your derived class if this test 1.26 + should not be run on the Python agent. 1.27 + """ 1.28 + runs_on_test_device = True 1.29 + 1.30 + def _setUp(self): 1.31 + """ Override this if you want set-up code in your test.""" 1.32 + return 1.33 + 1.34 + def setUp(self): 1.35 + self.dm = devicemanagerSUT.DeviceManagerSUT(host=ip, port=port, 1.36 + logLevel=log_level) 1.37 + self.dmerror = devicemanager.DMError 1.38 + self._setUp() 1.39 + 1.40 + 1.41 +class DeviceManagerTestLoader(unittest.TestLoader): 1.42 + 1.43 + def __init__(self, isTestDevice=False): 1.44 + self.isTestDevice = isTestDevice 1.45 + 1.46 + def loadTestsFromModuleName(self, module_name): 1.47 + """Loads tests from modules unless the SUT is a test device and 1.48 + the test case has runs_on_test_device set to False 1.49 + """ 1.50 + tests = [] 1.51 + module = __import__(module_name) 1.52 + for name in dir(module): 1.53 + obj = getattr(module, name) 1.54 + if (isinstance(obj, (type, types.ClassType)) and 1.55 + issubclass(obj, unittest.TestCase)) and \ 1.56 + (not self.isTestDevice or obj.runs_on_test_device): 1.57 + tests.append(self.loadTestsFromTestCase(obj)) 1.58 + return self.suiteClass(tests)