mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Replace NamedTemporaryFile with TemporaryDirectory in tests for better compatibility
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# Copyright (C) 2020-2022, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
from tempfile import NamedTemporaryFile
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
import numpy as np
|
||||
from scipy.stats import randint, uniform
|
||||
@@ -86,8 +86,8 @@ def test_set_cover() -> None:
|
||||
build_setcover_model_gurobipy(data),
|
||||
]:
|
||||
assert isinstance(model, AbstractModel)
|
||||
with NamedTemporaryFile() as tempfile:
|
||||
with H5File(tempfile.name) as h5:
|
||||
with TemporaryDirectory() as tempdir:
|
||||
with H5File(f"{tempdir}/data.h5", "w") as h5:
|
||||
model.optimize()
|
||||
model.extract_after_mip(h5)
|
||||
assert h5.get_scalar("mip_obj_value") == 11.0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
|
||||
# Copyright (C) 2020-2022, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
from tempfile import NamedTemporaryFile
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
import networkx as nx
|
||||
import numpy as np
|
||||
@@ -25,8 +25,8 @@ def test_stab() -> None:
|
||||
build_stab_model_pyomo(data),
|
||||
]:
|
||||
assert isinstance(model, AbstractModel)
|
||||
with NamedTemporaryFile() as tempfile:
|
||||
with H5File(tempfile.name) as h5:
|
||||
with TemporaryDirectory() as tempdir:
|
||||
with H5File(f"{tempdir}/data.h5", "w") as h5:
|
||||
model.optimize()
|
||||
model.extract_after_mip(h5)
|
||||
assert h5.get_scalar("mip_obj_value") == -2.0
|
||||
|
||||
Reference in New Issue
Block a user