michael@0: # Any copyright is dedicated to the Public Domain. michael@0: # http://creativecommons.org/publicdomain/zero/1.0/ michael@0: michael@0: import mozdevice michael@0: import mozlog michael@0: import unittest michael@0: from sut import MockAgent michael@0: michael@0: class MkDirsTest(unittest.TestCase): michael@0: michael@0: def test_mkdirs(self): michael@0: subTests = [{'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'), michael@0: ('isdir /mnt', 'TRUE'), michael@0: ('isdir /mnt/sdcard', 'TRUE'), michael@0: ('isdir /mnt/sdcard/baz', 'FALSE'), michael@0: ('mkdr /mnt/sdcard/baz', michael@0: '/mnt/sdcard/baz successfully created'), michael@0: ('isdir /mnt/sdcard/baz/boop', 'FALSE'), michael@0: ('mkdr /mnt/sdcard/baz/boop', michael@0: '/mnt/sdcard/baz/boop successfully created')], michael@0: 'expectException': False}, michael@0: {'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'), michael@0: ('isdir /mnt', 'TRUE'), michael@0: ('isdir /mnt/sdcard', 'TRUE'), michael@0: ('isdir /mnt/sdcard/baz', 'FALSE'), michael@0: ('mkdr /mnt/sdcard/baz', michael@0: '##AGENT-WARNING## Could not create the directory /mnt/sdcard/baz')], michael@0: 'expectException': True}, michael@0: ] michael@0: for subTest in subTests: michael@0: a = MockAgent(self, commands=subTest['cmds']) michael@0: michael@0: exceptionThrown = False michael@0: try: michael@0: d = mozdevice.DroidSUT('127.0.0.1', port=a.port, michael@0: logLevel=mozlog.DEBUG) michael@0: d.mkDirs('/mnt/sdcard/baz/boop/bip') michael@0: except mozdevice.DMError: michael@0: exceptionThrown = True michael@0: self.assertEqual(exceptionThrown, subTest['expectException']) michael@0: michael@0: a.wait() michael@0: michael@0: def test_repeated_path_part(self): michael@0: """ michael@0: Ensure that all dirs are created when last path part also found michael@0: earlier in the path (bug 826492). michael@0: """ michael@0: michael@0: cmds = [('isdir /mnt/sdcard/foo', 'FALSE'), michael@0: ('isdir /mnt', 'TRUE'), michael@0: ('isdir /mnt/sdcard', 'TRUE'), michael@0: ('isdir /mnt/sdcard/foo', 'FALSE'), michael@0: ('mkdr /mnt/sdcard/foo', michael@0: '/mnt/sdcard/foo successfully created')] michael@0: a = MockAgent(self, commands=cmds) michael@0: d = mozdevice.DroidSUT('127.0.0.1', port=a.port, michael@0: logLevel=mozlog.DEBUG) michael@0: d.mkDirs('/mnt/sdcard/foo/foo') michael@0: a.wait() michael@0: michael@0: def test_mkdirs_on_root(self): michael@0: cmds = [('isdir /', 'TRUE')] michael@0: a = MockAgent(self, commands=cmds) michael@0: d = mozdevice.DroidSUT('127.0.0.1', port=a.port, michael@0: logLevel=mozlog.DEBUG) michael@0: d.mkDirs('/foo') michael@0: michael@0: a.wait() michael@0: michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()