From 46093a1a01ea44f03dee4f12d65e7af1f0d2f6df Mon Sep 17 00:00:00 2001 From: Tom White Date: Fri, 14 Jun 2024 09:07:22 +0100 Subject: [PATCH] More tests for internal strategies --- tests/test_strategies.py | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/test_strategies.py b/tests/test_strategies.py index 6dd1809..b389e52 100644 --- a/tests/test_strategies.py +++ b/tests/test_strategies.py @@ -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 @@ -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