File: test_datafiles_install.py

package info (click to toggle)
jupyter-packaging 0.12.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: python: 1,533; sh: 15; makefile: 14
file content (94 lines) | stat: -rw-r--r-- 3,126 bytes parent folder | download | duplicates (3)
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
88
89
90
91
92
93
94
import pathlib
import shutil
import subprocess
import sys

import pytest
from deprecation import fail_if_not_removed

from .utils import site_packages_readonly

data_files_combinations = [
    (
        # data file source
        ("share/test.txt",),
        # data file spec
        ("jupyter-packaging-test", "share", "**/*"),
        # data file target
        "jupyter-packaging-test/test.txt",
    ),
    (
        # data file source
        ("share/test.txt",),
        # data file spec
        ("jupyter-packaging-test/level1", "share", "**/[a-z]est.txt"),
        # data file target
        "jupyter-packaging-test/level1/test.txt",
    ),
    (
        # data file source
        ("level1/test/test.txt",),
        # data file spec
        ("jupyter-packaging-test", "level1/test", "**/*"),
        # data file target
        "jupyter-packaging-test/test.txt",
    ),
    (
        # data file source
        ("level1/test/test.txt",),
        # data file spec
        ("jupyter-packaging-test/level1/level2", "level1/test", "**/*"),
        # data file target
        "jupyter-packaging-test//level1/level2/test.txt",
    ),
    (
        # data file source
        ("level1/level2/test/test.txt",),
        # data file spec
        ("jupyter-packaging-test", "level1", "**/*"),
        # data file target
        "jupyter-packaging-test/level2/test/test.txt",
    ),
]


@pytest.mark.skipif(site_packages_readonly, reason="Site Packages are Read-only")
@fail_if_not_removed
@pytest.mark.parametrize("source,spec,target", data_files_combinations)
def test_develop(make_package_deprecated, source, spec, target):
    name = "jupyter_packaging_test_foo"
    package_dir = make_package_deprecated(
        name=name, data_files=source, data_files_spec=[spec]
    )
    target_path = pathlib.Path(sys.prefix).joinpath(target)
    if target_path.exists():
        shutil.rmtree(str(target_path.parent))
    subprocess.check_output(
        [sys.executable, "-m", "pip", "install", "-e", "."], cwd=str(package_dir)
    )
    assert target_path.exists()
    subprocess.check_output(
        [sys.executable, "-m", "pip", "uninstall", "-y", name], cwd=str(package_dir)
    )
    # This is something to fix later. uninstalling a package installed
    # with -e should be removed.
    assert target_path.exists()
    shutil.rmtree(str(target_path.parent))


@pytest.mark.skipif(site_packages_readonly, reason="Site Packages are Read-only")
@pytest.mark.parametrize("source,spec,target", data_files_combinations)
def test_install(make_package, source, spec, target):
    name = "jupyter_packaging_test_foo"
    package_dir = make_package(name=name, data_files=source, data_files_spec=[spec])
    target_path = pathlib.Path(sys.prefix).joinpath(target)
    if target_path.exists():
        shutil.rmtree(str(target_path.parent))
    subprocess.check_output(
        [sys.executable, "-m", "pip", "install", "."], cwd=str(package_dir)
    )
    assert target_path.exists()
    subprocess.check_output(
        [sys.executable, "-m", "pip", "uninstall", "-y", name], cwd=str(package_dir)
    )
    assert not target_path.exists()