Skip to content

Commit 46093a1

Browse files
committed
More tests for internal strategies
1 parent dbbcce2 commit 46093a1

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

tests/test_strategies.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,52 @@
11
import pysam
22
from hypothesis import HealthCheck, given, note, settings
3+
from hypothesis.strategies import data
34

45
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)
550

651

752
# simple test from README
@@ -14,7 +59,7 @@ def test_vcf(vcf_string):
1459
# zero-based coordinates (even when passing zerobased=True to pysam.tabix_index below)
1560
@given(vcf_string=vcf(min_pos=1))
1661
@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):
1863
note(f"vcf:\n{vcf_string}")
1964

2065
# Write VCF to a file

0 commit comments

Comments
 (0)