Skip to content

Commit

Permalink
Fix logging issues in Julia1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mtanneau authored and dpo committed Mar 30, 2020
1 parent 669bdc0 commit 7ec0029
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 deletions.
20 changes: 9 additions & 11 deletions src/readqps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ function read_rows_line!(qps::QPSData, card::MPSCard)

if rtype == RTYPE_N
# Objective row
if isnothing(qps.objname)
if qps.objname === nothing
# Record objective
qps.objname = rowname
qps.conindices[rowname] = 0
@info "Using '$rowname' as objective (l. $(card.nline))"
else
# Record name but ignore input
@warn "Detected rim objective row $rowname at line $(card.nline)"
Expand Down Expand Up @@ -371,9 +372,10 @@ function read_rhs_line!(qps::QPSData, card::MPSCard)
)

rhs = card.f2
if isnothing(qps.rhsname)
if qps.rhsname === nothing
# Record this as the RHS
qps.rhsname = rhs
@info "Using '$rhs' as RHS (l. $(card.nline))"
elseif qps.rhsname != rhs
# Rim RHS, ignore this line
@error "Skipping line $(card.nline) with rim RHS $rhs"
Expand Down Expand Up @@ -452,9 +454,10 @@ function read_ranges_line!(qps::QPSData, card::MPSCard)
)

rng = card.f2
if isnothing(qps.rngname)
if qps.rngname === nothing
# Record this as the RANGES
qps.rngname = rng
@info "Using '$rng' as RANGES (l. $(card.nline))"
elseif qps.rngname != rng
# Rim RANGES, ignore this line
@error "Skipping line $(card.nline) with rim RANGES $rng"
Expand Down Expand Up @@ -521,9 +524,10 @@ function read_bounds_line!(qps::QPSData, card::MPSCard)
)

bnd = card.f2
if isnothing(qps.bndname)
if qps.bndname === nothing
# Record this as the BOUNDS
qps.bndname = bnd
@info "Using '$bnd' as BOUNDS (l. $(card.nline))"
elseif qps.bndname != bnd
# Rim BOUNDS, ignore this line
@error "Skipping line $(card.nline) with rim bound $bnd"
Expand Down Expand Up @@ -641,6 +645,7 @@ function readqps(filename::String)
name_section_read && error("more than one NAME section specified")
qpsdat.name = card.f2
name_section_read = true
@info "Using '$(qpsdat.name)' as NAME (l. $(card.nline))"
elseif sec == OBJ_SENSE
objsense_section_read && error("more than one OBJSENSE section specified")
objsense_section_read = true
Expand Down Expand Up @@ -704,12 +709,5 @@ function readqps(filename::String)

endata_read || @error("reached end of file before ENDATA section")

@info("Problem name : $(qpsdat.name)")
@info("Objective sense : $(qpsdat.objsense)")
@info("Objective name : $(qpsdat.objname)")
rhs_section_read && @info("RHS : $(qpsdat.rhsname)")
ranges_section_read && @info("RANGES : $(qpsdat.rngname)")
bounds_section_read && @info("BOUNDS : $(qpsdat.bndname)")

return qpsdat
end
2 changes: 1 addition & 1 deletion test/dat/rim_bnd.qps
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NAME RimObj
NAME RimBOUNDS
ROWS
N obj
G r1
Expand Down
12 changes: 5 additions & 7 deletions test/qp-example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ using SparseArrays
# Note that logs won't display since they are captured by the test macro
qp = @test_logs(
# These logs must appear in exactly this order
(:info, "Problem name : QP example"),
(:info, "Objective sense : notset"),
(:info, "Objective name : obj"),
(:info, "RHS : rhs1"),
(:info, "RANGES : nothing"),
(:info, "BOUNDS : bnd1"),
(:info, "Using 'QP example' as NAME (l. 1)"),
(:info, "Using 'obj' as objective (l. 3)"),
(:info, "Using 'rhs1' as RHS (l. 12)"),
(:info, "Using 'bnd1' as BOUNDS (l. 16)"),
match_mode = :all,
readqps("dat/qp-example.qps")
)
Expand All @@ -25,7 +23,7 @@ using SparseArrays
@test qp.objname == "obj"
@test qp.rhsname == "rhs1"
@test qp.bndname == "bnd1"
@test isnothing(qp.rngname)
@test qp.rngname === nothing

@test qp.nvar == 2
@test qp.ncon == 2
Expand Down
32 changes: 13 additions & 19 deletions test/rimdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
@testset "Objective" begin

qp = @test_logs(
(:info, "Using 'RimObj' as NAME (l. 1)"),
(:info, "Using 'obj1' as objective (l. 3)"),
(:warn, "Detected rim objective row obj2 at line 4"),
(:warn, "Detected rim objective row obj3 at line 7"),
(:error, "Ignoring coefficient (obj2, c1) with value 2.2 at line 10"),
(:error, "Ignoring coefficient (obj2, c2) with value -2.2 at line 12"),
(:error, "Ignoring coefficient (obj3, c1) with value 2.3 at line 13"),
(:error, "Ignoring coefficient (obj3, c2) with value -2.3 at line 14"),
(:info, "Using 'rhs1' as RHS (l. 16)"),
(:error, "Ignoring RHS for rim objective obj2 at line 16"),
(:info, "Problem name : RimObj"),
(:info, "Objective sense : notset"),
(:info, "Objective name : obj1"),
(:info, "RHS : rhs1"),
match_mode = :all,
readqps("dat/rim_obj.qps")
)
Expand All @@ -37,13 +36,12 @@
@testset "RHS" begin
qp = @test_logs(
# These logs should appear in exactly this order
(:info, "Using 'RimRHS' as NAME (l. 1)"),
(:info, "Using 'obj1' as objective (l. 3)"),
(:info, "Using 'rhs1' as RHS (l. 12)"),
(:error, "Skipping line 13 with rim RHS rhs2"),
(:error, "Skipping line 15 with rim RHS rhs2"),
(:error, "Skipping line 16 with rim RHS rhs3"),
(:info, "Problem name : RimRHS"),
(:info, "Objective sense : notset"),
(:info, "Objective name : obj1"),
(:info, "RHS : rhs1"),
match_mode = :all,
readqps("dat/rim_rhs.qps")
)
Expand All @@ -59,13 +57,11 @@
@testset "Range" begin
qp = @test_logs(
# These logs should appear in exactly this order
# (:warn, "Detected rim range rng2"),
(:info, "Using 'RimRANGES' as NAME (l. 1)"),
(:info, "Using 'obj1' as objective (l. 3)"),
(:info, "Using 'rhs1' as RHS (l. 12)"),
(:info, "Using 'rng1' as RANGES (l. 15)"),
(:error, "Skipping line 16 with rim RANGES rng2"),
(:info, "Problem name : RimRANGES"),
(:info, "Objective sense : notset"),
(:info, "Objective name : obj1"),
(:info, "RHS : rhs1"),
(:info, "RANGES : rng1"),
match_mode = :all,
readqps("dat/rim_rng.qps")
)
Expand All @@ -79,13 +75,11 @@
@testset "Bounds" begin
qp = @test_logs(
# These logs should appear in exactly this order
# (:warn, "Detected rim range rng2"),
(:info, "Using 'RimBOUNDS' as NAME (l. 1)"),
(:info, "Using 'obj' as objective (l. 3)"),
(:info, "Using 'bnd1' as BOUNDS (l. 12)"),
(:error, "Skipping line 13 with rim bound bnd2"),
(:error, "Skipping line 15 with rim bound bnd2"),
(:info, "Problem name : RimObj"),
(:info, "Objective sense : notset"),
(:info, "Objective name : obj"),
(:info, "BOUNDS : bnd1"),
match_mode = :all,
readqps("dat/rim_bnd.qps")
)
Expand Down

0 comments on commit 7ec0029

Please sign in to comment.