tor-browser

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

test.py (1733B)


      1 #!/usr/bin/env python
      2 
      3 import os
      4 
      5 import mozunit
      6 import pytest
      7 from mozdebug.mozdebug import (
      8    _DEBUGGER_PRIORITIES,
      9    DebuggerSearch,
     10    get_default_debugger_name,
     11 )
     12 
     13 here = os.path.abspath(os.path.dirname(__file__))
     14 
     15 
     16 @pytest.fixture
     17 def set_debuggers(monkeypatch):
     18    debugger_dir = os.path.join(here, "fake_debuggers")
     19 
     20    def _set_debuggers(*debuggers):
     21        dirs = []
     22        for d in debuggers:
     23            if d.endswith(".exe"):
     24                d = d[: -len(".exe")]
     25            dirs.append(os.path.join(debugger_dir, d))
     26        monkeypatch.setenv("PATH", os.pathsep.join(dirs))
     27 
     28    return _set_debuggers
     29 
     30 
     31 @pytest.mark.parametrize("os_name", ["android", "linux", "mac", "win", "unknown"])
     32 def test_default_debugger_name(os_name, set_debuggers, monkeypatch):
     33    import sys
     34 
     35    import mozinfo
     36 
     37    def update_os_name(*args, **kwargs):
     38        mozinfo.info["os"] = os_name
     39 
     40    monkeypatch.setattr(mozinfo, "find_and_update_from_json", update_os_name)
     41 
     42    if sys.platform == "win32":
     43        # This is used so distutils.spawn.find_executable doesn't add '.exe'
     44        # suffixes to all our dummy binaries on Windows.
     45        monkeypatch.setattr(sys, "platform", "linux")
     46 
     47    debuggers = _DEBUGGER_PRIORITIES[os_name][:]
     48    debuggers.reverse()
     49    first = True
     50    while len(debuggers) > 0:
     51        set_debuggers(*debuggers)
     52 
     53        if first:
     54            assert get_default_debugger_name() == debuggers[-1]
     55            first = False
     56        else:
     57            assert get_default_debugger_name() is None
     58            assert (
     59                get_default_debugger_name(DebuggerSearch.KeepLooking) == debuggers[-1]
     60            )
     61        debuggers = debuggers[:-1]
     62 
     63 
     64 if __name__ == "__main__":
     65    mozunit.main()