File: test_installation.py

package info (click to toggle)
python-git 3.1.44-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,732 kB
  • sloc: python: 18,505; sh: 186; makefile: 78
file content (73 lines) | stat: -rw-r--r-- 2,322 bytes parent folder | download
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
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import ast
import os
import subprocess

from test.lib import TestBase, VirtualEnvironment, with_rw_directory


class TestInstallation(TestBase):
    @with_rw_directory
    def test_installation(self, rw_dir):
        venv = self._set_up_venv(rw_dir)

        result = subprocess.run(
            [venv.pip, "install", "."],
            stdout=subprocess.PIPE,
            cwd=venv.sources,
        )
        self.assertEqual(
            0,
            result.returncode,
            msg=result.stderr or result.stdout or "Can't install project",
        )

        result = subprocess.run(
            [venv.python, "-c", "import git"],
            stdout=subprocess.PIPE,
            cwd=venv.sources,
        )
        self.assertEqual(
            0,
            result.returncode,
            msg=result.stderr or result.stdout or "Self-test failed",
        )

        result = subprocess.run(
            [venv.python, "-c", "import gitdb; import smmap"],
            stdout=subprocess.PIPE,
            cwd=venv.sources,
        )
        self.assertEqual(
            0,
            result.returncode,
            msg=result.stderr or result.stdout or "Dependencies not installed",
        )

        # Even IF gitdb or any other dependency is supplied during development by
        # inserting its location into PYTHONPATH or otherwise patched into sys.path,
        # make sure it is not wrongly inserted as the *first* entry.
        result = subprocess.run(
            [venv.python, "-c", "import sys; import git; print(sys.path)"],
            stdout=subprocess.PIPE,
            cwd=venv.sources,
        )
        syspath = result.stdout.decode("utf-8").splitlines()[0]
        syspath = ast.literal_eval(syspath)
        self.assertEqual(
            "",
            syspath[0],
            msg="Failed to follow the conventions for https://docs.python.org/3/library/sys.html#sys.path",
        )

    @staticmethod
    def _set_up_venv(rw_dir):
        venv = VirtualEnvironment(rw_dir, with_pip=True)
        os.symlink(
            os.path.dirname(os.path.dirname(__file__)),
            venv.sources,
            target_is_directory=True,
        )
        return venv