1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozprofile/tests/test_profile_view.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 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 +import mozfile 1.11 +import mozprofile 1.12 +import os 1.13 +import tempfile 1.14 +import unittest 1.15 + 1.16 +here = os.path.dirname(os.path.abspath(__file__)) 1.17 + 1.18 +class TestProfilePrint(unittest.TestCase): 1.19 + 1.20 + def test_profileprint(self): 1.21 + """ 1.22 + test the summary function 1.23 + """ 1.24 + 1.25 + keys = set(['Files', 'Path', 'user.js']) 1.26 + ff_prefs = mozprofile.FirefoxProfile.preferences # shorthand 1.27 + pref_string = '\n'.join(['%s: %s' % (key, ff_prefs[key]) 1.28 + for key in sorted(ff_prefs.keys())]) 1.29 + 1.30 + tempdir = tempfile.mkdtemp() 1.31 + try: 1.32 + profile = mozprofile.FirefoxProfile(tempdir) 1.33 + parts = profile.summary(return_parts=True) 1.34 + parts = dict(parts) 1.35 + 1.36 + self.assertEqual(parts['Path'], tempdir) 1.37 + self.assertEqual(set(parts.keys()), keys) 1.38 + self.assertEqual(pref_string, parts['user.js'].strip()) 1.39 + 1.40 + except: 1.41 + raise 1.42 + finally: 1.43 + mozfile.rmtree(tempdir) 1.44 + 1.45 + def test_strcast(self): 1.46 + """ 1.47 + test casting to a string 1.48 + """ 1.49 + 1.50 + profile = mozprofile.Profile() 1.51 + self.assertEqual(str(profile), profile.summary()) 1.52 + 1.53 + def test_profile_diff(self): 1.54 + profile1 = mozprofile.Profile() 1.55 + profile2 = mozprofile.Profile(preferences=dict(foo='bar')) 1.56 + 1.57 + # diff a profile against itself; no difference 1.58 + self.assertEqual([], mozprofile.diff(profile1, profile1)) 1.59 + 1.60 + # diff two profiles 1.61 + diff = dict(mozprofile.diff(profile1, profile2)) 1.62 + self.assertEqual(diff.keys(), ['user.js']) 1.63 + lines = [line.strip() for line in diff['user.js'].splitlines()] 1.64 + self.assertTrue('+foo: bar' in lines) 1.65 + 1.66 + # diff a blank vs FirefoxProfile 1.67 + ff_profile = mozprofile.FirefoxProfile() 1.68 + diff = dict(mozprofile.diff(profile2, ff_profile)) 1.69 + self.assertEqual(diff.keys(), ['user.js']) 1.70 + lines = [line.strip() for line in diff['user.js'].splitlines()] 1.71 + self.assertTrue('-foo: bar' in lines) 1.72 + ff_pref_lines = ['+%s: %s' % (key, value) 1.73 + for key, value in mozprofile.FirefoxProfile.preferences.items()] 1.74 + self.assertTrue(set(ff_pref_lines).issubset(lines)) 1.75 + 1.76 +if __name__ == '__main__': 1.77 + unittest.main()