16
16
17
17
import unittest
18
18
import tempfile
19
+ from os import path
19
20
from test .optimization .optimization_test_case import QiskitOptimizationTestCase
20
21
21
22
from docplex .mp .model import Model , DOcplexException
@@ -481,9 +482,11 @@ def test_write_to_lp_file(self):
481
482
q_p .quadratic_constraint ({'x' : 1 , 'y' : 1 }, {('x' , 'x' ): 1 , ('y' , 'z' ): - 1 , ('z' , 'z' ): 2 },
482
483
'>=' , 1 , 'quad_geq' )
483
484
485
+ reference_file_name = path .join ('test' , 'optimization' , 'resources' ,
486
+ 'test_quadratic_program.lp' )
484
487
temp_output_file = tempfile .NamedTemporaryFile (mode = 'w+t' , suffix = '.lp' )
485
488
q_p .write_to_lp_file (temp_output_file .name )
486
- with open ('test/optimization/resources/test_quadratic_program.lp' ) as reference :
489
+ with open (reference_file_name ) as reference :
487
490
lines1 = temp_output_file .readlines ()
488
491
lines2 = reference .readlines ()
489
492
self .assertListEqual (lines1 , lines2 )
@@ -492,8 +495,8 @@ def test_write_to_lp_file(self):
492
495
493
496
with tempfile .TemporaryDirectory () as temp_problem_dir :
494
497
q_p .write_to_lp_file (temp_problem_dir )
495
- with open (temp_problem_dir + '/ my_problem.lp' ) as file1 , open (
496
- 'test/optimization/resources/test_quadratic_program.lp' ) as file2 :
498
+ with open (path . join ( temp_problem_dir , ' my_problem.lp') ) as file1 , open (
499
+ reference_file_name ) as file2 :
497
500
lines1 = file1 .readlines ()
498
501
lines2 = file2 .readlines ()
499
502
self .assertListEqual (lines1 , lines2 )
0 commit comments