Skip to content

Commit

Permalink
Try alternative test implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed Jun 7, 2024
1 parent d36111e commit 119ea9f
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions FirebaseVertexAI/Tests/Unit/PartsRepresentableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,45 @@ final class PartsRepresentableTests: XCTestCase {
XCTFail("Expected model content from invlaid image to error")
}

#if canImport(UIKit) && !os(visionOS) // These tests are stalling in CI on visionOS.
func testModelContentFromInvalidUIImageThrows() throws {
#if canImport(UIKit)
func testModelContentFromInvalidUIImageThrows() {
print("Instantiating UIImage.")
let image = UIImage()
do {
print("Getting image parts.")
_ = try image.tryPartsValue()
XCTFail("Expected ImageConversionError.couldNotConvertToJPEG; no error.")
} catch let ImageConversionError.couldNotConvertToJPEG(source as UIImage) {
print("Checking image equality.")
XCTAssertEqual(source, image)
} catch {
guard let imageError = (error as? ImageConversionError) else {
XCTFail("Got unexpected error type: \(error)")
return
}
switch imageError {
case let .couldNotConvertToJPEG(source):
// String(describing:) works around a type error.
XCTAssertEqual(String(describing: source), String(describing: image))
return
case _:
XCTFail("Expected image conversion error, got \(imageError) instead")
return
}
XCTFail("Expected ImageConversionError.couldNotConvertToJPEG; error thrown: \(error)")
}
XCTFail("Expected model content from invlaid image to error")
print("Done testModelContentFromInvalidUIImageThrows.")
}

func testModelContentFromUIImageIsNotEmpty() throws {
let coreImage = CIImage(color: CIColor.red)
.cropped(to: CGRect(origin: CGPointZero, size: CGSize(width: 16, height: 16)))
let image = UIImage(ciImage: coreImage)
let modelContent = try image.tryPartsValue()
XCTAssert(modelContent.count > 0, "Expected non-empty model content for UIImage: \(image)")
func testModelContentFromUIImageIsNotEmpty() {
print("Creating UIImage with systemName.")
guard let image = UIImage(systemName: "photo") else {
XCTFail("Failed to create UIImage with system name.")
return
}
print("Getting image parts.")
let modelContent: [ModelContent.Part]
do {
modelContent = try image.tryPartsValue()
print("Got image parts.")
} catch {
XCTFail("Getting image parts failed with error: \(error)")
return
}
print("Checking content part count.")
XCTAssertEqual(
modelContent.count,
1,
"Expected non-empty model content for UIImage: \(image)"
)
print("Done testModelContentFromUIImageIsNotEmpty.")
}

#elseif canImport(AppKit)
Expand Down

0 comments on commit 119ea9f

Please sign in to comment.