22from __future__ import absolute_import
33import logging
44import os
5+ import tempfile
6+ import shutil
57from .. import unittest
68
79import mock
810
911from compose .cli import main
1012from compose .cli .main import TopLevelCommand
13+ from compose .cli .errors import ComposeFileNotFound
1114from six import StringIO
1215
1316
@@ -31,9 +34,9 @@ def test_project_name_with_explicit_base_dir(self):
3134
3235 def test_project_name_with_explicit_uppercase_base_dir (self ):
3336 command = TopLevelCommand ()
34- command .base_dir = 'tests/fixtures/Simple-figfile '
37+ command .base_dir = 'tests/fixtures/UpperCaseDir '
3538 project_name = command .get_project_name (command .get_config_path ())
36- self .assertEquals ('simplefigfile ' , project_name )
39+ self .assertEquals ('uppercasedir ' , project_name )
3740
3841 def test_project_name_with_explicit_project_name (self ):
3942 command = TopLevelCommand ()
@@ -57,12 +60,30 @@ def test_project_name_from_environment_new_var(self):
5760 project_name = command .get_project_name (None )
5861 self .assertEquals (project_name , name )
5962
60- def test_yaml_filename_check (self ):
61- command = TopLevelCommand ()
62- command .base_dir = 'tests/fixtures/longer-filename-composefile'
63- with mock .patch ('compose.cli.command.log' , autospec = True ) as mock_log :
64- self .assertTrue (command .get_config_path ())
65- self .assertEqual (mock_log .warning .call_count , 2 )
63+ def test_filename_check (self ):
64+ self .assertEqual ('docker-compose.yml' , get_config_filename_for_files ([
65+ 'docker-compose.yml' ,
66+ 'docker-compose.yaml' ,
67+ 'fig.yml' ,
68+ 'fig.yaml' ,
69+ ]))
70+
71+ self .assertEqual ('docker-compose.yaml' , get_config_filename_for_files ([
72+ 'docker-compose.yaml' ,
73+ 'fig.yml' ,
74+ 'fig.yaml' ,
75+ ]))
76+
77+ self .assertEqual ('fig.yml' , get_config_filename_for_files ([
78+ 'fig.yml' ,
79+ 'fig.yaml' ,
80+ ]))
81+
82+ self .assertEqual ('fig.yaml' , get_config_filename_for_files ([
83+ 'fig.yaml' ,
84+ ]))
85+
86+ self .assertRaises (ComposeFileNotFound , lambda : get_config_filename_for_files ([]))
6687
6788 def test_get_project (self ):
6889 command = TopLevelCommand ()
@@ -81,3 +102,21 @@ def test_setup_logging(self):
81102 main .setup_logging ()
82103 self .assertEqual (logging .getLogger ().level , logging .DEBUG )
83104 self .assertEqual (logging .getLogger ('requests' ).propagate , False )
105+
106+
107+ def get_config_filename_for_files (filenames ):
108+ project_dir = tempfile .mkdtemp ()
109+ try :
110+ make_files (project_dir , filenames )
111+ command = TopLevelCommand ()
112+ command .base_dir = project_dir
113+ return os .path .basename (command .get_config_path ())
114+ finally :
115+ shutil .rmtree (project_dir )
116+
117+
118+ def make_files (dirname , filenames ):
119+ for fname in filenames :
120+ with open (os .path .join (dirname , fname ), 'w' ) as f :
121+ f .write ('' )
122+
0 commit comments