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 tempfile michael@0: import posixpath michael@0: michael@0: from dmunit import DeviceManagerTestCase michael@0: michael@0: class FileExistsTestCase(DeviceManagerTestCase): michael@0: """This tests the "fileExists" command. michael@0: """ michael@0: michael@0: def testOnRoot(self): michael@0: self.assertTrue(self.dm.fileExists('/')) michael@0: michael@0: def testOnNonexistent(self): michael@0: self.assertFalse(self.dm.fileExists('/doesNotExist')) michael@0: michael@0: def testOnRegularFile(self): michael@0: remote_path = posixpath.join(self.dm.getDeviceRoot(), 'testFile') michael@0: self.assertFalse(self.dm.fileExists(remote_path)) michael@0: with tempfile.NamedTemporaryFile() as f: michael@0: self.dm.pushFile(f.name, remote_path) michael@0: self.assertTrue(self.dm.fileExists(remote_path)) michael@0: self.dm.removeFile(remote_path) michael@0: michael@0: def testOnDirectory(self): michael@0: remote_path = posixpath.join(self.dm.getDeviceRoot(), 'testDir') michael@0: remote_path_file = posixpath.join(remote_path, 'testFile') michael@0: self.assertFalse(self.dm.fileExists(remote_path)) michael@0: with tempfile.NamedTemporaryFile() as f: michael@0: self.dm.pushFile(f.name, remote_path_file) michael@0: self.assertTrue(self.dm.fileExists(remote_path)) michael@0: self.dm.removeFile(remote_path_file) michael@0: self.dm.removeDir(remote_path) michael@0: