@@ -1100,4 +1100,45 @@ class SnapshotDownloadTests: XCTestCase {
1100
1100
" Downloaded file should exist at \( filePath. path) "
1101
1101
)
1102
1102
}
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
+ }
1103
1144
}
0 commit comments