1
# Ubuntu Test Cases for Touch
2
# Copyright 2013 Canonical Ltd.
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
16
from __future__ import print_function
24
class TestRebootAndWait(unittest.TestCase):
26
"""Simple set of tests to make sure the reboot-and-wait command works."""
29
# do some trickery to load this as module
30
module = 'reboot-and-wait'
31
fname = os.path.join(os.path.dirname(__file__), '../scripts', module)
32
m = imp.load_source(module, fname)
34
self._get_parser = m._get_arg_parser
36
@mock.patch('phabletutils.device.AndroidBridge.reboot')
37
def testRebootFail(self, reboot):
38
reboot.side_effect = RuntimeError('foo')
39
args = self._get_parser().parse_args([])
40
with self.assertRaisesRegexp(RuntimeError, 'foo'):
43
@mock.patch('phabletutils.device.AndroidBridge.reboot')
44
@mock.patch('phabletutils.device.AndroidBridge.wait_for_device')
45
def testWaitForDeviceFail(self, wait_for, reboot):
46
wait_for.side_effect = RuntimeError('foo')
47
args = self._get_parser().parse_args([])
48
with self.assertRaisesRegexp(RuntimeError, 'foo'):
50
reboot.assert_called_once_with()
52
@mock.patch('phabletutils.device.AndroidBridge.reboot')
53
@mock.patch('phabletutils.device.AndroidBridge.wait_for_device')
54
@mock.patch('phabletutils.device.AndroidBridge.wait_for_network')
55
def testRetries(self, wait_for_net, wait_for_dev, reboot):
56
args = self._get_parser().parse_args([])
57
wait_for_net.side_effect = RuntimeError('foo')
58
self.assertEquals(1, self._main(args))
59
self.assertEquals(args.num_tries, reboot.call_count)
61
# now make sure it can recover after a single network failure
63
wait_for_net.reset_mock()
64
wait_for_net.side_effect = [RuntimeError('foo'), None]
65
self.assertEquals(0, self._main(args))
66
self.assertEquals(2, reboot.call_count)