Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CmdStanPy

on:
push:
branches:
Expand All @@ -14,7 +14,7 @@ on:
description: 'Version to test'
required: false
default: 'latest'

jobs:
get-cmdstan-version:
# get the latest cmdstan version to use as part of the cache key
Expand Down Expand Up @@ -81,11 +81,15 @@ jobs:
- name: Show libraries
run: python -m pip freeze

- name: Get system info
uses: kenchan0130/actions-system-info@v1.0.0
id: system-info

- name: CmdStan installation cacheing
uses: actions/cache@v2
with:
path: ~/.cmdstan
key: ${{ runner.os }}-cmdstan-${{ needs.get-cmdstan-version.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }}
key: ${{ runner.os }}-${{ steps.system-info.outputs.release }}-cmdstan-${{ needs.get-cmdstan-version.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }}

- name: Install CmdStan (Linux, macOS)
if: matrix.os != 'windows-latest'
Expand Down
6 changes: 4 additions & 2 deletions cmdstanpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,10 @@ def pushd(new_dir: str) -> Iterator[None]:
"""Acts like pushd/popd."""
previous_dir = os.getcwd()
os.chdir(new_dir)
yield
os.chdir(previous_dir)
try:
yield
finally:
os.chdir(previous_dir)


def report_signal(sig: int) -> None:
Expand Down
12 changes: 12 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
validate_dir,
windows_short_path,
write_stan_json,
pushd,
)

HERE = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -807,6 +808,17 @@ def test_exit(self):
do_command(args, HERE)


class PushdTest(unittest.TestCase):

def test_restore_cwd(self):
"Ensure do_command in a different cwd restores cwd after error."
cwd = os.getcwd()
with self.assertRaises(RuntimeError):
with pushd(os.path.dirname(cwd)):
raise RuntimeError('error')
self.assertEqual(cwd, os.getcwd())


class FlattenTest(unittest.TestCase):
def test_good(self):
array_3d = np.empty((200, 4, 4))
Expand Down