#  ___________________________________________________________________________
#
#  Pyomo: Python Optimization Modeling Objects
#  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________

import os
import pyutilib.th as unittest

from pyomo.solvers.plugins.solvers.CPLEX import _validate_file_name

class _mock_cplex_128(object):
    def version(self):
        return (12,8,0)

class _mock_cplex_126(object):
    def version(self):
        return (12,6,0)

class CPLEX_utils(unittest.TestCase):
    def test_validate_file_name(self):
        _126 = _mock_cplex_126()
        _128 = _mock_cplex_128()

        # Check plain file
        fname = 'foo.lp'
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))

        # Check spaces in the file
        fname = 'foo bar.lp'
        with self.assertRaisesRegexp(
                ValueError, "Space detected in CPLEX xxx file"):
            _validate_file_name(_126, fname, 'xxx')
        self.assertEqual('"%s"' % (fname,),
                         _validate_file_name(_128, fname, 'xxx'))

        # check OK path separators
        fname = 'foo%sbar.lp' % (os.path.sep,)
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))

        # check BAD path separators
        bad_char = '/\\'.replace(os.path.sep,'')
        fname = 'foo%sbar.lp' % (bad_char,)
        msg = 'Unallowed character \(%s\) found in CPLEX xxx file' % (
            repr(bad_char)[1:-1],)
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_126, fname, 'xxx')
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_128, fname, 'xxx')

if __name__ == "__main__":
    unittest.main()

a8b542765c7d0ac497c4e73c87453f4abf0564d4
<mask token>


class _mock_cplex_128(object):
    <mask token>


class _mock_cplex_126(object):

    def version(self):
        return 12, 6, 0


class CPLEX_utils(unittest.TestCase):

    def test_validate_file_name(self):
        _126 = _mock_cplex_126()
        _128 = _mock_cplex_128()
        fname = 'foo.lp'
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))
        fname = 'foo bar.lp'
        with self.assertRaisesRegexp(ValueError,
            'Space detected in CPLEX xxx file'):
            _validate_file_name(_126, fname, 'xxx')
        self.assertEqual('"%s"' % (fname,), _validate_file_name(_128, fname,
            'xxx'))
        fname = 'foo%sbar.lp' % (os.path.sep,)
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))
        bad_char = '/\\'.replace(os.path.sep, '')
        fname = 'foo%sbar.lp' % (bad_char,)
        msg = 'Unallowed character \\(%s\\) found in CPLEX xxx file' % (repr
            (bad_char)[1:-1],)
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_126, fname, 'xxx')
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_128, fname, 'xxx')


<mask token>

<mask token>


class _mock_cplex_128(object):

    def version(self):
        return 12, 8, 0


class _mock_cplex_126(object):

    def version(self):
        return 12, 6, 0


class CPLEX_utils(unittest.TestCase):

    def test_validate_file_name(self):
        _126 = _mock_cplex_126()
        _128 = _mock_cplex_128()
        fname = 'foo.lp'
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))
        fname = 'foo bar.lp'
        with self.assertRaisesRegexp(ValueError,
            'Space detected in CPLEX xxx file'):
            _validate_file_name(_126, fname, 'xxx')
        self.assertEqual('"%s"' % (fname,), _validate_file_name(_128, fname,
            'xxx'))
        fname = 'foo%sbar.lp' % (os.path.sep,)
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))
        bad_char = '/\\'.replace(os.path.sep, '')
        fname = 'foo%sbar.lp' % (bad_char,)
        msg = 'Unallowed character \\(%s\\) found in CPLEX xxx file' % (repr
            (bad_char)[1:-1],)
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_126, fname, 'xxx')
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_128, fname, 'xxx')


<mask token>

<mask token>


class _mock_cplex_128(object):

    def version(self):
        return 12, 8, 0


class _mock_cplex_126(object):

    def version(self):
        return 12, 6, 0


class CPLEX_utils(unittest.TestCase):

    def test_validate_file_name(self):
        _126 = _mock_cplex_126()
        _128 = _mock_cplex_128()
        fname = 'foo.lp'
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))
        fname = 'foo bar.lp'
        with self.assertRaisesRegexp(ValueError,
            'Space detected in CPLEX xxx file'):
            _validate_file_name(_126, fname, 'xxx')
        self.assertEqual('"%s"' % (fname,), _validate_file_name(_128, fname,
            'xxx'))
        fname = 'foo%sbar.lp' % (os.path.sep,)
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))
        bad_char = '/\\'.replace(os.path.sep, '')
        fname = 'foo%sbar.lp' % (bad_char,)
        msg = 'Unallowed character \\(%s\\) found in CPLEX xxx file' % (repr
            (bad_char)[1:-1],)
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_126, fname, 'xxx')
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_128, fname, 'xxx')


if __name__ == '__main__':
    unittest.main()

import os
import pyutilib.th as unittest
from pyomo.solvers.plugins.solvers.CPLEX import _validate_file_name


class _mock_cplex_128(object):

    def version(self):
        return 12, 8, 0


class _mock_cplex_126(object):

    def version(self):
        return 12, 6, 0


class CPLEX_utils(unittest.TestCase):

    def test_validate_file_name(self):
        _126 = _mock_cplex_126()
        _128 = _mock_cplex_128()
        fname = 'foo.lp'
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))
        fname = 'foo bar.lp'
        with self.assertRaisesRegexp(ValueError,
            'Space detected in CPLEX xxx file'):
            _validate_file_name(_126, fname, 'xxx')
        self.assertEqual('"%s"' % (fname,), _validate_file_name(_128, fname,
            'xxx'))
        fname = 'foo%sbar.lp' % (os.path.sep,)
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))
        bad_char = '/\\'.replace(os.path.sep, '')
        fname = 'foo%sbar.lp' % (bad_char,)
        msg = 'Unallowed character \\(%s\\) found in CPLEX xxx file' % (repr
            (bad_char)[1:-1],)
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_126, fname, 'xxx')
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_128, fname, 'xxx')


if __name__ == '__main__':
    unittest.main()

#  ___________________________________________________________________________
#
#  Pyomo: Python Optimization Modeling Objects
#  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________

import os
import pyutilib.th as unittest

from pyomo.solvers.plugins.solvers.CPLEX import _validate_file_name

class _mock_cplex_128(object):
    def version(self):
        return (12,8,0)

class _mock_cplex_126(object):
    def version(self):
        return (12,6,0)

class CPLEX_utils(unittest.TestCase):
    def test_validate_file_name(self):
        _126 = _mock_cplex_126()
        _128 = _mock_cplex_128()

        # Check plain file
        fname = 'foo.lp'
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))

        # Check spaces in the file
        fname = 'foo bar.lp'
        with self.assertRaisesRegexp(
                ValueError, "Space detected in CPLEX xxx file"):
            _validate_file_name(_126, fname, 'xxx')
        self.assertEqual('"%s"' % (fname,),
                         _validate_file_name(_128, fname, 'xxx'))

        # check OK path separators
        fname = 'foo%sbar.lp' % (os.path.sep,)
        self.assertEqual(fname, _validate_file_name(_126, fname, 'xxx'))
        self.assertEqual(fname, _validate_file_name(_128, fname, 'xxx'))

        # check BAD path separators
        bad_char = '/\\'.replace(os.path.sep,'')
        fname = 'foo%sbar.lp' % (bad_char,)
        msg = 'Unallowed character \(%s\) found in CPLEX xxx file' % (
            repr(bad_char)[1:-1],)
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_126, fname, 'xxx')
        with self.assertRaisesRegexp(ValueError, msg):
            _validate_file_name(_128, fname, 'xxx')

if __name__ == "__main__":
    unittest.main()
