Skip to content

Commit 5d18550

Browse files
committed
add python module unittest code
1 parent 29a51af commit 5d18550

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ build/
55
cmake-build-release
66
python/docs/_build
77
python/docs/_generate
8+
*.cobs_cache
9+
*.cobs_classic
10+
*.cobs_compact

python/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

python/tests/cobs_index_test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import unittest
2+
import os
3+
4+
import cobs_index as cobs
5+
6+
mydir = os.path.dirname(os.path.realpath(__file__))
7+
datadir = os.path.realpath(mydir + "/../../tests/data")
8+
9+
class MainTest(unittest.TestCase):
10+
# read a directory containing FastA files
11+
def test_doc_list(self):
12+
l = cobs.doc_list(datadir + "/fasta")
13+
self.assertEqual(l.size(), 7)
14+
15+
# construct classic index and run queries
16+
def test_classic_construct_query(self):
17+
index_file = datadir + "/python_test.cobs_classic"
18+
19+
# construct classic index
20+
p = cobs.ClassicIndexParameters()
21+
p.clobber = True
22+
cobs.classic_construct(
23+
input=datadir + "/fasta",
24+
out_file=index_file,
25+
index_params=p)
26+
self.assertTrue(os.path.isfile(index_file))
27+
28+
# TODO: run queries
29+
30+
# construct compact index and run queries
31+
def test_compact_construct_query(self):
32+
index_file = datadir + "/python_test.cobs_compact"
33+
34+
# construct compact index
35+
p = cobs.CompactIndexParameters()
36+
p.clobber = True
37+
cobs.compact_construct(
38+
input=datadir + "/fasta",
39+
out_file=index_file,
40+
index_params=p)
41+
self.assertTrue(os.path.isfile(index_file))
42+
43+
# TODO: run queries
44+
45+
if __name__ == '__main__':
46+
unittest.main()

setup.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
import sys
44
import platform
55
import subprocess
6+
import unittest
67

78
from setuptools import setup, Extension
89
from setuptools.command.build_ext import build_ext
910
from distutils.version import LooseVersion
1011

11-
1212
class CMakeExtension(Extension):
1313
def __init__(self, name, sourcedir=''):
1414
Extension.__init__(self, name, sources=[])
1515
self.sourcedir = os.path.abspath(sourcedir)
1616

17-
1817
class CMakeBuild(build_ext):
1918
def run(self):
2019
try:
@@ -56,15 +55,22 @@ def build_extension(self, ext):
5655
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
5756
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
5857

59-
setup(
60-
name='cobs_index',
61-
version='0.1',
62-
author='Timo Bingmann',
63-
author_email='tbdev@panthema.net',
64-
description='Compact Bit-Sliced Signature Index (COBS)',
65-
long_description='',
66-
url="https://github.com/bingmann/cobs",
67-
ext_modules=[CMakeExtension('cobs_index')],
68-
cmdclass=dict(build_ext=CMakeBuild),
69-
zip_safe=False,
70-
)
58+
def test_suite():
59+
test_loader = unittest.TestLoader()
60+
test_suite = test_loader.discover('python/tests', pattern='*_test.py')
61+
return test_suite
62+
63+
if __name__ == '__main__':
64+
setup(
65+
name='cobs_index',
66+
version='0.1',
67+
author='Timo Bingmann',
68+
author_email='tbdev@panthema.net',
69+
description='Compact Bit-Sliced Signature Index (COBS)',
70+
long_description='',
71+
url="https://github.com/bingmann/cobs",
72+
ext_modules=[CMakeExtension('cobs_index')],
73+
cmdclass=dict(build_ext=CMakeBuild),
74+
zip_safe=False,
75+
test_suite='setup.test_suite',
76+
)

0 commit comments

Comments
 (0)