testing/mozbase/mozdevice/tests/sut_mkdir.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozdevice/tests/sut_mkdir.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +# Any copyright is dedicated to the Public Domain.
     1.5 +# http://creativecommons.org/publicdomain/zero/1.0/
     1.6 +
     1.7 +import mozdevice
     1.8 +import mozlog
     1.9 +import unittest
    1.10 +from sut import MockAgent
    1.11 +
    1.12 +class MkDirsTest(unittest.TestCase):
    1.13 +
    1.14 +    def test_mkdirs(self):
    1.15 +        subTests = [{'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'),
    1.16 +                              ('isdir /mnt', 'TRUE'),
    1.17 +                              ('isdir /mnt/sdcard', 'TRUE'),
    1.18 +                              ('isdir /mnt/sdcard/baz', 'FALSE'),
    1.19 +                              ('mkdr /mnt/sdcard/baz',
    1.20 +                               '/mnt/sdcard/baz successfully created'),
    1.21 +                              ('isdir /mnt/sdcard/baz/boop', 'FALSE'),
    1.22 +                              ('mkdr /mnt/sdcard/baz/boop',
    1.23 +                               '/mnt/sdcard/baz/boop successfully created')],
    1.24 +                     'expectException': False},
    1.25 +                    {'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'),
    1.26 +                              ('isdir /mnt', 'TRUE'),
    1.27 +                              ('isdir /mnt/sdcard', 'TRUE'),
    1.28 +                              ('isdir /mnt/sdcard/baz', 'FALSE'),
    1.29 +                              ('mkdr /mnt/sdcard/baz',
    1.30 +                               '##AGENT-WARNING## Could not create the directory /mnt/sdcard/baz')],
    1.31 +                     'expectException': True},
    1.32 +                     ]
    1.33 +        for subTest in subTests:
    1.34 +            a = MockAgent(self, commands=subTest['cmds'])
    1.35 +
    1.36 +            exceptionThrown = False
    1.37 +            try:
    1.38 +                d = mozdevice.DroidSUT('127.0.0.1', port=a.port,
    1.39 +                                       logLevel=mozlog.DEBUG)
    1.40 +                d.mkDirs('/mnt/sdcard/baz/boop/bip')
    1.41 +            except mozdevice.DMError:
    1.42 +                exceptionThrown = True
    1.43 +            self.assertEqual(exceptionThrown, subTest['expectException'])
    1.44 +
    1.45 +            a.wait()
    1.46 +
    1.47 +    def test_repeated_path_part(self):
    1.48 +        """
    1.49 +        Ensure that all dirs are created when last path part also found
    1.50 +        earlier in the path (bug 826492).
    1.51 +        """
    1.52 +
    1.53 +        cmds = [('isdir /mnt/sdcard/foo', 'FALSE'),
    1.54 +                ('isdir /mnt', 'TRUE'),
    1.55 +                ('isdir /mnt/sdcard', 'TRUE'),
    1.56 +                ('isdir /mnt/sdcard/foo', 'FALSE'),
    1.57 +                ('mkdr /mnt/sdcard/foo',
    1.58 +                 '/mnt/sdcard/foo successfully created')]
    1.59 +        a = MockAgent(self, commands=cmds)
    1.60 +        d = mozdevice.DroidSUT('127.0.0.1', port=a.port,
    1.61 +                               logLevel=mozlog.DEBUG)
    1.62 +        d.mkDirs('/mnt/sdcard/foo/foo')
    1.63 +        a.wait()
    1.64 +
    1.65 +    def test_mkdirs_on_root(self):
    1.66 +        cmds = [('isdir /', 'TRUE')]
    1.67 +        a = MockAgent(self, commands=cmds)
    1.68 +        d = mozdevice.DroidSUT('127.0.0.1', port=a.port,
    1.69 +                               logLevel=mozlog.DEBUG)
    1.70 +        d.mkDirs('/foo')
    1.71 +
    1.72 +        a.wait()
    1.73 +
    1.74 +
    1.75 +if __name__ == '__main__':
    1.76 +    unittest.main()

mercurial