Skip to content

Commit 3c8da57

Browse files
committed
tests(oligos): Include unit tests for memoryview equivalent of functions offered through cython _oligos module.
1 parent c4d60c8 commit 3c8da57

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

tests/unit/test_oligos.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,52 @@
2929

3030
"""Unit test oligos module."""
3131

32-
from typing import Callable
32+
from functools import wraps
33+
from typing import Any, Callable
3334

3435
import pytest
3536

36-
from designer_dna import oligos
37+
from designer_dna import _oligos, oligos
3738

3839

39-
@pytest.mark.parametrize("function", [oligos.reverse, oligos.reverse_py])
40+
def wrapper(f: Callable[[str], str]) -> Callable[[str], str]:
41+
"""Wrap a function which acts inplace on string."""
42+
43+
@wraps(f)
44+
def inner(s: str, *args) -> str:
45+
b: bytes = s.encode("utf8")
46+
ba: bytearray = bytearray(b)
47+
m: memoryview = memoryview(ba)
48+
49+
f(m, *args)
50+
51+
return ba.decode("utf8")
52+
53+
return inner
54+
55+
56+
def wrap_out(f: Callable[[str], Any]) -> Callable[[str], Any]:
57+
"""Wrap a function which uses a string, but provides a different output."""
58+
59+
@wraps(f)
60+
def inner(s: str, *args) -> Any:
61+
b: bytes = s.encode("utf8")
62+
ba: bytearray = bytearray(b)
63+
m: memoryview = memoryview(ba)
64+
65+
return f(m, *args)
66+
67+
return inner
68+
69+
70+
@pytest.mark.parametrize(
71+
"function",
72+
[
73+
oligos.reverse,
74+
wrapper(_oligos.m_reverse),
75+
oligos.reverse_py,
76+
],
77+
)
4078
@pytest.mark.parametrize(
4179
["seq", "expected"],
4280
[
@@ -67,7 +105,11 @@ def test_reverse(seq: str, expected: str, function: Callable[[str], str]) -> Non
67105

68106
@pytest.mark.parametrize(
69107
"function",
70-
[oligos.complement, oligos.complement_py],
108+
[
109+
oligos.complement,
110+
wrapper(_oligos.m_complement),
111+
oligos.complement_py,
112+
],
71113
)
72114
@pytest.mark.parametrize(
73115
["seq", "dna", "expected"],
@@ -108,7 +150,12 @@ def test_complement(
108150

109151

110152
@pytest.mark.parametrize(
111-
"function", [oligos.reverse_complement, oligos.reverse_complement_py]
153+
"function",
154+
[
155+
oligos.reverse_complement,
156+
wrapper(_oligos.m_reverse_complement),
157+
oligos.reverse_complement_py,
158+
],
112159
)
113160
@pytest.mark.parametrize(
114161
["seq", "dna", "expected"],
@@ -137,7 +184,14 @@ def test_reverse_complement(
137184
assert result == expected, "Unexpected reverse complement."
138185

139186

140-
@pytest.mark.parametrize("function", [oligos.stretch, oligos.stretch_py])
187+
@pytest.mark.parametrize(
188+
"function",
189+
[
190+
oligos.stretch,
191+
wrap_out(_oligos.m_stretch),
192+
oligos.stretch_py,
193+
],
194+
)
141195
@pytest.mark.parametrize(
142196
["seq", "expected"],
143197
[

0 commit comments

Comments
 (0)