File: test_bootstrap.py

package info (click to toggle)
mozjs78 78.15.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 739,892 kB
  • sloc: javascript: 1,344,214; cpp: 1,215,708; python: 526,544; ansic: 433,835; xml: 118,736; sh: 26,176; asm: 16,664; makefile: 11,537; yacc: 4,486; perl: 2,564; ada: 1,681; lex: 1,414; pascal: 1,139; cs: 879; exp: 499; java: 164; ruby: 68; sql: 45; csh: 35; sed: 18; lisp: 2
file content (87 lines) | stat: -rw-r--r-- 2,691 bytes parent folder | download | duplicates (6)
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
76
77
78
79
80
81
82
83
84
85
86
87
from __future__ import absolute_import, unicode_literals

import inspect
import os
import re
import subprocess
import sys
import textwrap

import six

import virtualenv


def bootstrap():
    print("startup")
    import subprocess
    import os

    # noinspection PyUnusedLocal
    def extend_parser(opt_parse_parser):
        print("extend parser with count")
        opt_parse_parser.add_option("-c", action="count", dest="count", default=0, help="Count number of times passed")

    # noinspection PyUnusedLocal
    def adjust_options(options, args):
        print("adjust options")
        options.count += 1

    # noinspection PyUnusedLocal
    def after_install(options, home_dir):
        print("after install {} with options {}".format(home_dir, options.count))
        # noinspection PyUnresolvedReferences
        _, _, _, bin_dir = path_locations(home_dir)  # noqa: F821
        # noinspection PyUnresolvedReferences
        print(
            "exe at {}".format(
                subprocess.check_output(
                    [os.path.join(bin_dir, EXPECTED_EXE), "-c", "import sys; print(sys.executable)"],  # noqa: F821
                    universal_newlines=True,
                )
            )
        )


def test_bootstrap(tmp_path, monkeypatch):
    monkeypatch.chdir(tmp_path)

    extra_code = inspect.getsource(bootstrap)
    extra_code = textwrap.dedent(extra_code[extra_code.index("\n") + 1 :])

    output = virtualenv.create_bootstrap_script(extra_code)
    assert extra_code in output
    if six.PY2:
        output = output.decode()
    write_at = tmp_path / "blog-bootstrap.py"
    write_at.write_text(output)

    try:
        monkeypatch.chdir(tmp_path)
        cmd = [
            sys.executable,
            str(write_at),
            "--no-download",
            "--no-pip",
            "--no-wheel",
            "--no-setuptools",
            "-ccc",
            "-qqq",
            "env",
        ]
        raw = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT)
        out = re.sub(r"pydev debugger: process \d+ is connecting\n\n", "", raw, re.M).strip().split("\n")

        _, _, _, bin_dir = virtualenv.path_locations(str(tmp_path / "env"))
        exe = os.path.realpath(
            os.path.join(bin_dir, "{}{}".format(virtualenv.EXPECTED_EXE, ".exe" if virtualenv.IS_WIN else ""))
        )
        assert out == [
            "startup",
            "extend parser with count",
            "adjust options",
            "after install env with options 4",
            "exe at {}".format(exe),
        ]
    except subprocess.CalledProcessError as exception:
        assert not exception.returncode, exception.output