Skip to content

Commit

Permalink
Fix error in staging of config file
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Apr 3, 2019
1 parent 8157f6a commit eb6db65
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cpp/bmi-c
Submodule bmi-c updated 2 files
+0 −5 bmi/bmi.c
+0 −1 bmi/bmilib.h
4 changes: 2 additions & 2 deletions grpc4bmi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def stage_config_file(filename, input_dir, input_mount_point, home_mounted=False
home_mounted (bool): True if home directory is mounted inside container
"""
fn = filename
is_filename_inside_input_dir = input_dir and abspath(input_dir) < abspath(filename)
is_filename_inside_home_dir = home_mounted and expanduser('~') < abspath(filename)
is_filename_inside_input_dir = input_dir and abspath(filename).startswith(abspath(input_dir))
is_filename_inside_home_dir = home_mounted and abspath(filename).startswith(expanduser('~'))
filename_exists = exists(filename)
if is_filename_inside_input_dir:
# Replace input dir outside container by input dir inside container
Expand Down
44 changes: 44 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest

from grpc4bmi.utils import stage_config_file


class TestStageConfigFile:
def test_inside_inputdir(self, tmpdir):
input_dir = tmpdir.mkdir('input')
c = input_dir.join('config.cfg')
c.write("something")

result = stage_config_file(c, input_dir, input_mount_point='/data/input')
assert result == '/data/input/config.cfg'

def test_outside_inputdir(self, tmpdir):
input_dir = tmpdir.mkdir('input')
c = tmpdir.join('config.cfg')
c.write("something")

result = stage_config_file(c, input_dir, input_mount_point='/data/input')
assert result == '/data/input/config.cfg'

def test_outside_inputdir_beforeconfig(self, tmpdir):
input_dir = tmpdir.mkdir('ainput')
c = tmpdir.join('config.cfg')
c.write("something")

result = stage_config_file(c, input_dir, input_mount_point='/data/input')
assert result == '/data/input/config.cfg'

def test_cfg_in_container(self, tmpdir):
input_dir = tmpdir.mkdir('input')

c = '/somewhere/config.cfg'
result = stage_config_file(c, input_dir, input_mount_point='/data/input')
assert result == c

def test_noinputdir(self, tmpdir):
c = tmpdir.join('config.cfg')
c.write("something")

with pytest.raises(Exception) as exc_info:
stage_config_file(c, None, None)
assert str(exc_info.value).startswith('Unable to copy')

0 comments on commit eb6db65

Please sign in to comment.