Debian Codegraph @

tests/compile_test.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 '''
2 compile_test.py - check pyximport functionality with pysam
3 ==========================================================
4
5 test script for checking if compilation against
6 pysam and tabix works.
7 '''
8
9 # clean up previous compilation
10 import os
•11 import platform
12 import pytest
13 import pysam
14 from TestUtils import make_data_files, BAM_DATADIR, CBCF_DATADIR, TABIX_DATADIR
15
16
17 def setUpModule():
18 make_data_files(BAM_DATADIR)
19 make_data_files(CBCF_DATADIR)
20 make_data_files(TABIX_DATADIR)
21
22
23 try:
24 os.unlink('tests/_compile_test.c')
25 os.unlink('tests/_compile_test.pyxbldc')
26 except OSError:
27 pass
28
29 NO_PYXIMPORT = False
30 try:
31 import pyximport
32 pyximport.install(build_in_temp=False)
33 import _compile_test
34 except:
35 NO_PYXIMPORT = True
36
37
38 @pytest.mark.skipif(NO_PYXIMPORT, reason="no pyximport")
39 def test_bam():
40
41 input_filename = os.path.join(BAM_DATADIR, "ex1.bam")
42 nread = _compile_test.testCountBAM(
43 pysam.Samfile(input_filename))
44 assert nread == 3270
45
46
47 @pytest.mark.skipif(NO_PYXIMPORT, reason="no pyximport")
48 def test_gtf():
49
50 input_filename = os.path.join(TABIX_DATADIR, "example.gtf.gz")
51
52 nread = _compile_test.testCountGTF(
53 pysam.Tabixfile(input_filename))
54 assert nread == 237
55
56
•57 @pytest.mark.skipif(
58 platform.architecture()[0] != '64bit',
59 reason="64-bit specific tests"
60 )
61 class TestBinaryCompatibility:
62 def test_alignments(self):
63 fp = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"))
64 hdr = pysam.AlignmentHeader()
65 aln = pysam.AlignedSegment()
66
67 assert fp.__sizeof__() == 120
68 assert hdr.__sizeof__() == 24
69 assert aln.__sizeof__() == 72
70
71 def test_variants(self):
72 fp = pysam.VariantFile(os.path.join(CBCF_DATADIR, "example_vcf43.vcf"))
73 hdr = pysam.VariantHeader()
74
75 assert fp.__sizeof__() == 120
76 assert hdr.__sizeof__() == 32