mirror of
				https://github.com/docker/compose.git
				synced 2025-10-29 18:23:48 +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>
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import os
 | |
| import shutil
 | |
| import unittest
 | |
| 
 | |
| from docker import ContextAPI
 | |
| 
 | |
| from tests.acceptance.cli_test import dispatch
 | |
| 
 | |
| 
 | |
| class ContextTestCase(unittest.TestCase):
 | |
|     @classmethod
 | |
|     def setUpClass(cls):
 | |
|         cls.docker_dir = os.path.join(os.environ.get("HOME", "/tmp"), '.docker')
 | |
|         if not os.path.exists(cls.docker_dir):
 | |
|             os.makedirs(cls.docker_dir)
 | |
|         f = open(os.path.join(cls.docker_dir, "config.json"), "w")
 | |
|         f.write("{}")
 | |
|         f.close()
 | |
|         cls.docker_config = os.path.join(cls.docker_dir, "config.json")
 | |
|         os.environ['DOCKER_CONFIG'] = cls.docker_config
 | |
|         ContextAPI.create_context("testcontext", host="tcp://doesnotexist:8000")
 | |
| 
 | |
|     @classmethod
 | |
|     def tearDownClass(cls):
 | |
|         shutil.rmtree(cls.docker_dir, ignore_errors=True)
 | |
| 
 | |
|     def setUp(self):
 | |
|         self.base_dir = 'tests/fixtures/simple-composefile'
 | |
|         self.override_dir = None
 | |
| 
 | |
|     def dispatch(self, options, project_options=None, returncode=0, stdin=None):
 | |
|         return dispatch(self.base_dir, options, project_options, returncode, stdin)
 | |
| 
 | |
|     def test_help(self):
 | |
|         result = self.dispatch(['help'], returncode=0)
 | |
|         assert '-c, --context NAME' in result.stdout
 | |
| 
 | |
|     def test_fail_on_both_host_and_context_opt(self):
 | |
|         result = self.dispatch(['-H', 'unix://', '-c', 'default', 'up'], returncode=1)
 | |
|         assert '-H, --host and -c, --context are mutually exclusive' in result.stderr
 | |
| 
 | |
|     def test_fail_run_on_inexistent_context(self):
 | |
|         result = self.dispatch(['-c', 'testcontext', 'up', '-d'], returncode=1)
 | |
|         assert "Couldn't connect to Docker daemon" in result.stderr
 |