Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions longbow/apps/namd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@

import os
import re

import logging
import longbow.exceptions as exceptions

LOG = logging.getLogger("longbow.apps.namd")

EXECDATA = {
"namd2": {
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion longbow/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Binary file added tests/standards/namdcoordfile.coor
Binary file not shown.
39 changes: 39 additions & 0 deletions tests/unit/apps_namd/test_namd_fileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]