File: compile_test.py

package info (click to toggle)
python-pysam 0.23.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,464 kB
  • sloc: ansic: 158,947; python: 8,806; makefile: 264; sh: 79
file content (76 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'''
compile_test.py - check pyximport functionality with pysam
==========================================================

test script for checking if compilation against
pysam and tabix works.
'''

# clean up previous compilation
import os
import platform
import pytest
import pysam
from TestUtils import make_data_files, BAM_DATADIR, CBCF_DATADIR, TABIX_DATADIR


def setUpModule():
    make_data_files(BAM_DATADIR)
    make_data_files(CBCF_DATADIR)
    make_data_files(TABIX_DATADIR)


try:
    os.unlink('tests/_compile_test.c')
    os.unlink('tests/_compile_test.pyxbldc')
except OSError:
    pass

NO_PYXIMPORT = False
try:
    import pyximport
    pyximport.install(build_in_temp=False)
    import _compile_test
except:
    NO_PYXIMPORT = True


@pytest.mark.skipif(NO_PYXIMPORT, reason="no pyximport")
def test_bam():

    input_filename = os.path.join(BAM_DATADIR, "ex1.bam")
    nread = _compile_test.testCountBAM(
        pysam.Samfile(input_filename))
    assert nread == 3270


@pytest.mark.skipif(NO_PYXIMPORT, reason="no pyximport")
def test_gtf():

    input_filename = os.path.join(TABIX_DATADIR, "example.gtf.gz")

    nread = _compile_test.testCountGTF(
        pysam.Tabixfile(input_filename))
    assert nread == 237


@pytest.mark.skipif(
    platform.architecture()[0] != '64bit',
    reason="64-bit specific tests"
)
class TestBinaryCompatibility:
    def test_alignments(self):
        fp = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"))
        hdr = pysam.AlignmentHeader()
        aln = pysam.AlignedSegment()

        assert fp.__sizeof__() == 120
        assert hdr.__sizeof__() == 24
        assert aln.__sizeof__() == 72

    def test_variants(self):
        fp = pysam.VariantFile(os.path.join(CBCF_DATADIR, "example_vcf43.vcf"))
        hdr = pysam.VariantHeader()

        assert fp.__sizeof__() == 120
        assert hdr.__sizeof__() == 32