1414import string
1515import tempfile
1616import unittest
17- from pathlib import Path
1817from test import CustomTestCase
1918
2019import numpy as np
@@ -201,24 +200,15 @@ def test_cmdstan_version(self):
201200 with tempfile .TemporaryDirectory (
202201 prefix = "cmdstan_tests" , dir = _TMPDIR
203202 ) as tmpdir :
204- tdir = os .path .join (tmpdir , 'tmpdir_xxx' )
205- os .makedirs (tdir )
206- fake_path = os .path .join (tdir , 'cmdstan-2.22.0' )
207- os .makedirs (os .path .join (fake_path ))
208- fake_bin = os .path .join (fake_path , 'bin' )
209- os .makedirs (fake_bin )
210- Path (os .path .join (fake_bin , 'stanc' + EXTENSION )).touch ()
211- with self .modified_environ (CMDSTAN = fake_path ):
212- self .assertTrue (fake_path == cmdstan_path ())
213- expect = (
214- 'CmdStan installation {} missing makefile, '
215- 'cannot get version.' .format (fake_path )
216- )
217- with LogCapture () as log :
218- logging .getLogger ()
219- cmdstan_version ()
220- log .check_present (('cmdstanpy' , 'INFO' , expect ))
221- fake_makefile = os .path .join (fake_path , 'makefile' )
203+ tdir = pathlib .Path (tmpdir ) / 'tmpdir_xxx'
204+ fake_path = tdir / 'cmdstan-2.22.0'
205+ fake_bin = fake_path / 'bin'
206+ fake_bin .mkdir (parents = True )
207+ fake_makefile = fake_path / 'makefile'
208+ fake_makefile .touch ()
209+ (fake_bin / f'stanc{ EXTENSION } ' ).touch ()
210+ with self .modified_environ (CMDSTAN = str (fake_path )):
211+ self .assertTrue (str (fake_path ) == cmdstan_path ())
222212 with open (fake_makefile , 'w' ) as fd :
223213 fd .write ('... CMDSTAN_VERSION := dont_need_no_mmp\n \n ' )
224214 expect = (
@@ -229,6 +219,13 @@ def test_cmdstan_version(self):
229219 logging .getLogger ()
230220 cmdstan_version ()
231221 log .check_present (('cmdstanpy' , 'INFO' , expect ))
222+
223+ fake_makefile .unlink ()
224+ expect = StringComparison ('.*does not contain "makefile".*' )
225+ with LogCapture () as log :
226+ logging .getLogger ()
227+ cmdstan_version ()
228+ log .check_present (('cmdstanpy' , 'DEBUG' , expect ))
232229 cmdstan_path ()
233230
234231
0 commit comments