1
1
import pysam
2
2
from hypothesis import HealthCheck , given , note , settings
3
+ from hypothesis .strategies import data
3
4
4
5
from hypothesis_vcf import vcf
6
+ from hypothesis_vcf .strategies import (
7
+ RESERVED_FORMAT_KEYS ,
8
+ RESERVED_INFO_KEYS ,
9
+ Field ,
10
+ vcf_field_keys ,
11
+ vcf_fields ,
12
+ vcf_values ,
13
+ )
14
+
15
+
16
+ @given (data = data ())
17
+ def test_vcf_field_keys (data ):
18
+ info_field_key = data .draw (vcf_field_keys ("INFO" ))
19
+ assert info_field_key not in RESERVED_INFO_KEYS
20
+ format_field_key = data .draw (vcf_field_keys ("FORMAT" ))
21
+ assert format_field_key not in RESERVED_FORMAT_KEYS
22
+
23
+
24
+ @given (data = data ())
25
+ def test_info_fields (data ):
26
+ field = data .draw (vcf_fields ("INFO" , max_number = 3 ))
27
+ assert field .category == "INFO"
28
+ assert field .vcf_number != "G"
29
+ if field .vcf_type == "Flag" :
30
+ assert field .vcf_number == "0"
31
+ else :
32
+ assert field .vcf_number != "0"
33
+
34
+
35
+ @given (data = data ())
36
+ def test_format_fields (data ):
37
+ field = data .draw (vcf_fields ("FORMAT" , max_number = 3 ))
38
+ assert field .category == "FORMAT"
39
+ assert field .vcf_type != "Flag"
40
+ assert field .vcf_number != "0"
41
+
42
+
43
+ @given (data = data ())
44
+ def test_vcf_values (data ):
45
+ field = Field ("INFO" , "I1" , "Integer" , "1" )
46
+ values = data .draw (vcf_values (field , max_number = 3 , alt_alleles = 1 , ploidy = 2 ))
47
+ assert values is not None
48
+ assert len (values ) == 1
49
+ assert values [0 ] is None or isinstance (values [0 ], int )
5
50
6
51
7
52
# simple test from README
@@ -14,7 +59,7 @@ def test_vcf(vcf_string):
14
59
# zero-based coordinates (even when passing zerobased=True to pysam.tabix_index below)
15
60
@given (vcf_string = vcf (min_pos = 1 ))
16
61
@settings (suppress_health_check = [HealthCheck .function_scoped_fixture ])
17
- def test (tmp_path , vcf_string ):
62
+ def test_vcf_parsing_with_pysam (tmp_path , vcf_string ):
18
63
note (f"vcf:\n { vcf_string } " )
19
64
20
65
# Write VCF to a file
0 commit comments