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.

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

mercurial