michael@0: #!/usr/bin/env python michael@0: 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 file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: michael@0: import os michael@0: import tempfile michael@0: import unittest michael@0: michael@0: from mozprofile.profile import Profile michael@0: michael@0: michael@0: class CloneCleanupTest(unittest.TestCase): michael@0: """ michael@0: test cleanup logic for the clone functionality michael@0: see https://bugzilla.mozilla.org/show_bug.cgi?id=642843 michael@0: """ michael@0: michael@0: def setUp(self): michael@0: # make a profile with one preference michael@0: path = tempfile.mktemp() michael@0: self.profile = Profile(path, michael@0: preferences={'foo': 'bar'}, michael@0: restore=False) michael@0: user_js = os.path.join(self.profile.profile, 'user.js') michael@0: self.assertTrue(os.path.exists(user_js)) michael@0: michael@0: def test_restore_true(self): michael@0: # make a clone of this profile with restore=True michael@0: clone = Profile.clone(self.profile.profile, restore=True) michael@0: michael@0: clone.cleanup() michael@0: michael@0: # clone should be deleted michael@0: self.assertFalse(os.path.exists(clone.profile)) michael@0: michael@0: def test_restore_false(self): michael@0: # make a clone of this profile with restore=False michael@0: clone = Profile.clone(self.profile.profile, restore=False) michael@0: michael@0: clone.cleanup() michael@0: michael@0: # clone should still be around on the filesystem michael@0: self.assertTrue(os.path.exists(clone.profile)) michael@0: michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main() michael@0: