|
1 # Any copyright is dedicated to the Public Domain. |
|
2 # http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 |
|
4 import mozdevice |
|
5 import mozlog |
|
6 import unittest |
|
7 from sut import MockAgent |
|
8 |
|
9 class MkDirsTest(unittest.TestCase): |
|
10 |
|
11 def test_mkdirs(self): |
|
12 subTests = [{'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'), |
|
13 ('isdir /mnt', 'TRUE'), |
|
14 ('isdir /mnt/sdcard', 'TRUE'), |
|
15 ('isdir /mnt/sdcard/baz', 'FALSE'), |
|
16 ('mkdr /mnt/sdcard/baz', |
|
17 '/mnt/sdcard/baz successfully created'), |
|
18 ('isdir /mnt/sdcard/baz/boop', 'FALSE'), |
|
19 ('mkdr /mnt/sdcard/baz/boop', |
|
20 '/mnt/sdcard/baz/boop successfully created')], |
|
21 'expectException': False}, |
|
22 {'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'), |
|
23 ('isdir /mnt', 'TRUE'), |
|
24 ('isdir /mnt/sdcard', 'TRUE'), |
|
25 ('isdir /mnt/sdcard/baz', 'FALSE'), |
|
26 ('mkdr /mnt/sdcard/baz', |
|
27 '##AGENT-WARNING## Could not create the directory /mnt/sdcard/baz')], |
|
28 'expectException': True}, |
|
29 ] |
|
30 for subTest in subTests: |
|
31 a = MockAgent(self, commands=subTest['cmds']) |
|
32 |
|
33 exceptionThrown = False |
|
34 try: |
|
35 d = mozdevice.DroidSUT('127.0.0.1', port=a.port, |
|
36 logLevel=mozlog.DEBUG) |
|
37 d.mkDirs('/mnt/sdcard/baz/boop/bip') |
|
38 except mozdevice.DMError: |
|
39 exceptionThrown = True |
|
40 self.assertEqual(exceptionThrown, subTest['expectException']) |
|
41 |
|
42 a.wait() |
|
43 |
|
44 def test_repeated_path_part(self): |
|
45 """ |
|
46 Ensure that all dirs are created when last path part also found |
|
47 earlier in the path (bug 826492). |
|
48 """ |
|
49 |
|
50 cmds = [('isdir /mnt/sdcard/foo', 'FALSE'), |
|
51 ('isdir /mnt', 'TRUE'), |
|
52 ('isdir /mnt/sdcard', 'TRUE'), |
|
53 ('isdir /mnt/sdcard/foo', 'FALSE'), |
|
54 ('mkdr /mnt/sdcard/foo', |
|
55 '/mnt/sdcard/foo successfully created')] |
|
56 a = MockAgent(self, commands=cmds) |
|
57 d = mozdevice.DroidSUT('127.0.0.1', port=a.port, |
|
58 logLevel=mozlog.DEBUG) |
|
59 d.mkDirs('/mnt/sdcard/foo/foo') |
|
60 a.wait() |
|
61 |
|
62 def test_mkdirs_on_root(self): |
|
63 cmds = [('isdir /', 'TRUE')] |
|
64 a = MockAgent(self, commands=cmds) |
|
65 d = mozdevice.DroidSUT('127.0.0.1', port=a.port, |
|
66 logLevel=mozlog.DEBUG) |
|
67 d.mkDirs('/foo') |
|
68 |
|
69 a.wait() |
|
70 |
|
71 |
|
72 if __name__ == '__main__': |
|
73 unittest.main() |