command_test.py 1.8 KB

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