Exemple #1
0
def test_find_package_json_no_package_json(tmpdir):
    tarfile_path = os.path.join(tmpdir, "random.tgz")
    with tarfile.open(tarfile_path, "x:gz") as archive:
        archive.addfile(tarfile.TarInfo("wrong_file.json"), b"{}")
        archive.addfile(
            tarfile.TarInfo("package/tom_hanks_quotes.html"),
            b"<p>Life is like a box of chocolates. You never know what you're gonna get.<p>",
        )
    assert general_js.find_package_json(tarfile_path) is None
Exemple #2
0
def test_find_package_json(tmpdir):
    tarfile_path = os.path.join(tmpdir, "npm-package.tgz")
    with tarfile.open(tarfile_path, "x:gz") as archive:
        archive.addfile(
            tarfile.TarInfo("in/a/galaxy/far/far/away/package.json"))
        archive.addfile(tarfile.TarInfo("in/too/deep/package.json"))
        archive.addfile(tarfile.TarInfo("wrong_file.json"))
        archive.addfile(tarfile.TarInfo("package/index.html"))
        archive.addfile(tarfile.TarInfo("package2/package.json"))
        archive.addfile(tarfile.TarInfo("package/package.json"))

    assert general_js.find_package_json(
        tarfile_path) == "package2/package.json"