Skip to content

Commit 4d997aa

Browse files
Tested boolean operator precedence is correct
1 parent 2e5040b commit 4d997aa

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

tests/test_bcftools_validation.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,32 @@ def test_query_arithmethic(tmp_path, expr):
204204
assert vcztools_output == "112\n"
205205

206206

207+
@pytest.mark.parametrize(
208+
"expr",
209+
[
210+
# Check boolean logic evaluation. Will evaluate this with
211+
# POS=112, so POS=112 is True and POS!=112 is False
212+
"POS==112 || POS!=112", # True
213+
"POS==112 && POS!=112", # True
214+
"POS==112 || POS!=112 && POS!= 112", # True
215+
"(POS==112 || POS!=112) && POS!= 112", # False
216+
],
217+
)
218+
def test_query_logic_precendence(tmp_path, expr):
219+
220+
args = r"query -f '%POS\n'" + f" -i 'POS=112 && ({expr})'"
221+
vcf_name = "sample.vcf.gz"
222+
vcf_path = pathlib.Path("tests/data/vcf") / vcf_name
223+
vcz_path = vcz_path_cache(vcf_path)
224+
225+
bcftools_output, _ = run_bcftools(f"{args} {vcf_path}")
226+
vcztools_output, _ = run_vcztools(f"{args} {vcz_path}")
227+
228+
assert vcztools_output == bcftools_output
229+
num_lines = len(list(vcztools_output.splitlines()))
230+
assert num_lines in [0, 1]
231+
232+
207233
@pytest.mark.parametrize(
208234
("args", "vcf_name"),
209235
[

tests/test_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ def test_boolean_operator_expressions(self, expr, expected):
220220
("a | b", {"a": [0, 1], "b": [1, 1]}, [True, True]),
221221
("a || b", {"a": [0, 1], "b": [1, 1]}, [True, True]),
222222
("(a < 2) & (b > 1)", {"a": [0, 1], "b": [1, 2]}, [False, True]),
223+
# AND has precedence over OR
224+
("t | f & f", {"t": [1], "f": [0]}, [True or False and False]),
225+
("(t | f) & f", {"t": [1], "f": [0]}, [(True or False) and False]),
223226
],
224227
)
225228
def test_boolean_operator_expressions_data(self, expr, data, expected):

vcztools/retrieval.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import collections.abc
22

33

4+
# NOTE: this class is just a skeleton for now. The idea is that this
5+
# will provide readahead, caching etc, and will be the central location
6+
# for fetching bulk Zarr data.
47
class VariantChunkReader(collections.abc.Sequence):
58
"""
69
Retrieve data from a Zarr store and return chunk-by-chunk in the

0 commit comments

Comments
 (0)