Skip to content

Commit

Permalink
More tests for internal strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite committed Jun 14, 2024
1 parent dbbcce2 commit 46093a1
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion tests/test_strategies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
import pysam
from hypothesis import HealthCheck, given, note, settings
from hypothesis.strategies import data

from hypothesis_vcf import vcf
from hypothesis_vcf.strategies import (
RESERVED_FORMAT_KEYS,
RESERVED_INFO_KEYS,
Field,
vcf_field_keys,
vcf_fields,
vcf_values,
)


@given(data=data())
def test_vcf_field_keys(data):
info_field_key = data.draw(vcf_field_keys("INFO"))
assert info_field_key not in RESERVED_INFO_KEYS
format_field_key = data.draw(vcf_field_keys("FORMAT"))
assert format_field_key not in RESERVED_FORMAT_KEYS


@given(data=data())
def test_info_fields(data):
field = data.draw(vcf_fields("INFO", max_number=3))
assert field.category == "INFO"
assert field.vcf_number != "G"
if field.vcf_type == "Flag":
assert field.vcf_number == "0"
else:
assert field.vcf_number != "0"


@given(data=data())
def test_format_fields(data):
field = data.draw(vcf_fields("FORMAT", max_number=3))
assert field.category == "FORMAT"
assert field.vcf_type != "Flag"
assert field.vcf_number != "0"


@given(data=data())
def test_vcf_values(data):
field = Field("INFO", "I1", "Integer", "1")
values = data.draw(vcf_values(field, max_number=3, alt_alleles=1, ploidy=2))
assert values is not None
assert len(values) == 1
assert values[0] is None or isinstance(values[0], int)


# simple test from README
Expand All @@ -14,7 +59,7 @@ def test_vcf(vcf_string):
# zero-based coordinates (even when passing zerobased=True to pysam.tabix_index below)
@given(vcf_string=vcf(min_pos=1))
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture])
def test(tmp_path, vcf_string):
def test_vcf_parsing_with_pysam(tmp_path, vcf_string):
note(f"vcf:\n{vcf_string}")

# Write VCF to a file
Expand Down

0 comments on commit 46093a1

Please sign in to comment.