Skip to content

Commit f6304af

Browse files
Sendable Hub.Downloader, Hub.Hub and Hub.HubApi .6
1 parent 5212740 commit f6304af

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Tests/HubTests/HubApiTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,4 +1100,45 @@ class SnapshotDownloadTests: XCTestCase {
11001100
"Downloaded file should exist at \(filePath.path)"
11011101
)
11021102
}
1103+
1104+
func testDownloadWithRevision() async throws {
1105+
let hubApi = HubApi(downloadBase: downloadDestination)
1106+
var lastProgress: Progress? = nil
1107+
1108+
let commitHash = "eaf97358a37d03fd48e5a87d15aff2e8423c1afb"
1109+
let downloadedTo = try await hubApi.snapshot(from: repo, revision: commitHash, matching: "*.json") { progress in
1110+
print("Total Progress: \(progress.fractionCompleted)")
1111+
print("Files Completed: \(progress.completedUnitCount) of \(progress.totalUnitCount)")
1112+
lastProgress = progress
1113+
}
1114+
1115+
let downloadedFilenames = getRelativeFiles(url: downloadDestination, repo: repo)
1116+
XCTAssertEqual(lastProgress?.fractionCompleted, 1)
1117+
XCTAssertEqual(lastProgress?.completedUnitCount, 6)
1118+
XCTAssertEqual(downloadedTo, downloadDestination.appending(path: "models/\(repo)"))
1119+
XCTAssertEqual(
1120+
Set(downloadedFilenames),
1121+
Set([
1122+
"config.json", "tokenizer.json", "tokenizer_config.json",
1123+
"llama-2-7b-chat.mlpackage/Manifest.json",
1124+
"llama-2-7b-chat.mlpackage/Data/com.apple.CoreML/FeatureDescriptions.json",
1125+
"llama-2-7b-chat.mlpackage/Data/com.apple.CoreML/Metadata.json",
1126+
])
1127+
)
1128+
1129+
do {
1130+
let revision = "nonexistent-revision"
1131+
try await hubApi.snapshot(from: repo, revision: revision, matching: "*.json")
1132+
XCTFail("Expected an error to be thrown")
1133+
} catch let error as Hub.HubClientError {
1134+
switch error {
1135+
case .fileNotFound:
1136+
break // Error type is correct
1137+
default:
1138+
XCTFail("Wrong error type: \(error)")
1139+
}
1140+
} catch {
1141+
XCTFail("Unexpected error: \(error)")
1142+
}
1143+
}
11031144
}

0 commit comments

Comments
 (0)