File: test.py

package info (click to toggle)
mozjs128 128.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,132,528 kB
  • sloc: javascript: 2,181,430; cpp: 1,371,420; python: 776,651; ansic: 641,398; xml: 117,736; sh: 17,537; asm: 13,468; makefile: 11,191; yacc: 4,504; perl: 2,221; lex: 1,414; ruby: 1,032; exp: 756; java: 185; sql: 66; sed: 18
file content (65 lines) | stat: -rw-r--r-- 1,733 bytes parent folder | download | duplicates (19)
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
#!/usr/bin/env python

import os

import mozunit
import pytest
from mozdebug.mozdebug import (
    _DEBUGGER_PRIORITIES,
    DebuggerSearch,
    get_default_debugger_name,
)

here = os.path.abspath(os.path.dirname(__file__))


@pytest.fixture
def set_debuggers(monkeypatch):
    debugger_dir = os.path.join(here, "fake_debuggers")

    def _set_debuggers(*debuggers):
        dirs = []
        for d in debuggers:
            if d.endswith(".exe"):
                d = d[: -len(".exe")]
            dirs.append(os.path.join(debugger_dir, d))
        monkeypatch.setenv("PATH", os.pathsep.join(dirs))

    return _set_debuggers


@pytest.mark.parametrize("os_name", ["android", "linux", "mac", "win", "unknown"])
def test_default_debugger_name(os_name, set_debuggers, monkeypatch):
    import sys

    import mozinfo

    def update_os_name(*args, **kwargs):
        mozinfo.info["os"] = os_name

    monkeypatch.setattr(mozinfo, "find_and_update_from_json", update_os_name)

    if sys.platform == "win32":
        # This is used so distutils.spawn.find_executable doesn't add '.exe'
        # suffixes to all our dummy binaries on Windows.
        monkeypatch.setattr(sys, "platform", "linux")

    debuggers = _DEBUGGER_PRIORITIES[os_name][:]
    debuggers.reverse()
    first = True
    while len(debuggers) > 0:
        set_debuggers(*debuggers)

        if first:
            assert get_default_debugger_name() == debuggers[-1]
            first = False
        else:
            assert get_default_debugger_name() is None
            assert (
                get_default_debugger_name(DebuggerSearch.KeepLooking) == debuggers[-1]
            )
        debuggers = debuggers[:-1]


if __name__ == "__main__":
    mozunit.main()