Skip to content

Commit eae3612

Browse files
committed
Fix test
1 parent a59cca6 commit eae3612

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

cmdstanpy/utils.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,9 @@ def cmdstan_version() -> Optional[Tuple[int, ...]]:
218218
"""
219219
try:
220220
makefile = os.path.join(cmdstan_path(), 'makefile')
221-
except ValueError:
221+
except ValueError as e:
222222
get_logger().info('No CmdStan installation found.')
223-
return None
224-
225-
if not os.path.exists(makefile):
226-
get_logger().info(
227-
'CmdStan installation %s missing makefile, cannot get version.',
228-
cmdstan_path(),
229-
)
223+
get_logger().debug("%s", e)
230224
return None
231225

232226
with open(makefile, 'r') as fd:

test/test_utils.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import string
1515
import tempfile
1616
import unittest
17-
from pathlib import Path
1817
from test import CustomTestCase
1918

2019
import 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

Comments
 (0)