Skip to content

Commit 0779738

Browse files
author
Alan Christie
committed
- Improves test coverage
1 parent ca6b638 commit 0779738

File tree

5 files changed

+174
-1
lines changed

5 files changed

+174
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
build
88
dist
99
*.pyc
10+
*.tmp
1011
work
1112
.nextflow
1213
.nextflow.log*
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import unittest
3+
4+
from pipelines_utils import BasicObjectWriter
5+
6+
DATA_DIR = os.path.join('test', 'pipelines_utils', 'data')
7+
8+
class BasicObjectWriterTestCase(unittest.TestCase):
9+
10+
def test_basic_operation_with_supplied_uuid(self):
11+
"""Test basic file creation.
12+
"""
13+
filename = 'bow_test_a.tmp'
14+
15+
bow = BasicObjectWriter.BasicObjectWriter(filename)
16+
bow.writeHeader()
17+
bow.write({"A":"a"}, objectUUID="1234567890")
18+
bow.writeFooter()
19+
bow.close()
20+
21+
# Expect something like this: `
22+
# [{"uuid": "1234567890", "values": {"A": "a"}}]`
23+
#
24+
bow_file = open(filename, 'r')
25+
line = bow_file.readline()
26+
self.assertTrue(line.startswith('[{'))
27+
self.assertTrue(line.find('"uuid": "1234567890"') >= 0)
28+
self.assertTrue(line.find('"values": {"A": "a"}') >= 0)
29+
self.assertTrue(line.endswith('}]'))
30+
bow_file.close()
31+
os.remove(filename)
32+
33+
def test_basic_operation_with_generated_uuid(self):
34+
"""Test basic file creation.
35+
"""
36+
filename = 'bow_test_b.tmp'
37+
38+
bow = BasicObjectWriter.BasicObjectWriter(filename)
39+
# Chec file
40+
bow.writeHeader()
41+
bow.write({"A":"a"})
42+
bow.writeFooter()
43+
bow.close()
44+
45+
# Expect something like this: `
46+
# [{"uuid": "1234567890", "values": {"A": "a"}}]`
47+
#
48+
bow_file = open(filename, 'r')
49+
line = bow_file.readline()
50+
self.assertTrue(line.startswith('[{'))
51+
self.assertTrue(line.find('"uuid": ') >= 0)
52+
self.assertTrue(line.find('"values": {"A": "a"}') >= 0)
53+
self.assertTrue(line.endswith('}]'))
54+
bow_file.close()
55+
os.remove(filename)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import unittest
3+
4+
from collections import OrderedDict
5+
6+
from pipelines_utils import TsvWriter
7+
8+
DATA_DIR = os.path.join('test', 'pipelines_utils', 'data')
9+
10+
class TsvWriterTestCase(unittest.TestCase):
11+
12+
def test_basic_operation_with_supplied_uuid(self):
13+
"""Test basic file creation.
14+
"""
15+
filename = 'bow_test_a.tmp'
16+
header = OrderedDict()
17+
header['a'] = 'one'
18+
header['b'] = 'two'
19+
20+
tw = TsvWriter.TsvWriter(filename, header)
21+
tw.writeHeader()
22+
tw.write({'a': '123', 'b': '456'})
23+
tw.writeFooter()
24+
tw.close()
25+
26+
# Expect something like this: `
27+
# [{"uuid": "1234567890", "values": {"A": "a"}}]`
28+
#
29+
tw_file = open(filename, 'r')
30+
line = tw_file.readline()
31+
self.assertEquals('one\ttwo\n', line)
32+
line = tw_file.readline()
33+
self.assertEquals('123\t456\n', line)
34+
tw_file.close()
35+
os.remove(filename)

src/python/test/pipelines_utils/test_parameter_utils.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import unittest
22

3+
import argparse
4+
35
from pipelines_utils import parameter_utils
46

57

@@ -63,3 +65,49 @@ def test_expand_parameters_with_real_data(self):
6365
a, b, c, d, e, f, g = parameter_utils.expandParameters(t1, t2, t3, t4, t5, t6, t7)
6466
self.assertEquals([0.135, 0.675, 1.35], a)
6567
self.assertEquals([0.29, 0.23, 0.23], g)
68+
69+
def test_add_default_input_args_with_short_options(self):
70+
"""Checks ArgParse manipulation.
71+
"""
72+
parser = argparse.ArgumentParser()
73+
74+
parameter_utils.add_default_input_args(parser)
75+
76+
result = parser.parse_args('-i inputfile -if sdf'.split())
77+
self.assertEquals('inputfile', result.input)
78+
self.assertEquals('sdf', result.informat)
79+
80+
def test_add_default_output_args_with_short_options(self):
81+
"""Checks ArgParse manipulation.
82+
"""
83+
parser = argparse.ArgumentParser()
84+
85+
parameter_utils.add_default_output_args(parser)
86+
87+
result = parser.parse_args('-o outputfile -of sdf --meta'.split())
88+
self.assertEquals('outputfile', result.output)
89+
self.assertEquals('sdf', result.outformat)
90+
self.assertTrue(result.meta)
91+
92+
def test_add_default_input_args_with_long_options(self):
93+
"""Checks ArgParse manipulation.
94+
"""
95+
parser = argparse.ArgumentParser()
96+
97+
parameter_utils.add_default_input_args(parser)
98+
99+
result = parser.parse_args('--input inputfile --informat sdf'.split())
100+
self.assertEquals('inputfile', result.input)
101+
self.assertEquals('sdf', result.informat)
102+
103+
def test_add_default_output_args_with_long_options(self):
104+
"""Checks ArgParse manipulation.
105+
"""
106+
parser = argparse.ArgumentParser()
107+
108+
parameter_utils.add_default_output_args(parser)
109+
110+
result = parser.parse_args('--output outputfile --outformat sdf --meta'.split())
111+
self.assertEquals('outputfile', result.output)
112+
self.assertEquals('sdf', result.outformat)
113+
self.assertTrue(result.meta)

src/python/test/pipelines_utils/test_utils.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44

5-
from pipelines_utils import utils
5+
from pipelines_utils import parameter_utils, utils
66

77

88
class UtilsTestCase(unittest.TestCase):
@@ -69,3 +69,37 @@ def test_write_metrics(self):
6969
os.remove(m_filename)
7070
self.assertTrue(found_a)
7171
self.assertTrue(found_b)
72+
73+
def test_generate_molecule_object_dict_without_values(self):
74+
"""Checks molecule object creation without values.
75+
"""
76+
source = 'COCC(=O)NC=1C=CC=C(NC(=O)C)C1'
77+
format = 'smiles'
78+
values = None
79+
80+
m = utils.generate_molecule_object_dict(source, format, values)
81+
82+
self.assertEquals(3, len(m))
83+
self.assertTrue('uuid' in m)
84+
self.assertTrue('source' in m)
85+
self.assertTrue('format' in m)
86+
self.assertEquals('smiles', m['format'])
87+
self.assertEquals(source, m['source'])
88+
89+
def test_generate_molecule_object_dict_with_values(self):
90+
"""Checks molecule object creation with values.
91+
"""
92+
source = 'COCC(=O)NC=1C=CC=C(NC(=O)C)C1'
93+
format = 'smiles'
94+
values = {'a':1}
95+
96+
m = utils.generate_molecule_object_dict(source, format, values)
97+
98+
self.assertEquals(4, len(m))
99+
self.assertTrue('uuid' in m)
100+
self.assertTrue('source' in m)
101+
self.assertTrue('format' in m)
102+
self.assertTrue('values' in m)
103+
self.assertEquals('smiles', m['format'])
104+
self.assertEquals(source, m['source'])
105+
self.assertEquals(values, m['values'])

0 commit comments

Comments
 (0)