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