Skip to content

Commit 46171be

Browse files
committed
added check for missing file in SeqIO
1 parent d9ade06 commit 46171be

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/main/kotlin/biokotlin/seqIO/SeqIO.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private fun seqIterator(format: SeqFormat, type: SeqType, filename: String): Seq
6161
fun reader(filename: String, format: SeqFormat? = null, type: SeqType = SeqType.nucleotide): SequenceIterator {
6262

6363
assert(filename.isNotEmpty())
64+
require(File(filename).exists()) { "File not found: $filename"}
6465

6566
val formatToUse = if (format != null) {
6667
format

src/test/kotlin/biokotlin/seqIO/FastaIOTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import biokotlin.seq.*
44
import biokotlin.util.bufferedReader
55
import io.kotest.core.spec.style.StringSpec
66
import io.kotest.matchers.shouldBe
7+
import org.junit.jupiter.api.assertThrows
78
import java.io.File
89

910
class FastaIOTest : StringSpec({
@@ -18,6 +19,14 @@ class FastaIOTest : StringSpec({
1819
"B73V4_ctg58" to 196,
1920
"B73V4_ctg43" to 161
2021
)
22+
"Verify file exists" {
23+
// this test verifies that when given a non-existing file, the exception is propagated
24+
// and the test does not hang
25+
val badFile = "/Users/lcj34/debug/biokotlin/nonExisting.fa"
26+
assertThrows<IllegalArgumentException>{
27+
NucSeqIO(badFile)
28+
}
29+
}
2130

2231
"iterateFile" {
2332

0 commit comments

Comments
 (0)