testing/mozbase/moztest/tests/test.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/moztest/tests/test.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 +# You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +import math
     1.9 +import time
    1.10 +import unittest
    1.11 +
    1.12 +from moztest.results import TestContext, TestResult, TestResultCollection
    1.13 +
    1.14 +
    1.15 +class Result(unittest.TestCase):
    1.16 +
    1.17 +    def test_results(self):
    1.18 +        self.assertRaises(AssertionError,
    1.19 +                          lambda: TestResult('test', result_expected='hello'))
    1.20 +        t = TestResult('test')
    1.21 +        self.assertRaises(ValueError, lambda: t.finish(result='good bye'))
    1.22 +
    1.23 +    def test_time(self):
    1.24 +        now = time.time()
    1.25 +        t = TestResult('test')
    1.26 +        time.sleep(1)
    1.27 +        t.finish('PASS')
    1.28 +        duration = time.time() - now
    1.29 +        self.assertTrue(math.fabs(duration - t.duration) < 1)
    1.30 +
    1.31 +    def test_custom_time(self):
    1.32 +        t = TestResult('test', time_start=0)
    1.33 +        t.finish(result='PASS', time_end=1000)
    1.34 +        self.assertEqual(t.duration, 1000)
    1.35 +
    1.36 +
    1.37 +class Collection(unittest.TestCase):
    1.38 +
    1.39 +    def setUp(self):
    1.40 +        c1 = TestContext('host1')
    1.41 +        c2 = TestContext('host2')
    1.42 +        c3 = TestContext('host2')
    1.43 +        c3.os = 'B2G'
    1.44 +        c4 = TestContext('host1')
    1.45 +
    1.46 +        t1 = TestResult('t1', context=c1)
    1.47 +        t2 = TestResult('t2', context=c2)
    1.48 +        t3 = TestResult('t3', context=c3)
    1.49 +        t4 = TestResult('t4', context=c4)
    1.50 +
    1.51 +        self.collection = TestResultCollection('tests')
    1.52 +        self.collection.extend([t1, t2, t3, t4])
    1.53 +
    1.54 +    def test_unique_contexts(self):
    1.55 +        self.assertEqual(len(self.collection.contexts), 3)
    1.56 +
    1.57 +if __name__ == '__main__':
    1.58 +    unittest.main()

mercurial