command_test.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.const import IS_WINDOWS_PLATFORM
  7. from tests import mock
  8. class TestGetConfigPathFromOptions(object):
  9. def test_path_from_options(self):
  10. paths = ['one.yml', 'two.yml']
  11. opts = {'--file': paths}
  12. assert get_config_path_from_options(opts) == paths
  13. def test_single_path_from_env(self):
  14. with mock.patch.dict(os.environ):
  15. os.environ['COMPOSE_FILE'] = 'one.yml'
  16. assert get_config_path_from_options({}) == ['one.yml']
  17. @pytest.mark.skipif(IS_WINDOWS_PLATFORM, reason='posix separator')
  18. def test_multiple_path_from_env(self):
  19. with mock.patch.dict(os.environ):
  20. os.environ['COMPOSE_FILE'] = 'one.yml:two.yml'
  21. assert get_config_path_from_options({}) == ['one.yml', 'two.yml']
  22. @pytest.mark.skipif(not IS_WINDOWS_PLATFORM, reason='windows separator')
  23. def test_multiple_path_from_env_windows(self):
  24. with mock.patch.dict(os.environ):
  25. os.environ['COMPOSE_FILE'] = 'one.yml;two.yml'
  26. assert get_config_path_from_options({}) == ['one.yml', 'two.yml']
  27. def test_no_path(self):
  28. assert not get_config_path_from_options({})