Skip to content

Commit

Permalink
trying to manage the temp dir using the tempfilemanager as a context
Browse files Browse the repository at this point in the history
  • Loading branch information
DLWoodruff committed Mar 29, 2024
1 parent 485cddc commit 9f624d6
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions pyomo/contrib/iis/tests/test_mis.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,25 @@ def _test_mis(solver_name):
m = _get_infeasible_model()
opt = pyo.SolverFactory(solver_name)

TempfileManager.push()
tmp_path = TempfileManager.create_tempdir()
file_name = os.path.join(tmp_path, f"{solver_name}_mis.log")
logger = logging.getLogger(f"test_mis_{solver_name}")
logger.setLevel(logging.INFO)
# create file handler which logs even debug messages
print(f"{file_name =}")
fh = logging.FileHandler(file_name)
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)

mis.compute_infeasibility_explanation(m, opt, logger=logger)
_check_output(file_name)
# logging.getLogger().removeHandler(logging.getLogger().handlers[0])
logger.removeHandler(logger.handlers[0])

TempfileManager.pop()
####TempfileManager.push()
####tmp_path = TempfileManager.create_tempdir()
with TempfileManager.new_context() as tmpmgr:
tmp_path = tmpmgr.mkdtemp()
file_name = os.path.join(tmp_path, f"{solver_name}_mis.log")
logger = logging.getLogger(f"test_mis_{solver_name}")
logger.setLevel(logging.INFO)
# create file handler which logs even debug messages
print(f"{file_name =}")
fh = logging.FileHandler(file_name)
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)

mis.compute_infeasibility_explanation(m, opt, logger=logger)
_check_output(file_name)
# logging.getLogger().removeHandler(logging.getLogger().handlers[0])
logger.removeHandler(logger.handlers[0])

####TempfileManager.pop()


if __name__ == "__main__":
Expand Down

0 comments on commit 9f624d6

Please sign in to comment.