mirror of
				https://github.com/docker/compose.git
				synced 2025-10-31 19:24:21 +01:00 
			
		
		
		
	Closes: #6890 Some remarks, - `# coding ... utf-8` statements are not needed - isdigit on strings instead of a try-catch. - Default opening mode is read, so we can do `open()` without the `'r'` everywhere - Removed inheritinng from `object` class, it isn't necessary in python3. - `super(ClassName, self)` can now be replaced with `super()` - Use of itertools and `chain` on a couple places dealing with sets. - Used the operator module instead of lambdas when warranted `itemgetter(0)` instead of `lambda x: x[0]` `attrgetter('name')` instead of `lambda x: x.name` - `sorted` returns a list, so no need to use `list(sorted(...))` - Removed `dict()` using dictionary comprehensions whenever possible - Attempted to remove python3.2 support Signed-off-by: alexrecuenco <alejandrogonzalezrecuenco@gmail.com>
		
			
				
	
	
		
			68 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import tempfile
 | |
| 
 | |
| from ddt import data
 | |
| from ddt import ddt
 | |
| 
 | |
| from .. import mock
 | |
| from ..acceptance.cli_test import dispatch
 | |
| from compose.cli.command import get_project
 | |
| from compose.cli.command import project_from_options
 | |
| from compose.config.environment import Environment
 | |
| from tests.integration.testcases import DockerClientTestCase
 | |
| 
 | |
| 
 | |
| @ddt
 | |
| class EnvironmentTest(DockerClientTestCase):
 | |
|     @classmethod
 | |
|     def setUpClass(cls):
 | |
|         super().setUpClass()
 | |
|         cls.compose_file = tempfile.NamedTemporaryFile(mode='w+b')
 | |
|         cls.compose_file.write(bytes("""version: '3.2'
 | |
| services:
 | |
|   svc:
 | |
|     image: busybox:1.31.0-uclibc
 | |
|     environment:
 | |
|       TEST_VARIABLE: ${TEST_VARIABLE}""", encoding='utf-8'))
 | |
|         cls.compose_file.flush()
 | |
| 
 | |
|     @classmethod
 | |
|     def tearDownClass(cls):
 | |
|         super().tearDownClass()
 | |
|         cls.compose_file.close()
 | |
| 
 | |
|     @data('events',
 | |
|           'exec',
 | |
|           'kill',
 | |
|           'logs',
 | |
|           'pause',
 | |
|           'ps',
 | |
|           'restart',
 | |
|           'rm',
 | |
|           'start',
 | |
|           'stop',
 | |
|           'top',
 | |
|           'unpause')
 | |
|     def _test_no_warning_on_missing_host_environment_var_on_silent_commands(self, cmd):
 | |
|         options = {'COMMAND': cmd, '--file': [EnvironmentTest.compose_file.name]}
 | |
|         with mock.patch('compose.config.environment.log') as fake_log:
 | |
|             # Note that the warning silencing and the env variables check is
 | |
|             # done in `project_from_options`
 | |
|             # So no need to have a proper options map, the `COMMAND` key is enough
 | |
|             project_from_options('.', options)
 | |
|             assert fake_log.warn.call_count == 0
 | |
| 
 | |
| 
 | |
| class EnvironmentOverrideFileTest(DockerClientTestCase):
 | |
|     def test_env_file_override(self):
 | |
|         base_dir = 'tests/fixtures/env-file-override'
 | |
|         dispatch(base_dir, ['--env-file', '.env.override', 'up'])
 | |
|         project = get_project(project_dir=base_dir,
 | |
|                               config_path=['docker-compose.yml'],
 | |
|                               environment=Environment.from_env_file(base_dir, '.env.override'),
 | |
|                               override_dir=base_dir)
 | |
|         containers = project.containers(stopped=True)
 | |
|         assert len(containers) == 1
 | |
|         assert "WHEREAMI=override" in containers[0].get('Config.Env')
 | |
|         assert "DEFAULT_CONF_LOADED=true" in containers[0].get('Config.Env')
 | |
|         dispatch(base_dir, ['--env-file', '.env.override', 'down'], None)
 |