File: test_core_functions.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 (97 lines) | stat: -rw-r--r-- 2,976 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
95
96
97
from pathlib import Path
from unittest.mock import call

from setuptools.dist import Distribution

from jupyter_packaging.setupbase import npm_builder, wrap_installers


def test_wrap_installers():
    called = False

    def func():
        nonlocal called
        called = True

    cmd_class = wrap_installers(
        pre_dist=func, pre_develop=func, post_dist=func, post_develop=func
    )

    for name in ["pre_dist", "pre_develop", "post_dist", "post_develop"]:
        cmd_class[name](Distribution()).run()
        assert called
        called = False


def test_npm_builder(mocker):
    which = mocker.patch("jupyter_packaging.setupbase.which")
    run = mocker.patch("jupyter_packaging.setupbase.run")
    builder = npm_builder()
    which.return_value = ["foo"]
    builder()
    cwd = Path.cwd()
    run.assert_has_calls(
        [call(["npm", "install"], cwd=cwd), call(["npm", "run", "build"], cwd=cwd)]
    )


def test_npm_build_skip(mocker):
    which = mocker.patch("jupyter_packaging.setupbase.which")
    run = mocker.patch("jupyter_packaging.setupbase.run")
    mocker.patch("jupyter_packaging.setupbase.skip_npm", True)
    builder = npm_builder()
    which.return_value = ["foo"]
    builder()
    run.assert_not_called()


def test_npm_builder_yarn(tmp_path, mocker):
    which = mocker.patch("jupyter_packaging.setupbase.which")
    run = mocker.patch("jupyter_packaging.setupbase.run")
    tmp_path.joinpath("yarn.lock").write_text("hello")
    builder = npm_builder(path=tmp_path)
    which.return_value = ["foo"]
    builder()
    run.assert_has_calls(
        [
            call(["yarn", "install"], cwd=tmp_path),
            call(["yarn", "run", "build"], cwd=tmp_path),
        ]
    )


def test_npm_builder_missing_yarn(tmp_path, mocker):
    which = mocker.patch("jupyter_packaging.setupbase.which")
    run = mocker.patch("jupyter_packaging.setupbase.run")
    tmp_path.joinpath("yarn.lock").write_text("hello")
    builder = npm_builder(path=tmp_path)
    which.side_effect = ["", "foo"]
    builder()
    run.assert_has_calls(
        [
            call(["npm", "install"], cwd=tmp_path),
            call(["npm", "run", "build"], cwd=tmp_path),
        ]
    )


def test_npm_builder_not_stale(tmp_path, mocker):
    which = mocker.patch("jupyter_packaging.setupbase.which")
    run = mocker.patch("jupyter_packaging.setupbase.run")
    is_stale = mocker.patch("jupyter_packaging.setupbase.is_stale")
    is_stale.return_value = False
    builder = npm_builder(build_dir=tmp_path, source_dir=tmp_path)
    which.return_value = ["foo"]
    builder()
    run.assert_not_called()


def test_npm_builder_no_npm(mocker):
    which = mocker.patch("jupyter_packaging.setupbase.which")
    run = mocker.patch("jupyter_packaging.setupbase.run")
    is_stale = mocker.patch("jupyter_packaging.setupbase.is_stale")
    is_stale.return_value = False
    builder = npm_builder()
    which.return_value = []
    builder()
    run.assert_not_called()