diff --git a/longbow/apps/namd.py b/longbow/apps/namd.py index 139d3a8..a31b326 100644 --- a/longbow/apps/namd.py +++ b/longbow/apps/namd.py @@ -39,9 +39,10 @@ import os import re - +import logging import longbow.exceptions as exceptions +LOG = logging.getLogger("longbow.apps.namd") EXECDATA = { "namd2": { @@ -88,39 +89,44 @@ def file_parser(filename, path, files, substitutions=None): fil = _fileopen(path, addfile) - # Search every line for possible input files. - for line in fil: + try: + + # Search every line for possible input files. + for line in fil: + + # Remove comments. + if '#' in line: - # Remove comments. - if '#' in line: + words = line[:line.index('#')].split() - words = line[:line.index('#')].split() + else: - else: + words = line[:len(line)].split() - words = line[:len(line)].split() + if len(words) > 0: - if len(words) > 0: + # Pick up substitutions from within file + _internalsubstitutions(variables, words) - # Pick up substitutions from within file - _internalsubstitutions(variables, words) + # If this line is reading in an input file. + if words[0].lower() in keywords: - # If this line is reading in an input file. - if words[0].lower() in keywords: + newfile = words[-1] - newfile = words[-1] + # Do variable substitutons + newfile = _variablesubstitutions(newfile, variables) - # Do variable substitutons - newfile = _variablesubstitutions(newfile, variables) + # Check newfile. + newfile = _newfilechecks(addfile, newfile, path) - # Deduce the location of newfile. - newpath = path + # Recursive function + file_parser(newfile, path, files, substitutions) - # Check newfile. - newfile = _newfilechecks(addfile, newfile, path) + except UnicodeDecodeError: - # Recursive function. - file_parser(newfile, newpath, files, substitutions) + LOG.debug("Couldn't read file '{0}' - this is probably because " + "it is a binary format or unknown encoding" + .format(addfile)) fil.close() diff --git a/longbow/entrypoints.py b/longbow/entrypoints.py index f413500..999b76e 100644 --- a/longbow/entrypoints.py +++ b/longbow/entrypoints.py @@ -70,7 +70,7 @@ import longbow.staging as staging PYTHONVERSION = "{0}.{1}".format(sys.version_info[0], sys.version_info[1]) -LONGBOWVERSION = "1.5.2" +LONGBOWVERSION = "1.5.3-dev" LOG = logging.getLogger("longbow") diff --git a/setup.py b/setup.py index 54471cf..76e41ad 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,7 @@ # Setup setup(name='Longbow', - version='1.5.2', + version='1.5.3-dev', description='Biomolecular simulation remote job submission tool.', long_description=open('README.rst').read(), author='James T Gebbie-Rayet, Gareth B Shannon', diff --git a/tests/standards/namdcoordfile.coor b/tests/standards/namdcoordfile.coor new file mode 100644 index 0000000..bae734e Binary files /dev/null and b/tests/standards/namdcoordfile.coor differ diff --git a/tests/unit/apps_namd/test_namd_fileparser.py b/tests/unit/apps_namd/test_namd_fileparser.py index b223396..c9a902b 100644 --- a/tests/unit/apps_namd/test_namd_fileparser.py +++ b/tests/unit/apps_namd/test_namd_fileparser.py @@ -98,3 +98,42 @@ def test_fileparser_test3(): file_parser(filename, path, files, substitutions) assert files == ["apps_fileparsernamd.txt", "apps_recursivetest.txt"] + + +def test_fileparser_test4(): + + """ + Test with a binary file. + """ + + filename = "namdcoordfile.coor" + path = os.path.join(os.getcwd(), "tests/standards/") + files = [] + substitutions = {} + + file_parser(filename, path, files, substitutions) + + assert files == ["namdcoordfile.coor"] + + +@mock.patch('longbow.apps.namd._internalsubstitutions') +def test_fileparser_test5(subs): + + """ + Test with a binary file check file still added for upload on mocked except. + + This is test is really a bit of a fake, since it is difficult to mock the + exception in the way it is thrown organically. But this test does do the + trick! + """ + + filename = "namdcoordfile.coor" + path = os.path.join(os.getcwd(), "tests/standards/") + files = [] + substitutions = {} + + subs.side_effect = UnicodeDecodeError('blah', b'', 80, 0, '') + + file_parser(filename, path, files, substitutions) + + assert files == ["namdcoordfile.coor"]