File size: 4,378 Bytes
21dd449 |
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
import { assert, it, describe } from "vitest";
import type { ListFileEntry } from "./list-files";
import { listFiles } from "./list-files";
describe("listFiles", () => {
it("should fetch the list of files from the repo", async () => {
const cursor = listFiles({
repo: {
name: "bert-base-uncased",
type: "model",
},
revision: "dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7",
});
const files: ListFileEntry[] = [];
for await (const entry of cursor) {
files.push(entry);
}
assert.deepStrictEqual(files, [
{
oid: "dc08351d4dc0732d9c8af04070ced089b201ce2f",
path: ".gitattributes",
size: 345,
type: "file",
},
{
oid: "fca794a5f07ff8f963fe8b61e3694b0fb7f955df",
path: "config.json",
size: 313,
type: "file",
},
{
lfs: {
oid: "097417381d6c7230bd9e3557456d726de6e83245ec8b24f529f60198a67b203a",
size: 440473133,
pointerSize: 134,
},
xetHash: "2d8408d3a894d02517d04956e2f7546ff08362594072f3527ce144b5212a3296",
oid: "ba5d19791be1dd7992e33bd61f20207b0f7f50a5",
path: "pytorch_model.bin",
size: 440473133,
type: "file",
},
{
lfs: {
oid: "a7a17d6d844b5de815ccab5f42cad6d24496db3850a2a43d8258221018ce87d2",
size: 536063208,
pointerSize: 134,
},
xetHash: "879c5715c18a0b7f051dd33f70f0a5c8dd1522e0a43f6f75520f16167f29279b",
oid: "9eb98c817f04b051b3bcca591bcd4e03cec88018",
path: "tf_model.h5",
size: 536063208,
type: "file",
},
{
oid: "fb140275c155a9c7c5a3b3e0e77a9e839594a938",
path: "vocab.txt",
size: 231508,
type: "file",
},
]);
});
it("should fetch the list of files from the repo, including last commit", async () => {
const cursor = listFiles({
repo: {
name: "bert-base-uncased",
type: "model",
},
revision: "dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7",
expand: true,
});
const files: ListFileEntry[] = [];
for await (const entry of cursor) {
delete entry.securityFileStatus; // flaky
files.push(entry);
}
assert.deepStrictEqual(files, [
{
lastCommit: {
date: "2018-11-14T23:35:08.000Z",
id: "504939aa53e8ce310dba3dd2296dbe266c575de4",
title: "initial commit",
},
oid: "dc08351d4dc0732d9c8af04070ced089b201ce2f",
path: ".gitattributes",
size: 345,
type: "file",
},
{
lastCommit: {
date: "2019-06-18T09:06:51.000Z",
id: "bb3c1c3256d2598217df9889a14a2e811587891d",
title: "Update config.json",
},
oid: "fca794a5f07ff8f963fe8b61e3694b0fb7f955df",
path: "config.json",
size: 313,
type: "file",
},
{
lastCommit: {
date: "2019-06-18T09:06:34.000Z",
id: "3d2477d72b675a999d1b13ca822aaaf4908634ad",
title: "Update pytorch_model.bin",
},
lfs: {
oid: "097417381d6c7230bd9e3557456d726de6e83245ec8b24f529f60198a67b203a",
size: 440473133,
pointerSize: 134,
},
xetHash: "2d8408d3a894d02517d04956e2f7546ff08362594072f3527ce144b5212a3296",
oid: "ba5d19791be1dd7992e33bd61f20207b0f7f50a5",
path: "pytorch_model.bin",
size: 440473133,
type: "file",
},
{
lastCommit: {
date: "2019-09-23T19:48:44.000Z",
id: "dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7",
title: "Update tf_model.h5",
},
lfs: {
oid: "a7a17d6d844b5de815ccab5f42cad6d24496db3850a2a43d8258221018ce87d2",
size: 536063208,
pointerSize: 134,
},
xetHash: "879c5715c18a0b7f051dd33f70f0a5c8dd1522e0a43f6f75520f16167f29279b",
oid: "9eb98c817f04b051b3bcca591bcd4e03cec88018",
path: "tf_model.h5",
size: 536063208,
type: "file",
},
{
lastCommit: {
date: "2018-11-14T23:35:08.000Z",
id: "2f07d813ca87c8c709147704c87210359ccf2309",
title: "Update vocab.txt",
},
oid: "fb140275c155a9c7c5a3b3e0e77a9e839594a938",
path: "vocab.txt",
size: 231508,
type: "file",
},
]);
});
it("should fetch the list of files from the repo, including subfolders", async () => {
const cursor = listFiles({
repo: {
name: "xsum",
type: "dataset",
},
revision: "0f3ea2f2b55fcb11e71fb1e3aec6822e44ddcb0f",
recursive: true,
});
const files: ListFileEntry[] = [];
for await (const entry of cursor) {
files.push(entry);
}
assert(files.some((file) => file.path === "data/XSUM-EMNLP18-Summary-Data-Original.tar.gz"));
});
});
|