Skip to content

Commit

Permalink
raise an IOError if the file is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Sep 24, 2024
1 parent 49ea351 commit 13cec41
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ext/bio/bigwig/bigwigext.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bw_get_header(VALUE self)

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
rb_raise(rb_eIOError, "The bigWig file handle is not opened!");
return Qnil;
}

Expand Down Expand Up @@ -225,7 +225,7 @@ bw_get_chroms(int argc, VALUE *argv, VALUE self)

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
rb_raise(rb_eIOError, "The bigWig file handle is not opened!");
return Qnil;
}

Expand Down Expand Up @@ -299,7 +299,7 @@ bw_get_stats(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE rb_

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
rb_raise(rb_eIOError, "The bigWig file handle is not opened!");
return Qnil;
}

Expand Down Expand Up @@ -412,7 +412,7 @@ bw_get_values(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end)

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
rb_raise(rb_eIOError, "The bigWig file handle is not opened!");
return Qnil;
}

Expand Down Expand Up @@ -484,7 +484,7 @@ bw_get_intervals(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end)

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
rb_raise(rb_eIOError, "The bigWig file handle is not opened!");
return Qnil;
}

Expand Down Expand Up @@ -573,7 +573,7 @@ bb_get_entries(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE r

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigBed file handle is not opened!");
rb_raise(rb_eIOError, "The bigBed file handle is not opened!");
return Qnil;
}

Expand Down Expand Up @@ -671,7 +671,7 @@ bb_get_sql(VALUE self)

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigBed file handle is not opened!");
rb_raise(rb_eIOError, "The bigBed file handle is not opened!");
return Qnil;
}

Expand Down Expand Up @@ -701,7 +701,7 @@ bw_get_file_type(VALUE self)

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
rb_raise(rb_eIOError, "The bigWig file handle is not opened!");
return Qnil;
}

Expand All @@ -724,7 +724,7 @@ bw_is_file_type(VALUE self, int type_check)

if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
rb_raise(rb_eIOError, "The bigWig file handle is not opened!");
return Qnil;
}

Expand Down
15 changes: 15 additions & 0 deletions test/bigwig_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ def test_closed_with_block
assert_equal true, f.closed?
end

def test_closed_file_error
bw = Bio::BigWig.new(bwfile)
assert_equal Bio::BigWig, bw.class
bw.close
assert_raises(IOError) { bw.header }
assert_raises(IOError) { bw.chroms }
assert_raises(IOError) { bw.stats("1") }
assert_raises(IOError) { bw.values("1", 0, 3) }
assert_raises(IOError) { bw.intervals("1", 0, 3) }
assert_raises(IOError) { bw.entries("1", 0, 3) }
assert_raises(IOError) { bw.sql }
assert_raises(IOError) { bw.is_bigwig? }
assert_raises(IOError) { bw.is_bigbed? }
end

def test_open_remote
skip "Skipping remote test" unless ENV["RUN_REMOTE_TESTS"] == "1"

Expand Down

0 comments on commit 13cec41

Please sign in to comment.