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.

     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/.
     5 import math
     6 import time
     7 import unittest
     9 from moztest.results import TestContext, TestResult, TestResultCollection
    12 class Result(unittest.TestCase):
    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'))
    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)
    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)
    34 class Collection(unittest.TestCase):
    36     def setUp(self):
    37         c1 = TestContext('host1')
    38         c2 = TestContext('host2')
    39         c3 = TestContext('host2')
    40         c3.os = 'B2G'
    41         c4 = TestContext('host1')
    43         t1 = TestResult('t1', context=c1)
    44         t2 = TestResult('t2', context=c2)
    45         t3 = TestResult('t3', context=c3)
    46         t4 = TestResult('t4', context=c4)
    48         self.collection = TestResultCollection('tests')
    49         self.collection.extend([t1, t2, t3, t4])
    51     def test_unique_contexts(self):
    52         self.assertEqual(len(self.collection.contexts), 3)
    54 if __name__ == '__main__':
    55     unittest.main()

mercurial