testing/mozbase/mozdevice/sut_tests/dmunit.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial