testing/mozbase/mozdevice/sut_tests/test_getdir.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozdevice/sut_tests/test_getdir.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +import os
     1.9 +import posixpath
    1.10 +import shutil
    1.11 +import tempfile
    1.12 +
    1.13 +from mozdevice.devicemanager import DMError
    1.14 +from dmunit import DeviceManagerTestCase
    1.15 +
    1.16 +class GetDirectoryTestCase(DeviceManagerTestCase):
    1.17 +
    1.18 +    def _setUp(self):
    1.19 +        self.localsrcdir = tempfile.mkdtemp()
    1.20 +        os.makedirs(os.path.join(self.localsrcdir, 'push1', 'sub.1', 'sub.2'))
    1.21 +        path = os.path.join(self.localsrcdir,
    1.22 +                            'push1', 'sub.1', 'sub.2', 'testfile')
    1.23 +        file(path, 'w').close()
    1.24 +        os.makedirs(os.path.join(self.localsrcdir, 'push1', 'emptysub'))
    1.25 +        self.localdestdir = tempfile.mkdtemp()
    1.26 +        self.expected_filelist = ['emptysub', 'sub.1']
    1.27 +
    1.28 +    def tearDown(self):
    1.29 +        shutil.rmtree(self.localsrcdir)
    1.30 +        shutil.rmtree(self.localdestdir)
    1.31 +
    1.32 +    def runTest(self):
    1.33 +        """This tests the getDirectory() function.
    1.34 +        """
    1.35 +        testroot = posixpath.join(self.dm.getDeviceRoot(), 'infratest')
    1.36 +        self.dm.removeDir(testroot)
    1.37 +        self.dm.mkDir(testroot)
    1.38 +        self.dm.pushDir(
    1.39 +            os.path.join(self.localsrcdir, 'push1'),
    1.40 +            posixpath.join(testroot, 'push1'))
    1.41 +        # pushDir doesn't copy over empty directories, but we want to make sure
    1.42 +        # that they are retrieved correctly.
    1.43 +        self.dm.mkDir(posixpath.join(testroot, 'push1', 'emptysub'))
    1.44 +        self.dm.getDirectory(posixpath.join(testroot, 'push1'),
    1.45 +                             os.path.join(self.localdestdir, 'push1'))
    1.46 +        self.assertTrue(os.path.exists(
    1.47 +            os.path.join(self.localdestdir,
    1.48 +                         'push1', 'sub.1', 'sub.2', 'testfile')))
    1.49 +        self.assertTrue(os.path.exists(
    1.50 +            os.path.join(self.localdestdir, 'push1', 'emptysub')))
    1.51 +        self.assertRaises(DMError, self.dm.getDirectory,
    1.52 +                '/dummy', os.path.join(self.localdestdir, '/none'))
    1.53 +        self.assertFalse(os.path.exists(self.localdestdir + '/none'))

mercurial