Skip to content

Commit 0cf9d29

Browse files
committed
{AH} add unit tests to check return type for string/byte output, closes #292
1 parent 44497a5 commit 0cf9d29

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

pysam/cutils.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ def _pysam_dispatch(collection,
297297
# setup the function call to samtools/bcftools main
298298
cdef char ** cargs
299299
cdef int i, n, retval, l
300-
301300
n = len(args)
302301
method = force_bytes(method)
303302
collection = force_bytes(collection)

pysam/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def __call__(self, *args, **kwargs):
7171
"stdout=%s, stderr=%s" %
7272
(self.collection,
7373
retval,
74-
"\n".join(stdout),
75-
"\n".join(stderr)))
74+
stdout,
75+
stderr))
7676

7777
self.stderr = stderr
7878

tests/samtools_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,28 @@ def testEmptyIndex(self):
243243
self.assertRaises(IOError, pysam.samtools.index,
244244
"exdoesntexist.bam")
245245

246+
class TestReturnType(unittest.TestCase):
247+
248+
def testReturnValueString(self):
249+
retval = pysam.idxstats(os.path.join(DATADIR, "ex1.bam"))
250+
if IS_PYTHON3:
251+
self.assertFalse(isinstance(retval, bytes))
252+
self.assertTrue(isinstance(retval, str))
253+
else:
254+
self.assertTrue(isinstance(retval, bytes))
255+
self.assertTrue(isinstance(retval, basestring))
256+
257+
def testReturnValueData(self):
258+
args = "-O BAM {}".format(os.path.join(DATADIR, "ex1.bam")).split(" ")
259+
retval = pysam.view(*args)
260+
261+
if IS_PYTHON3:
262+
self.assertTrue(isinstance(retval, bytes))
263+
self.assertFalse(isinstance(retval, str))
264+
else:
265+
self.assertTrue(isinstance(retval, bytes))
266+
self.assertTrue(isinstance(retval, basestring))
267+
246268

247269
class StdoutTest(unittest.TestCase):
248270
'''test if stdout can be redirected.'''

0 commit comments

Comments
 (0)