tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_profile_view.py (2026B)


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