コード例 #1
0
ファイル: package_json.py プロジェクト: saurzcode/catboost
def test_get_workspace_map_ok():
    pj = PackageJson("/packages/foo/package.json")
    pj.data = {
        "dependencies": {
            "@yandex-int/bar": "workspace:../bar",
        },
    }

    def load_mock(cls, path):
        name = os.path.basename(os.path.dirname(path))
        p = PackageJson(path)
        p.data = {
            "name": "@yandex-int/{}".format(name),
            "dependencies": ({"@yandex-int/qux": "workspace:../qux"} if name == "bar" else {}),
        }
        return p
    PackageJson.load = classmethod(load_mock)

    ws_map = pj.get_workspace_map()

    assert len(ws_map) == 3
    assert ws_map["/packages/foo"][0].path == "/packages/foo/package.json"
    assert ws_map["/packages/foo"][1] == 0
    assert ws_map["/packages/bar"][0].path == "/packages/bar/package.json"
    assert ws_map["/packages/bar"][1] == 1
    assert ws_map["/packages/qux"][0].path == "/packages/qux/package.json"
    assert ws_map["/packages/qux"][1] == 2
コード例 #2
0
ファイル: package_json.py プロジェクト: saurzcode/catboost
 def load_mock(cls, path):
     name = os.path.basename(os.path.dirname(path))
     p = PackageJson(path)
     p.data = {
         "name": "@yandex-int/{}".format(name),
         "dependencies": ({"@yandex-int/qux": "workspace:../qux"} if name == "bar" else {}),
     }
     return p
コード例 #3
0
ファイル: package_json.py プロジェクト: saurzcode/catboost
def test_get_workspace_dep_paths_invalid_path():
    pj = PackageJson("/packages/foo/package.json")
    pj.data = {
        "dependencies": {
            "@yandex-int/bar": "workspace:*",
        },
    }

    with pytest.raises(PackageJsonWorkspaceError) as e:
        pj.get_workspace_dep_paths()

    assert str(e.value) == "Expected relative path specifier for workspace dependency, but got 'workspace:*' for @yandex-int/bar in /packages/foo/package.json"
コード例 #4
0
ファイル: package_json.py プロジェクト: saurzcode/catboost
def test_get_workspace_dep_paths_ok():
    pj = PackageJson("/packages/foo/package.json")
    pj.data = {
        "dependencies": {
            "@yandex-int/bar": "workspace:../bar",
        },
        "devDependencies": {
            "@yandex-int/baz": "workspace:../baz",
        },
    }

    ws_dep_paths = pj.get_workspace_dep_paths()

    assert ws_dep_paths == [
        ("@yandex-int/bar", "../bar"),
        ("@yandex-int/baz", "../baz"),
    ]
コード例 #5
0
ファイル: package_json.py プロジェクト: saurzcode/catboost
def test_get_workspace_deps_with_wrong_name():
    pj = PackageJson("/packages/foo/package.json")
    pj.data = {
        "dependencies": {
            "@yandex-int/bar": "workspace:../bar",
        },
    }

    def load_mock(cls, path):
        p = PackageJson(path)
        p.data = {
            "name": "@shouldbe/{}".format(os.path.basename(os.path.dirname(path))),
        }
        return p
    PackageJson.load = classmethod(load_mock)

    with pytest.raises(PackageJsonWorkspaceError) as e:
        pj.get_workspace_deps()

    assert str(e.value) == "Workspace dependency name mismatch, found '@yandex-int/bar' instead of '@shouldbe/bar' in /packages/foo/package.json"
コード例 #6
0
ファイル: package_json.py プロジェクト: saurzcode/catboost
def test_get_workspace_deps_ok():
    pj = PackageJson("/packages/foo/package.json")
    pj.data = {
        "dependencies": {
            "@yandex-int/bar": "workspace:../bar",
        },
        "devDependencies": {
            "@yandex-int/baz": "workspace:../baz",
        },
    }

    def load_mock(cls, path):
        p = PackageJson(path)
        p.data = {
            "name": "@yandex-int/{}".format(os.path.basename(os.path.dirname(path))),
        }
        return p
    PackageJson.load = classmethod(load_mock)

    ws_deps = pj.get_workspace_deps()

    assert len(ws_deps) == 2
    assert ws_deps[0].path == "/packages/bar/package.json"
    assert ws_deps[1].path == "/packages/baz/package.json"
コード例 #7
0
ファイル: package_json.py プロジェクト: saurzcode/catboost
 def load_mock(cls, path):
     p = PackageJson(path)
     p.data = {
         "name": "@shouldbe/{}".format(os.path.basename(os.path.dirname(path))),
     }
     return p