~barry/autopilot/lp1488175

« back to all changes in this revision

Viewing changes to autopilot/tests/functional/test_testcase.py

  • Committer: CI bot
  • Author(s): Leonardo Arias Fonseca, Thomi Richards, Christopher Lee, Leo Arias, nskaggs
  • Date: 2014-10-31 21:49:56 UTC
  • mfrom: (493.1.26 trunk)
  • Revision ID: ps-jenkins@lists.canonical.com-20141031214956-oaptmny2t0vgj973
Autopilot release:
  - Add support for large timestamps
  - Add per-test timeouts
  - Add press duration to touch clicks
  - Improved logging
  - Make own autopilot functional test runnable with testtools runner.   
Approved by: Nicholas Skaggs, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
 
21
21
from testtools import TestCase
 
22
from testtools.matchers import Contains
22
23
from testtools.content_type import ContentType
23
24
 
24
 
from autopilot.testcase import AutopilotTestCase
 
25
from unittest.mock import patch
 
26
import time
 
27
 
 
28
from autopilot import testcase
25
29
 
26
30
 
27
31
class AutopilotTestCaseScreenshotTests(TestCase):
28
32
    def test_screenshot_taken_when_test_fails(self):
29
 
        class InnerTest(AutopilotTestCase):
 
33
        class InnerTest(testcase.AutopilotTestCase):
30
34
            def test_foo(self):
31
35
                self.fail()
32
36
 
44
48
    def test_take_screenshot(self):
45
49
        screenshot_name = self.getUniqueString()
46
50
 
47
 
        class InnerTest(AutopilotTestCase):
 
51
        class InnerTest(testcase.AutopilotTestCase):
48
52
            def test_foo(self):
49
53
                self.take_screenshot(screenshot_name)
50
54
 
58
62
            screenshot_content.content_type,
59
63
            ContentType("image", "png")
60
64
        )
 
65
 
 
66
 
 
67
class TimedRunTestTests(TestCase):
 
68
 
 
69
    @patch.object(testcase, 'get_test_timeout', new=lambda: 5)
 
70
    def test_timed_run_test_times_out(self):
 
71
        class TimedTest(testcase.AutopilotTestCase):
 
72
 
 
73
            def test_will_timeout(self):
 
74
                time.sleep(10)  # should timeout after 5 seconds
 
75
 
 
76
        test = TimedTest('test_will_timeout')
 
77
        result = test.run()
 
78
        self.assertFalse(result.wasSuccessful())
 
79
        self.assertEqual(1, len(result.errors))
 
80
        self.assertThat(
 
81
            result.errors[0][1],
 
82
            Contains('raise TimeoutException()')
 
83
        )
 
84
 
 
85
    @patch.object(testcase, 'get_test_timeout', new=lambda: 0)
 
86
    def test_untimed_run_test_does_not_time_out(self):
 
87
        class TimedTest(testcase.AutopilotTestCase):
 
88
 
 
89
            def test_wont_timeout(self):
 
90
                time.sleep(10)
 
91
 
 
92
        test = TimedTest('test_wont_timeout')
 
93
        result = test.run()
 
94
        self.assertTrue(result.wasSuccessful())