command_test.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. import os
  4. import pytest
  5. from compose.cli.command import get_config_path_from_options
  6. from compose.config.environment import Environment
  7. from compose.const import IS_WINDOWS_PLATFORM
  8. from tests import mock
  9. class TestGetConfigPathFromOptions(object):
  10. def test_path_from_options(self):
  11. paths = ['one.yml', 'two.yml']
  12. opts = {'--file': paths}
  13. environment = Environment.from_env_file('.')
  14. assert get_config_path_from_options('.', opts, environment) == paths
  15. def test_single_path_from_env(self):
  16. with mock.patch.dict(os.environ):
  17. os.environ['COMPOSE_FILE'] = 'one.yml'
  18. environment = Environment.from_env_file('.')
  19. assert get_config_path_from_options('.', {}, environment) == ['one.yml']
  20. @pytest.mark.skipif(IS_WINDOWS_PLATFORM, reason='posix separator')
  21. def test_multiple_path_from_env(self):
  22. with mock.patch.dict(os.environ):
  23. os.environ['COMPOSE_FILE'] = 'one.yml:two.yml'
  24. environment = Environment.from_env_file('.')
  25. assert get_config_path_from_options(
  26. '.', {}, environment
  27. ) == ['one.yml', 'two.yml']
  28. @pytest.mark.skipif(not IS_WINDOWS_PLATFORM, reason='windows separator')
  29. def test_multiple_path_from_env_windows(self):
  30. with mock.patch.dict(os.environ):
  31. os.environ['COMPOSE_FILE'] = 'one.yml;two.yml'
  32. environment = Environment.from_env_file('.')
  33. assert get_config_path_from_options(
  34. '.', {}, environment
  35. ) == ['one.yml', 'two.yml']
  36. def test_no_path(self):
  37. environment = Environment.from_env_file('.')
  38. assert not get_config_path_from_options('.', {}, environment)