testing/mozbase/moztest/tests/test.py

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

mercurial