Skip to content

Commit

Permalink
[tree] random ascii strain name testing
Browse files Browse the repository at this point in the history
This test generates random ASCII names. It's disabled for CI as it's
both stochastic and slow but you can easily toggle it back on (by
uncommenting the function call) if you want to better test strain name
handling in `augur tree`
  • Loading branch information
jameshadfield committed Feb 10, 2025
1 parent 1283f64 commit c3390c4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/functional/tree/cram/generate-fasta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import random

def get_random_unicode(length):
"""Adapted from <https://stackoverflow.com/a/21666621>"""

try:
get_char = unichr
except NameError:
get_char = chr

# code point ranges to be sampled
include_ranges = [
# ASCII non-control characters excluding single quote (0x27) and backslash (0x5c)
(0x20, 0x26), (0x28, 0x5b), (0x5d, 0x7e)
]

alphabet = [
get_char(code_point) for current_range in include_ranges
for code_point in range(current_range[0], current_range[1] + 1)
]
return ''.join(random.choice(alphabet) for _ in range(length))


if __name__ == "__main__":
for i in range(10):
print('>' + get_random_unicode(5))
print("ATGC")

18 changes: 18 additions & 0 deletions tests/functional/tree/cram/iqtree-name-modifications.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,21 @@ similar to single quotes.
Invalid characters: .* (re)

[2]

This test generates random ASCII names. It's disabled for CI as it's both
stochastic and slow but you can easily toggle it back on (by uncommenting the
function call) if you want to better test strain name handling in `augur tree`

$ random_ascii_names() {
> python3 "$TESTDIR"/generate-fasta.py > random_${1}.mfa
>
> ${AUGUR} tree \
> --method iqtree \
> --alignment random_${1}.mfa \
> --output random_${1}.new > /dev/null
> }

$ for iteration in $(seq 1 100); do
> # random_ascii_names $iteration
> :
> done

0 comments on commit c3390c4

Please sign in to comment.