Skip to content

Commit 98955d9

Browse files
authored
extend tests to py2.7 (#15)
* extend tests to py2.7 * also remove --cov for old py27 * fix import for py27 * try to fix syntax for py27 * some additional work to function with old python 2.7 and also slightly more modern python 3.x * more elegant conversion * remove leftover * make import StringIO compatible
1 parent fb44b4e commit 98955d9

File tree

6 files changed

+40
-31
lines changed

6 files changed

+40
-31
lines changed

.github/workflows/qiita-plugin-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.5", "3.6", "3.9", "3.10", "3.11", "3.12"]
14+
python-version: ["2.7", "3.5", "3.6", "3.9", "3.10", "3.11", "3.12"]
1515
steps:
1616
# Downloads a copy of the code in your repository before running CI tests
1717
- name: Check out repository code
@@ -35,7 +35,7 @@ jobs:
3535
shell: bash -l {0}
3636
run: |
3737
conda activate qiita-files
38-
pytest --doctest-modules --cov=qiita_files `if (( $(echo "${{ matrix.python-version }} > 3.6" | bc -l) )); then echo "--cov-report=lcov"; else echo ""; fi`
38+
pytest --doctest-modules `if (( $(echo "${{ matrix.python-version }} > 3.6" | bc -l) )); then echo "--cov-report=lcov --cov=qiita_files"; else echo ""; fi`
3939
4040
lint:
4141
runs-on: ubuntu-latest

qiita_files/parse/fastq.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
import numpy as np
1010
from qiita_files.util import open_file
11-
from itertools import zip_longest
11+
try:
12+
from itertools import zip_longest
13+
except ImportError:
14+
from itertools import izip_longest as zip_longest
1215

1316

1417
def _ascii_to_phred(s, offset):

qiita_files/parse/tests/test_fastq.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class ParseFastqTestsInputIsFileNames(FileData, ParseFastqTests, TestCase):
155155
}
156156

157157

158-
FASTQ_EXAMPLE = rb"""@GAPC_0015:6:1:1259:10413#0/1
158+
FASTQ_EXAMPLE = r"""@GAPC_0015:6:1:1259:10413#0/1
159159
AACACCAAACTTCTCCACCACGTGAGCTACAAAAG
160160
+GAPC_0015:6:1:1259:10413#0/1
161161
````Y^T]`]c^cabcacc`^Lb^ccYT\T\Y\WF
@@ -194,26 +194,26 @@ class ParseFastqTestsInputIsFileNames(FileData, ParseFastqTests, TestCase):
194194
@GAPC_0015:6:1:1317:3403#0/1
195195
TTGTTTCCACTTGGTTGATTTCACCCCTGAGTTTG
196196
+GAPC_0015:6:1:1317:3403#0/1
197-
\\\ZTYTSaLbb``\_UZ_bbcc`cc^[ac\a\Tc"""
197+
\\\ZTYTSaLbb``\_UZ_bbcc`cc^[ac\a\Tc""".encode("utf-8")
198198

199199

200-
FASTQ_EXAMPLE_2 = rb"""@GAPC_0017:6:1:1259:10413#0/1
200+
FASTQ_EXAMPLE_2 = r"""@GAPC_0017:6:1:1259:10413#0/1
201201
AACACCAAACTTCTCCACCACGTGAGCTACAAAAG
202202
+GAPC_0015:6:1:1259:10413#0/1
203203
````Y^T]`]c^cabcacc`^Lb^ccYT\T\Y\WF
204204
@GAPC_0015:6:1:1283:11957#0/1
205205
TATGTATATATAACATATACATATATACATACATA
206206
+GAPC_0015:6:1:1283:11957#0/1
207207
]KZ[PY]_[YY^```ac^\\`bT``c`\aT``bbb
208-
"""
208+
""".encode("utf-8")
209209

210210

211-
FASTQ_EXAMPLE_3 = rb"""@GAPC_0017:6:1:1259:10413#0/1
211+
FASTQ_EXAMPLE_3 = r"""@GAPC_0017:6:1:1259:10413#0/1
212212
AACACCAAACTTCTCCACCACGTGAGCTACAAAAG
213213
+GAPC_0015:6:1:1259:10413#0/1
214214
````Y^T]`]c^cabcacc`^Lb^ccYT\T\Y\WF
215215
@GAPC_0015:6:1:1283:11957#0/1
216-
"""
216+
""".encode("utf-8")
217217

218218

219219
if __name__ == "__main__":

qiita_files/parse/tests/test_iterator.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -276,61 +276,61 @@ def test_fastq_gen(self):
276276
self.assertEqual(obs3, exp3)
277277

278278

279-
fasta1 = rb""">1
279+
fasta1 = r""">1
280280
aattggcc
281281
>2
282282
aattaatt
283-
"""
283+
""".encode("utf-8")
284284

285-
fasta2 = rb""">3
285+
fasta2 = r""">3
286286
atat
287-
"""
287+
""".encode("utf-8")
288288

289-
fasta3 = rb""">4
289+
fasta3 = r""">4
290290
attatt
291291
>5
292292
ggccc
293-
"""
293+
""".encode("utf-8")
294294

295-
qual1 = rb""">1
295+
qual1 = r""">1
296296
1 2 3 4 5 6 7 8
297297
>2
298298
8 7 6 5 4 3 2 1
299-
"""
299+
""".encode("utf-8")
300300

301-
qual2 = rb""">3
301+
qual2 = r""">3
302302
1 2 3 4
303-
"""
303+
""".encode("utf-8")
304304

305-
qual3 = rb""">4
305+
qual3 = r""">4
306306
1 2 3 4 5 6
307307
>5
308308
1 2 3 4 5
309-
"""
309+
""".encode("utf-8")
310310

311-
qual_bad_val = rb""">3
311+
qual_bad_val = r""">3
312312
1 2
313-
"""
313+
""".encode("utf-8")
314314

315-
qual_bad_id = rb""">asdasd
315+
qual_bad_id = r""">asdasd
316316
1 2 3 4
317-
"""
317+
""".encode("utf-8")
318318

319-
fastq1 = rb"""@1
319+
fastq1 = r"""@1
320320
atat
321321
+
322322
ABCD
323323
@2
324324
atgc
325325
+
326326
BCDE
327-
"""
327+
""".encode("utf-8")
328328

329-
fastq2 = rb"""@3
329+
fastq2 = r"""@3
330330
taa
331331
+
332332
EFG
333-
"""
333+
""".encode("utf-8")
334334

335335

336336
if __name__ == '__main__':

qiita_files/tests/test_util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88
# -----------------------------------------------------------------------------
99

1010
import os
11+
import sys
1112
from unittest import TestCase, main
1213
import tempfile
1314

1415
import h5py
15-
from io import StringIO, BytesIO
16+
if sys.version_info[0] == 2:
17+
from StringIO import StringIO
18+
else:
19+
from io import StringIO
20+
from io import BytesIO
1621

1722
from qiita_files.util import (open_file, _is_string_or_bytes)
1823

@@ -25,7 +30,7 @@ class TestFilePathOpening(TestCase):
2530
"""Tests adapted from scikit-bio's skbio.io.util tests"""
2631
def test_is_string_or_bytes(self):
2732
self.assertTrue(_is_string_or_bytes('foo'))
28-
self.assertTrue(_is_string_or_bytes(u'foo'))
33+
self.assertTrue(_is_string_or_bytes(u'foo'.encode("utf-8")))
2934
self.assertTrue(_is_string_or_bytes(b'foo'))
3035
self.assertFalse(_is_string_or_bytes(StringIO('bar')))
3136
self.assertFalse(_is_string_or_bytes([1]))

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Topic :: Software Development :: Libraries :: Application Frameworks
1919
Topic :: Software Development :: Libraries :: Python Modules
2020
Programming Language :: Python
21+
Programming Language :: Python :: 2.7
2122
Programming Language :: Python :: 3.5
2223
Programming Language :: Python :: 3.6
2324
Programming Language :: Python :: 3.9

0 commit comments

Comments
 (0)