Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapper: Don't unload CLR. #84

Merged
merged 1 commit into from
Sep 19, 2023
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
8 changes: 1 addition & 7 deletions am2r_yams/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,14 @@ def _load_cs_environment():

clr.AddReference("YAMS-LIB")

def _unload_cs_environment():
# Unload dotnet runtime
unload()

@contextmanager
def load_wrapper() -> Wrapper:
try:
_load_cs_environment()
from YAMS_LIB import Patcher as CSharp_Patcher
yield Wrapper(CSharp_Patcher)
except Exception as e:
raise YamsException(str(e)) from None
finally:
_unload_cs_environment
raise e


def _prepare_environment_and_get_data_win_path(folder: str) -> Path:
Expand Down
15 changes: 7 additions & 8 deletions am2r_yams_tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
@pytest.fixture(scope="session", autouse=True)
def _mock_load_unload():
with patch("am2r_yams.wrapper._load_cs_environment") as mocked_load:
with patch("am2r_yams.wrapper._unload_cs_environment") as mocked_unload:
load("coreclr")
import clr
load("coreclr")
import clr

clr.AddReference("YAMS-LIB")
from YAMS_LIB import Patcher as CSharp_Patcher
clr.AddReference("YAMS-LIB")
from YAMS_LIB import Patcher as CSharp_Patcher

yield
unload()
yield
unload()


def test_correct_versions():
Expand All @@ -38,5 +37,5 @@ def test_throw_correct_exception():

raise System.Exception("Dummy Exception")

assert excinfo.type is YamsException
assert excinfo.type is System.Exception
assert "Dummy Exception" == str(excinfo.value)
Loading