testing/mozbase/mozdevice/sut_tests/dmunit.py

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:feb894c5e4aa
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import types
6 import unittest
7
8 import mozlog
9
10 from mozdevice import devicemanager
11 from mozdevice import devicemanagerSUT
12
13 ip = ''
14 port = 0
15 heartbeat_port = 0
16 log_level = mozlog.ERROR
17
18 class DeviceManagerTestCase(unittest.TestCase):
19 """DeviceManager tests should subclass this.
20 """
21
22 """Set to False in your derived class if this test
23 should not be run on the Python agent.
24 """
25 runs_on_test_device = True
26
27 def _setUp(self):
28 """ Override this if you want set-up code in your test."""
29 return
30
31 def setUp(self):
32 self.dm = devicemanagerSUT.DeviceManagerSUT(host=ip, port=port,
33 logLevel=log_level)
34 self.dmerror = devicemanager.DMError
35 self._setUp()
36
37
38 class DeviceManagerTestLoader(unittest.TestLoader):
39
40 def __init__(self, isTestDevice=False):
41 self.isTestDevice = isTestDevice
42
43 def loadTestsFromModuleName(self, module_name):
44 """Loads tests from modules unless the SUT is a test device and
45 the test case has runs_on_test_device set to False
46 """
47 tests = []
48 module = __import__(module_name)
49 for name in dir(module):
50 obj = getattr(module, name)
51 if (isinstance(obj, (type, types.ClassType)) and
52 issubclass(obj, unittest.TestCase)) and \
53 (not self.isTestDevice or obj.runs_on_test_device):
54 tests.append(self.loadTestsFromTestCase(obj))
55 return self.suiteClass(tests)

mercurial