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