testing/mozbase/mozdevice/sut_tests/test_getdir.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 import os
michael@0 6 import posixpath
michael@0 7 import shutil
michael@0 8 import tempfile
michael@0 9
michael@0 10 from mozdevice.devicemanager import DMError
michael@0 11 from dmunit import DeviceManagerTestCase
michael@0 12
michael@0 13 class GetDirectoryTestCase(DeviceManagerTestCase):
michael@0 14
michael@0 15 def _setUp(self):
michael@0 16 self.localsrcdir = tempfile.mkdtemp()
michael@0 17 os.makedirs(os.path.join(self.localsrcdir, 'push1', 'sub.1', 'sub.2'))
michael@0 18 path = os.path.join(self.localsrcdir,
michael@0 19 'push1', 'sub.1', 'sub.2', 'testfile')
michael@0 20 file(path, 'w').close()
michael@0 21 os.makedirs(os.path.join(self.localsrcdir, 'push1', 'emptysub'))
michael@0 22 self.localdestdir = tempfile.mkdtemp()
michael@0 23 self.expected_filelist = ['emptysub', 'sub.1']
michael@0 24
michael@0 25 def tearDown(self):
michael@0 26 shutil.rmtree(self.localsrcdir)
michael@0 27 shutil.rmtree(self.localdestdir)
michael@0 28
michael@0 29 def runTest(self):
michael@0 30 """This tests the getDirectory() function.
michael@0 31 """
michael@0 32 testroot = posixpath.join(self.dm.getDeviceRoot(), 'infratest')
michael@0 33 self.dm.removeDir(testroot)
michael@0 34 self.dm.mkDir(testroot)
michael@0 35 self.dm.pushDir(
michael@0 36 os.path.join(self.localsrcdir, 'push1'),
michael@0 37 posixpath.join(testroot, 'push1'))
michael@0 38 # pushDir doesn't copy over empty directories, but we want to make sure
michael@0 39 # that they are retrieved correctly.
michael@0 40 self.dm.mkDir(posixpath.join(testroot, 'push1', 'emptysub'))
michael@0 41 self.dm.getDirectory(posixpath.join(testroot, 'push1'),
michael@0 42 os.path.join(self.localdestdir, 'push1'))
michael@0 43 self.assertTrue(os.path.exists(
michael@0 44 os.path.join(self.localdestdir,
michael@0 45 'push1', 'sub.1', 'sub.2', 'testfile')))
michael@0 46 self.assertTrue(os.path.exists(
michael@0 47 os.path.join(self.localdestdir, 'push1', 'emptysub')))
michael@0 48 self.assertRaises(DMError, self.dm.getDirectory,
michael@0 49 '/dummy', os.path.join(self.localdestdir, '/none'))
michael@0 50 self.assertFalse(os.path.exists(self.localdestdir + '/none'))

mercurial