Skip to content

Commit 107c493

Browse files
psiddhCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 305afcb commit 107c493

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch/LlmModuleConversationHistoryTest.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,16 @@ class LlmModuleConversationHistoryTest {
4747
@Throws(IOException::class)
4848
fun setUp() {
4949
val pteFile = File(getTestFilePath(TEST_FILE_NAME))
50-
val pteStream =
51-
requireNotNull(javaClass.getResourceAsStream(TEST_FILE_NAME)) {
50+
requireNotNull(javaClass.getResourceAsStream(TEST_FILE_NAME)) {
5251
"Test resource $TEST_FILE_NAME not found; did android_test_setup.sh run?"
5352
}
54-
FileUtils.copyInputStreamToFile(pteStream, pteFile)
55-
pteStream.close()
53+
.use { pteStream -> FileUtils.copyInputStreamToFile(pteStream, pteFile) }
5654

5755
val tokenizerFile = File(getTestFilePath(TOKENIZER_FILE_NAME))
58-
val tokenizerStream =
59-
requireNotNull(javaClass.getResourceAsStream(TOKENIZER_FILE_NAME)) {
56+
requireNotNull(javaClass.getResourceAsStream(TOKENIZER_FILE_NAME)) {
6057
"Test resource $TOKENIZER_FILE_NAME not found; did android_test_setup.sh run?"
6158
}
62-
FileUtils.copyInputStreamToFile(tokenizerStream, tokenizerFile)
63-
tokenizerStream.close()
59+
.use { tokenizerStream -> FileUtils.copyInputStreamToFile(tokenizerStream, tokenizerFile) }
6460

6561
llmModule =
6662
LlmModule(getTestFilePath(TEST_FILE_NAME), getTestFilePath(TOKENIZER_FILE_NAME), 0.0f)
@@ -118,7 +114,7 @@ class LlmModuleConversationHistoryTest {
118114
firstRun,
119115
secondRun,
120116
)
121-
} catch (_: RuntimeException) {
117+
} catch (_: ExecutorchRuntimeException) {
122118
// The second generate() threw because KV-cache state from the first call
123119
// affected execution — this also proves state persistence.
124120
}

0 commit comments

Comments
 (0)