Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include file name in error when open fails, include range in error wh… #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/tabixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ tabix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)

tb = ti_open(fn, fnidx);
if (tb == NULL) {
PyErr_SetString(TabixError, "Can't open the index file.");
return NULL;
return PyErr_Format(TabixError, "Can't open index file: %s", fn);
}

self = (TabixObject *)type->tp_alloc(type, 0);
Expand Down Expand Up @@ -234,8 +233,7 @@ tabix_query(TabixObject *self, PyObject *args)

result = ti_query(self->tb, name, begin - 1, end);
if (result == NULL) {
PyErr_SetString(TabixError, "query failed");
return NULL;
return PyErr_Format(TabixError, "query failed: %s:%d-%d", name, begin, end);
}

return tabixiter_create(self, result);
Expand All @@ -252,8 +250,7 @@ tabix_queryi(TabixObject *self, PyObject *args)

result = ti_queryi(self->tb, tid, begin - 1, end);
if (result == NULL) {
PyErr_SetString(TabixError, "query failed");
return NULL;
return PyErr_Format(TabixError, "query failed: tid: %d range: %d-%d", tid, begin, end);
}

return tabixiter_create(self, result);
Expand All @@ -270,8 +267,7 @@ tabix_querys(TabixObject *self, PyObject *args)

result = ti_querys(self->tb, reg);
if (result == NULL) {
PyErr_SetString(TabixError, "query failed");
return NULL;
return PyErr_Format(TabixError, "query failed: %s", reg);
}

return tabixiter_create(self, result);
Expand Down
11 changes: 10 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,23 @@ def test_querys(self):
tb_result = [ [x[0], x[3], x[4]] for x in it ]
self.assertEqual(self.result, tb_result)

def test_query_bad_seq(self):
with self.assertRaisesRegexp(tabix.TabixError, "^query failed: fred:{}-{}$".format(self.start, self.end)):
it = self.tb.query("fred", self.start, self.end)

def test_local_bad_file(self):
file1 = "this_file_does_not_really_exist"
with self.assertRaisesRegexp(tabix.TabixError, "^Can't open index file: {}$".format(file1)):
tabix.open(file1)

def test_remote_file(self):
file1 = "ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20100804/" \
"ALL.2of4intersection.20100804.genotypes.vcf.gz"
tabix.open(file1)

def test_remote_file_bad_url(self):
file1 = "ftp://badurl"
with self.assertRaises(tabix.TabixError):
with self.assertRaisesRegexp(tabix.TabixError, "^Can't open index file: {}$".format(file1)):
tabix.open(file1)


Expand Down