testing/mozbase/moztest/tests/test.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 file,
michael@0 3 # You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 import math
michael@0 6 import time
michael@0 7 import unittest
michael@0 8
michael@0 9 from moztest.results import TestContext, TestResult, TestResultCollection
michael@0 10
michael@0 11
michael@0 12 class Result(unittest.TestCase):
michael@0 13
michael@0 14 def test_results(self):
michael@0 15 self.assertRaises(AssertionError,
michael@0 16 lambda: TestResult('test', result_expected='hello'))
michael@0 17 t = TestResult('test')
michael@0 18 self.assertRaises(ValueError, lambda: t.finish(result='good bye'))
michael@0 19
michael@0 20 def test_time(self):
michael@0 21 now = time.time()
michael@0 22 t = TestResult('test')
michael@0 23 time.sleep(1)
michael@0 24 t.finish('PASS')
michael@0 25 duration = time.time() - now
michael@0 26 self.assertTrue(math.fabs(duration - t.duration) < 1)
michael@0 27
michael@0 28 def test_custom_time(self):
michael@0 29 t = TestResult('test', time_start=0)
michael@0 30 t.finish(result='PASS', time_end=1000)
michael@0 31 self.assertEqual(t.duration, 1000)
michael@0 32
michael@0 33
michael@0 34 class Collection(unittest.TestCase):
michael@0 35
michael@0 36 def setUp(self):
michael@0 37 c1 = TestContext('host1')
michael@0 38 c2 = TestContext('host2')
michael@0 39 c3 = TestContext('host2')
michael@0 40 c3.os = 'B2G'
michael@0 41 c4 = TestContext('host1')
michael@0 42
michael@0 43 t1 = TestResult('t1', context=c1)
michael@0 44 t2 = TestResult('t2', context=c2)
michael@0 45 t3 = TestResult('t3', context=c3)
michael@0 46 t4 = TestResult('t4', context=c4)
michael@0 47
michael@0 48 self.collection = TestResultCollection('tests')
michael@0 49 self.collection.extend([t1, t2, t3, t4])
michael@0 50
michael@0 51 def test_unique_contexts(self):
michael@0 52 self.assertEqual(len(self.collection.contexts), 3)
michael@0 53
michael@0 54 if __name__ == '__main__':
michael@0 55 unittest.main()

mercurial