|
29 | 29 |
|
30 | 30 | """Unit test oligos module.""" |
31 | 31 |
|
32 | | -from typing import Callable |
| 32 | +from functools import wraps |
| 33 | +from typing import Any, Callable |
33 | 34 |
|
34 | 35 | import pytest |
35 | 36 |
|
36 | | -from designer_dna import oligos |
| 37 | +from designer_dna import _oligos, oligos |
37 | 38 |
|
38 | 39 |
|
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 | +) |
40 | 78 | @pytest.mark.parametrize( |
41 | 79 | ["seq", "expected"], |
42 | 80 | [ |
@@ -67,7 +105,11 @@ def test_reverse(seq: str, expected: str, function: Callable[[str], str]) -> Non |
67 | 105 |
|
68 | 106 | @pytest.mark.parametrize( |
69 | 107 | "function", |
70 | | - [oligos.complement, oligos.complement_py], |
| 108 | + [ |
| 109 | + oligos.complement, |
| 110 | + wrapper(_oligos.m_complement), |
| 111 | + oligos.complement_py, |
| 112 | + ], |
71 | 113 | ) |
72 | 114 | @pytest.mark.parametrize( |
73 | 115 | ["seq", "dna", "expected"], |
@@ -108,7 +150,12 @@ def test_complement( |
108 | 150 |
|
109 | 151 |
|
110 | 152 | @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 | + ], |
112 | 159 | ) |
113 | 160 | @pytest.mark.parametrize( |
114 | 161 | ["seq", "dna", "expected"], |
@@ -137,7 +184,14 @@ def test_reverse_complement( |
137 | 184 | assert result == expected, "Unexpected reverse complement." |
138 | 185 |
|
139 | 186 |
|
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 | +) |
141 | 195 | @pytest.mark.parametrize( |
142 | 196 | ["seq", "expected"], |
143 | 197 | [ |
|
0 commit comments