testing/mozbase/mozprofile/tests/test_clone_cleanup.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozprofile/tests/test_clone_cleanup.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 +# You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +
    1.11 +import os
    1.12 +import tempfile
    1.13 +import unittest
    1.14 +
    1.15 +from mozprofile.profile import Profile
    1.16 +
    1.17 +
    1.18 +class CloneCleanupTest(unittest.TestCase):
    1.19 +    """
    1.20 +    test cleanup logic for the clone functionality
    1.21 +    see https://bugzilla.mozilla.org/show_bug.cgi?id=642843
    1.22 +    """
    1.23 +
    1.24 +    def setUp(self):
    1.25 +        # make a profile with one preference
    1.26 +        path = tempfile.mktemp()
    1.27 +        self.profile = Profile(path,
    1.28 +                          preferences={'foo': 'bar'},
    1.29 +                          restore=False)
    1.30 +        user_js = os.path.join(self.profile.profile, 'user.js')
    1.31 +        self.assertTrue(os.path.exists(user_js))
    1.32 +
    1.33 +    def test_restore_true(self):
    1.34 +        # make a clone of this profile with restore=True
    1.35 +        clone = Profile.clone(self.profile.profile, restore=True)
    1.36 +
    1.37 +        clone.cleanup()
    1.38 +
    1.39 +        # clone should be deleted
    1.40 +        self.assertFalse(os.path.exists(clone.profile))
    1.41 +
    1.42 +    def test_restore_false(self):
    1.43 +        # make a clone of this profile with restore=False
    1.44 +        clone = Profile.clone(self.profile.profile, restore=False)
    1.45 +
    1.46 +        clone.cleanup()
    1.47 +
    1.48 +        # clone should still be around on the filesystem
    1.49 +        self.assertTrue(os.path.exists(clone.profile))
    1.50 +
    1.51 +
    1.52 +if __name__ == '__main__':
    1.53 +    unittest.main()
    1.54 +

mercurial