Skip to content

Commit

Permalink
Add new test for model setLogFile and fix setLogFile(None) error
Browse files Browse the repository at this point in the history
  • Loading branch information
liangbug committed Mar 27, 2024
1 parent 67004c3 commit f13c198
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## Unreleased
### Added
- Add SCIP function SCIPgetTreesizeEstimation and wrapper getTreesizeEstimation
- New test for model setLogFile
### Fixed
- Fixed model.setLogFile(None) error
### Changed
### Removed

Expand Down
34 changes: 34 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import os

from pyscipopt import Model, SCIP_STAGE

Expand Down Expand Up @@ -300,3 +301,36 @@ def test_getTreesizeEstimation():
m.optimize()

assert m.getTreesizeEstimation() > 0

def test_setLogFile():
m = Model()
x = m.addVar("x", vtype="I")
y = m.addVar("y", vtype="I")
m.addCons(x + y == 1)
m.setObjective(2*x+y)

log_file_name = "test_setLogFile.log"
m.setLogfile(log_file_name)
assert os.path.exists(log_file_name)

m.optimize()
del m
assert os.path.getsize(log_file_name) > 0
os.remove(log_file_name)

def test_setLogFile_none():
m = Model()
x = m.addVar("x", vtype="I")
y = m.addVar("y", vtype="I")
m.addCons(x + y == 1)
m.setObjective(2*x+y)

log_file_name = "test_setLogfile_none.log"
m.setLogfile(log_file_name)
assert os.path.exists(log_file_name)

m.setLogfile(None)
m.optimize()
del m
assert os.path.getsize(log_file_name) == 0
os.remove(log_file_name)

0 comments on commit f13c198

Please sign in to comment.