Injecting os.environ in Environment instance happens outside of init method

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2016-03-22 15:42:30 -07:00
commit 12ad3ff301
5 changed files with 29 additions and 19 deletions

View file

@ -90,7 +90,9 @@ class DockerClientTestCase(unittest.TestCase):
if 'command' not in kwargs:
kwargs['command'] = ["top"]
kwargs['environment'] = resolve_environment(kwargs, Environment())
kwargs['environment'] = resolve_environment(
kwargs, Environment.from_env_file(None)
)
labels = dict(kwargs.setdefault('labels', {}))
labels['com.docker.compose.test-name'] = self.id()

View file

@ -37,7 +37,9 @@ def make_service_dict(name, service_dict, working_dir, filename=None):
filename=filename,
name=name,
config=service_dict),
config.ConfigFile(filename=filename, config={}))
config.ConfigFile(filename=filename, config={}),
environment=Environment.from_env_file(working_dir)
)
return config.process_service(resolver.run())
@ -2061,7 +2063,9 @@ class EnvTest(unittest.TestCase):
},
}
self.assertEqual(
resolve_environment(service_dict, Environment()),
resolve_environment(
service_dict, Environment.from_env_file(None)
),
{'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': 'E3', 'NO_DEF': None},
)
@ -2099,7 +2103,8 @@ class EnvTest(unittest.TestCase):
os.environ['ENV_DEF'] = 'E3'
self.assertEqual(
resolve_environment(
{'env_file': ['tests/fixtures/env/resolve.env']}, Environment()
{'env_file': ['tests/fixtures/env/resolve.env']},
Environment.from_env_file(None)
),
{
'FILE_DEF': u'bär',

View file

@ -20,7 +20,7 @@ def mock_env():
def test_interpolate_environment_variables_in_services(mock_env):
services = {
'servivea': {
'servicea': {
'image': 'example:${USER}',
'volumes': ['$FOO:/target'],
'logging': {
@ -32,7 +32,7 @@ def test_interpolate_environment_variables_in_services(mock_env):
}
}
expected = {
'servivea': {
'servicea': {
'image': 'example:jenny',
'volumes': ['bar:/target'],
'logging': {
@ -44,7 +44,7 @@ def test_interpolate_environment_variables_in_services(mock_env):
}
}
assert interpolate_environment_variables(
services, 'service', Environment()
services, 'service', Environment.from_env_file(None)
) == expected
@ -70,5 +70,5 @@ def test_interpolate_environment_variables_in_volumes(mock_env):
'other': {},
}
assert interpolate_environment_variables(
volumes, 'volume', Environment()
volumes, 'volume', Environment.from_env_file(None)
) == expected