Ejemplo n.º 1
0
    def setUpClass(cls):
        # Create a working directory for output files. If this is
        # an in-source test, create the directory in the root
        # test/work directory. Otherwise, create a system level
        # temporary directory
        root_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
        if os.path.exists(os.path.join(root_dir, 'SConstruct')):
            cls.test_work_dir = os.path.join(root_dir, 'test', 'work',
                                             'python')
            cls.using_tempfile = False
            try:
                os.makedirs(cls.test_work_dir)
            except OSError as e:
                if e.errno == errno.EEXIST:
                    pass
                elif e.errno == errno.EACCES:
                    cls.test_work_dir = tempfile.mkdtemp()
                else:
                    raise
        else:
            cls.test_work_dir = tempfile.mkdtemp()
            cls.using_tempfile = True

        cantera.make_deprecation_warnings_fatal()
        cantera.add_directory(cls.test_work_dir)
        cls.test_data_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'data'))
        cls.cantera_data = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', 'data'))
Ejemplo n.º 2
0
    def test_deprecated_getters(self):
        # check property getters deprecated in new framework
        if self._yaml is None:
            return

        ct.suppress_deprecation_warnings() # disable fatal deprecation warnings

        rxn = ct.Reaction.from_yaml(self._yaml, kinetics=self.gas)
        for attr, default in self._deprecated_getters.items():
            if self._legacy:
                self.check_equal(getattr(rxn, attr), default)
            else:
                with self.assertWarnsRegex(DeprecationWarning, "property is moved"):
                    try:
                        self.check_equal(getattr(rxn, attr), default)
                    except Exception as err:
                        print(f"Exception raised when testing getter for '{attr}'")
                        raise err

        ct.make_deprecation_warnings_fatal() # re-enable fatal deprecation warnings
Ejemplo n.º 3
0
    def setUpClass(cls):
        # Create a working directory for output files. If this is
        # an in-source test, create the directory in the root
        # test/work directory. Otherwise, create a system level
        # temporary directory
        root_dir = Path(__file__).parents[4].resolve()
        if (root_dir / "SConstruct").is_file():
            cls.test_work_path = root_dir / "test" / "work" / "python"
            cls.using_tempfile = False
            try:
                cls.test_work_path.mkdir(exist_ok=True)
            except FileNotFoundError:
                cls.test_work_path = Path(tempfile.mkdtemp())
                cls.using_tempfile = True
        else:
            cls.test_work_path = Path(tempfile.mkdtemp())
            cls.using_tempfile = True

        cantera.make_deprecation_warnings_fatal()
        cantera.add_directory(cls.test_work_path)
        cls.test_data_path = TEST_DATA_PATH
        cls.cantera_data_path = CANTERA_DATA_PATH
Ejemplo n.º 4
0
module_path = os.path.abspath(os.sep.join(cantera_root + ['build']))

if 'PYTHONPATH' in os.environ:
    os.environ['PYTHONPATH'] = module_path + os.path.pathsep + os.environ[
        'PYTHONPATH']
else:
    os.environ['PYTHONPATH'] = module_path

sys.path.insert(0, module_path)
os.chdir(os.sep.join(cantera_root + ['test', 'work']))

from cantera.test.utilities import unittest
import cantera
import cantera.test

cantera.make_deprecation_warnings_fatal()


class TestResult(unittest.TextTestResult):
    def __init__(self, *args, **kwargs):
        unittest.TextTestResult.__init__(self, *args, **kwargs)
        self.outName = 'python-results.txt'
        with open(self.outName, 'w') as f:
            pass  # just create an empty output file

    def reformat(self, test_string):
        name, cls = test_string.split()
        cls = cls.replace('(cantera.test.', '').replace(')', '')
        return '%s.%s' % (cls, name)

    def addSuccess(self, test):
Ejemplo n.º 5
0
 def wrapper(*args, **kwargs):
     cantera.suppress_deprecation_warnings()
     try:
         test(*args, **kwargs)
     finally:
         cantera.make_deprecation_warnings_fatal()
Ejemplo n.º 6
0
py_version = 'python3' if sys.version_info[0] == 3 else 'python2'
module_path = os.path.abspath(os.sep.join(cantera_root + ['build', py_version]))

if 'PYTHONPATH' in os.environ:
    os.environ['PYTHONPATH'] = module_path + os.path.pathsep + os.environ['PYTHONPATH']
else:
    os.environ['PYTHONPATH'] = module_path

sys.path.insert(0, module_path)
os.chdir(os.sep.join(cantera_root + ['test', 'work']))

from cantera.test.utilities import unittest
import cantera
import cantera.test

cantera.make_deprecation_warnings_fatal()

class TestResult(unittest.TextTestResult):
    def __init__(self, *args, **kwargs):
        unittest.TextTestResult.__init__(self, *args, **kwargs)
        self.outName = 'python%d-results.txt' % sys.version_info[0]
        with open(self.outName, 'w') as f:
            pass # just create an empty output file

    def reformat(self, test_string):
        name, cls = test_string.split()
        cls = cls.replace('(cantera.test.', '').replace(')','')
        return '%s.%s' % (cls, name)

    def addSuccess(self, test):
        with open(self.outName, 'a') as f:
Ejemplo n.º 7
0
def allow_deprecated():
    cantera.suppress_deprecation_warnings()
    yield
    cantera.make_deprecation_warnings_fatal()