Skip to content

Commit

Permalink
Add testcases to autoscale
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Apr 30, 2024
1 parent bfcb4ea commit 0bd3285
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion jcvi/utils/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,11 @@ def human_size(size, a_kilobyte_is_1024_bytes=False, precision=1, target=None):
return "{0:.{1}f}{2}".format(size, precision, suffix)


def autoscale(bp: int, optimal: int = 6):
def autoscale(bp: int, optimal: int = 8):
"""
Autoscale the basepair length to a more human readable number.
The optimal is the number of ticks we want to see on the axis.
>>> autoscale(150000000)
20000000
>>> autoscale(97352632)
Expand Down
21 changes: 14 additions & 7 deletions tests/utils/test_cbook.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import os.path as op
import pytest

from jcvi.apps.base import cleanup
from jcvi.utils.cbook import autoscale, depends, gene_name, seqid_parse


@pytest.mark.parametrize(
"input,output",
[
(150000000, 20000000),
(97352632, 10000000),
],
)
def test_autoscale(input, output):
assert autoscale(input) == output


@pytest.mark.parametrize(
"input,output",
[("AT5G54690.2", "AT5G54690"), ("evm.test.1", "evm.test.1")],
)
def test_gene_name(input, output):
from jcvi.utils.cbook import gene_name

assert gene_name(input) == output


Expand All @@ -25,15 +37,10 @@ def test_gene_name(input, output):
],
)
def test_seqid_parse(seqid, sep, stdpf, output):
from jcvi.utils.cbook import seqid_parse

assert seqid_parse(seqid, sep, stdpf) == output


def test_depends():
from jcvi.apps.base import cleanup
from jcvi.utils.cbook import depends

@depends
def func1(infile="a", outfile="b"):
assert op.exists(infile)
Expand Down

0 comments on commit 0bd3285

Please sign in to comment.