Debian Codegraph @

testing/mozbase/mozprofile/tests/test_profile_view.py

raw
1 #!/usr/bin/env python
2
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/.
6
7 import os
8 import sys
9
10 import mozprofile
11 import mozunit
12 import pytest
13 from six import text_type
14
15 here = os.path.dirname(os.path.abspath(__file__))
16
17
18 def test_profileprint(tmpdir):
19 """Test the summary function."""
20 keys = set(["Files", "Path"])
21
22 tmpdir = tmpdir.strpath
23 profile = mozprofile.FirefoxProfile(tmpdir)
24 parts = profile.summary(return_parts=True)
25 parts = dict(parts)
26
27 assert parts["Path"] == tmpdir
28 assert set(parts.keys()) == keys
29
30
31 def test_str_cast():
32 """Test casting to a string."""
33 profile = mozprofile.Profile()
34 assert str(profile) == profile.summary()
35
36
37 @pytest.mark.skipif(
38 sys.version_info[0] >= 3, reason="no unicode() operator starting from python3"
39 )
40 def test_unicode_cast():
41 """Test casting to a unicode string."""
42 profile = mozprofile.Profile()
43 assert text_type(profile) == profile.summary()
44
45
46 def test_profile_diff():
47 profile1 = mozprofile.Profile()
48 profile2 = mozprofile.Profile(preferences=dict(foo="bar"))
49
50 # diff a profile against itself; no difference
51 assert mozprofile.diff(profile1, profile1) == []
52
53 # diff two profiles
54 diff = dict(mozprofile.diff(profile1, profile2))
55 assert list(diff.keys()) == ["user.js"]
56 lines = [line.strip() for line in diff["user.js"].splitlines()]
57 assert "+foo: bar" in lines
58
59 # diff a blank vs FirefoxProfile
60 ff_profile = mozprofile.FirefoxProfile()
61 diff = dict(mozprofile.diff(profile2, ff_profile))
62 assert list(diff.keys()) == ["user.js"]
63 lines = [line.strip() for line in diff["user.js"].splitlines()]
64 assert "-foo: bar" in lines
65 ff_pref_lines = [
66 "+%s: %s" % (key, value)
67 for key, value in mozprofile.FirefoxProfile.preferences.items()
68 ]
69 assert set(ff_pref_lines).issubset(lines)
70
71
72 if __name__ == "__main__":
73 mozunit.main()