michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import os michael@0: import posixpath michael@0: import shutil michael@0: import tempfile michael@0: michael@0: from mozdevice.devicemanager import DMError michael@0: from dmunit import DeviceManagerTestCase michael@0: michael@0: class GetDirectoryTestCase(DeviceManagerTestCase): michael@0: michael@0: def _setUp(self): michael@0: self.localsrcdir = tempfile.mkdtemp() michael@0: os.makedirs(os.path.join(self.localsrcdir, 'push1', 'sub.1', 'sub.2')) michael@0: path = os.path.join(self.localsrcdir, michael@0: 'push1', 'sub.1', 'sub.2', 'testfile') michael@0: file(path, 'w').close() michael@0: os.makedirs(os.path.join(self.localsrcdir, 'push1', 'emptysub')) michael@0: self.localdestdir = tempfile.mkdtemp() michael@0: self.expected_filelist = ['emptysub', 'sub.1'] michael@0: michael@0: def tearDown(self): michael@0: shutil.rmtree(self.localsrcdir) michael@0: shutil.rmtree(self.localdestdir) michael@0: michael@0: def runTest(self): michael@0: """This tests the getDirectory() function. michael@0: """ michael@0: testroot = posixpath.join(self.dm.getDeviceRoot(), 'infratest') michael@0: self.dm.removeDir(testroot) michael@0: self.dm.mkDir(testroot) michael@0: self.dm.pushDir( michael@0: os.path.join(self.localsrcdir, 'push1'), michael@0: posixpath.join(testroot, 'push1')) michael@0: # pushDir doesn't copy over empty directories, but we want to make sure michael@0: # that they are retrieved correctly. michael@0: self.dm.mkDir(posixpath.join(testroot, 'push1', 'emptysub')) michael@0: self.dm.getDirectory(posixpath.join(testroot, 'push1'), michael@0: os.path.join(self.localdestdir, 'push1')) michael@0: self.assertTrue(os.path.exists( michael@0: os.path.join(self.localdestdir, michael@0: 'push1', 'sub.1', 'sub.2', 'testfile'))) michael@0: self.assertTrue(os.path.exists( michael@0: os.path.join(self.localdestdir, 'push1', 'emptysub'))) michael@0: self.assertRaises(DMError, self.dm.getDirectory, michael@0: '/dummy', os.path.join(self.localdestdir, '/none')) michael@0: self.assertFalse(os.path.exists(self.localdestdir + '/none'))