Skip to content

Commit 5ba2a77

Browse files
committed
merge: branch fix-inchi-validation
2 parents a8cc5fa + f91db0d commit 5ba2a77

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ dependencies:
55
- brs_utils
66
- filetype
77
- colored
8+
- pytest

retropath2_wrapper/RetroPath2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ def check_inchi_from_file(
333333
# Other (sub-)layers
334334
# matches:
335335
# (/.+)? --> if '/' is present, then at least one character/symbol is mandatory
336-
# if match('InChI=1(S)?/(([a-z|[A-Z])\d+)+(/.+)?$', inchi) is None:
337-
if match('InChI=1(S)?/(([a-z|[A-Z])+\d+)+(/.+)?$', inchi) is None:
336+
if match('InChI=1(S)?/(([a-z|[A-Z])+\d*)+(/.+)?$', inchi) is None:
338337
logger.error(' {inchi} is not a valid InChI notation'.format(inchi=inchi))
339338
return ''
340339

tests/test_RP2.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
__KNIME_VER__,
1818
__RETROPATH2_KWF__,
1919
set_vars,
20-
gunzip_to_csv
20+
gunzip_to_csv,
21+
check_inchi_from_file
2122
)
2223
from retropath2_wrapper.__main__ import create_logger
2324

@@ -126,3 +127,23 @@ def test_set_vars_None(self):
126127
# self.outdir,
127128
# dmin=16)
128129
# self.assertTrue(cmp(result, self.ref_file))
130+
131+
132+
class TestMethods:
133+
134+
def test_check_inchi_from_file(self, tmpdir):
135+
inchis = [
136+
'InChI=1S/C3H6O/c1-3(2)4/h1-2H3',
137+
'InChI=1S/C14H12O3/c15-12-5-3-10(4-6-12)1-2-11-7-13(16)9-14(17)8-11/h1-9,15-17H/b2-1+',
138+
'InChI=1S/H2O2/c1-2/h1-2H',
139+
'InChI=1S/C4H10O/c1-4(2)3-5/h4-5H,3H2,1-2H3'
140+
]
141+
for inchi in inchis:
142+
tmp_file = Path(tmpdir) / 'source.csv'
143+
with open(tmp_file, 'w') as fh:
144+
fh.write('"Name","InChI"\n')
145+
fh.write(f'"target","{inchi}"')
146+
try:
147+
assert check_inchi_from_file(tmp_file) != ''
148+
except AssertionError as e:
149+
raise e

0 commit comments

Comments
 (0)