-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dates: Remove unused is_date_ambiguous()
The re-implementation of augur filter accounts for this directly in filter_by_ambiguous_date(). Remove old tests and add equivalent tests. Note that some date strings have been changed since the previous values would fail date format validation.
- Loading branch information
Showing
5 changed files
with
77 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import argparse | ||
import shlex | ||
from augur.filter import register_arguments | ||
|
||
|
||
def parse_args(args: str): | ||
parser = argparse.ArgumentParser() | ||
register_arguments(parser) | ||
return parser.parse_args(shlex.split(args)) | ||
|
||
|
||
def write_metadata(tmpdir, metadata): | ||
fn = str(tmpdir / "metadata.tsv") | ||
with open(fn, "w") as fh: | ||
fh.write("\n".join(("\t".join(md) for md in metadata))) | ||
return fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This file contains functional tests that would normally be written as | ||
# Cram-style tests. However, pytest is nice here since it is easy to use with | ||
# parameterized inputs/outputs (not straightforward to set up for Cram tests¹). | ||
# ¹ https://github.com/nextstrain/augur/pull/1183#discussion_r1142687476 | ||
|
||
import pytest | ||
|
||
from augur.errors import AugurError | ||
from augur.filter._run import run | ||
|
||
from . import parse_args, write_metadata | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"date, ambiguity", | ||
[ | ||
# Test complete date strings with ambiguous values. | ||
("2019-0X-0X", "any"), | ||
("2019-XX-XX", "month"), | ||
("2019-XX-XX", "day"), | ||
("2019-03-XX", "day"), | ||
("201X-XX-XX", "year"), | ||
("201X-XX-XX", "month"), | ||
("201X-XX-XX", "day"), | ||
# Test incomplete date strings with ambiguous values. | ||
("2019", "month"), | ||
("2019", "day"), | ||
("2019", "any"), | ||
("201X", "year"), | ||
("201X", "month"), | ||
("201X", "day"), | ||
("201X", "any"), | ||
], | ||
) | ||
def test_date_is_dropped(tmpdir, date, ambiguity): | ||
metadata = write_metadata(tmpdir, (("strain","date"), | ||
("SEQ1" , date))) | ||
args = parse_args(f'--metadata {metadata} --exclude-ambiguous-dates-by {ambiguity}') | ||
with pytest.raises(AugurError, match="All samples have been dropped"): | ||
run(args) | ||
|
||
@pytest.mark.parametrize( | ||
"date, ambiguity", | ||
[ | ||
# Test complete date strings without the specified level of ambiguity. | ||
("2019-09-03", "any"), | ||
("2019-03-XX", "month"), | ||
("2019-09-03", "day"), | ||
("2019-XX-XX", "year"), | ||
# Test incomplete date strings without the specified level of ambiguity. | ||
("2019", "year"), | ||
], | ||
) | ||
def test_date_is_not_dropped(tmpdir, date, ambiguity): | ||
metadata = write_metadata(tmpdir, (("strain","date"), | ||
("SEQ1" , date))) | ||
args = parse_args(f'--metadata {metadata} --exclude-ambiguous-dates-by {ambiguity}') | ||
run(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters