Skip to content

Commit

Permalink
Merge pull request #84 from randovania/no-unload-clr
Browse files Browse the repository at this point in the history
Wrapper: Don't unload CLR.
  • Loading branch information
henriquegemignani authored Sep 19, 2023
2 parents 0b8106e + e0da8b1 commit f811c46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
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)

0 comments on commit f811c46

Please sign in to comment.