testing/mozbase/mozprofile/tests/test_profile_view.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2
michael@0 3 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 # You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 6
michael@0 7 import mozfile
michael@0 8 import mozprofile
michael@0 9 import os
michael@0 10 import tempfile
michael@0 11 import unittest
michael@0 12
michael@0 13 here = os.path.dirname(os.path.abspath(__file__))
michael@0 14
michael@0 15 class TestProfilePrint(unittest.TestCase):
michael@0 16
michael@0 17 def test_profileprint(self):
michael@0 18 """
michael@0 19 test the summary function
michael@0 20 """
michael@0 21
michael@0 22 keys = set(['Files', 'Path', 'user.js'])
michael@0 23 ff_prefs = mozprofile.FirefoxProfile.preferences # shorthand
michael@0 24 pref_string = '\n'.join(['%s: %s' % (key, ff_prefs[key])
michael@0 25 for key in sorted(ff_prefs.keys())])
michael@0 26
michael@0 27 tempdir = tempfile.mkdtemp()
michael@0 28 try:
michael@0 29 profile = mozprofile.FirefoxProfile(tempdir)
michael@0 30 parts = profile.summary(return_parts=True)
michael@0 31 parts = dict(parts)
michael@0 32
michael@0 33 self.assertEqual(parts['Path'], tempdir)
michael@0 34 self.assertEqual(set(parts.keys()), keys)
michael@0 35 self.assertEqual(pref_string, parts['user.js'].strip())
michael@0 36
michael@0 37 except:
michael@0 38 raise
michael@0 39 finally:
michael@0 40 mozfile.rmtree(tempdir)
michael@0 41
michael@0 42 def test_strcast(self):
michael@0 43 """
michael@0 44 test casting to a string
michael@0 45 """
michael@0 46
michael@0 47 profile = mozprofile.Profile()
michael@0 48 self.assertEqual(str(profile), profile.summary())
michael@0 49
michael@0 50 def test_profile_diff(self):
michael@0 51 profile1 = mozprofile.Profile()
michael@0 52 profile2 = mozprofile.Profile(preferences=dict(foo='bar'))
michael@0 53
michael@0 54 # diff a profile against itself; no difference
michael@0 55 self.assertEqual([], mozprofile.diff(profile1, profile1))
michael@0 56
michael@0 57 # diff two profiles
michael@0 58 diff = dict(mozprofile.diff(profile1, profile2))
michael@0 59 self.assertEqual(diff.keys(), ['user.js'])
michael@0 60 lines = [line.strip() for line in diff['user.js'].splitlines()]
michael@0 61 self.assertTrue('+foo: bar' in lines)
michael@0 62
michael@0 63 # diff a blank vs FirefoxProfile
michael@0 64 ff_profile = mozprofile.FirefoxProfile()
michael@0 65 diff = dict(mozprofile.diff(profile2, ff_profile))
michael@0 66 self.assertEqual(diff.keys(), ['user.js'])
michael@0 67 lines = [line.strip() for line in diff['user.js'].splitlines()]
michael@0 68 self.assertTrue('-foo: bar' in lines)
michael@0 69 ff_pref_lines = ['+%s: %s' % (key, value)
michael@0 70 for key, value in mozprofile.FirefoxProfile.preferences.items()]
michael@0 71 self.assertTrue(set(ff_pref_lines).issubset(lines))
michael@0 72
michael@0 73 if __name__ == '__main__':
michael@0 74 unittest.main()

mercurial