1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozdevice/tests/sut_copytree.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +#!/usr/bin/env python 1.5 +# -*- coding: utf-8 -*- 1.6 + 1.7 +# This Source Code Form is subject to the terms of the Mozilla Public 1.8 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.9 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.10 + 1.11 +import mozdevice 1.12 +import mozlog 1.13 +import unittest 1.14 +from sut import MockAgent 1.15 + 1.16 +class CopyTreeTest(unittest.TestCase): 1.17 + def test_copyFile(self): 1.18 + commands = [('dd if=/mnt/sdcard/tests/test.txt of=/mnt/sdcard/tests/test2.txt', ''), 1.19 + ('isdir /mnt/sdcard/tests', 'TRUE'), 1.20 + ('cd /mnt/sdcard/tests', ''), 1.21 + ('ls', 'test.txt\ntest2.txt')] 1.22 + 1.23 + m = MockAgent(self, commands=commands) 1.24 + d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) 1.25 + 1.26 + self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/test.txt', 1.27 + '/mnt/sdcard/tests/test2.txt')) 1.28 + expected = (commands[3][1].strip()).split('\n') 1.29 + self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests')) 1.30 + 1.31 + def test_copyDir(self): 1.32 + commands = [('dd if=/mnt/sdcard/tests/foo of=/mnt/sdcard/tests/bar', ''), 1.33 + ('isdir /mnt/sdcard/tests', 'TRUE'), 1.34 + ('cd /mnt/sdcard/tests', ''), 1.35 + ('ls', 'foo\nbar')] 1.36 + 1.37 + m = MockAgent(self, commands=commands) 1.38 + d = mozdevice.DroidSUT("127.0.0.1", port=m.port, 1.39 + logLevel=mozlog.DEBUG) 1.40 + 1.41 + self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/foo', 1.42 + '/mnt/sdcard/tests/bar')) 1.43 + expected = (commands[3][1].strip()).split('\n') 1.44 + self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests')) 1.45 + 1.46 + def test_copyNonEmptyDir(self): 1.47 + commands = [('isdir /mnt/sdcard/tests/foo/bar', 'TRUE'), 1.48 + ('dd if=/mnt/sdcard/tests/foo of=/mnt/sdcard/tests/foo2', ''), 1.49 + ('isdir /mnt/sdcard/tests', 'TRUE'), 1.50 + ('cd /mnt/sdcard/tests', ''), 1.51 + ('ls', 'foo\nfoo2'), 1.52 + ('isdir /mnt/sdcard/tests/foo2', 'TRUE'), 1.53 + ('cd /mnt/sdcard/tests/foo2', ''), 1.54 + ('ls', 'bar')] 1.55 + 1.56 + m = MockAgent(self, commands=commands) 1.57 + d = mozdevice.DroidSUT("127.0.0.1", port=m.port, 1.58 + logLevel=mozlog.DEBUG) 1.59 + 1.60 + self.assertTrue(d.dirExists('/mnt/sdcard/tests/foo/bar')) 1.61 + self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/foo', 1.62 + '/mnt/sdcard/tests/foo2')) 1.63 + expected = (commands[4][1].strip()).split('\n') 1.64 + self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests')) 1.65 + self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2/bar')) 1.66 + 1.67 +if __name__ == "__main__": 1.68 + unittest.main()