Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • kit/virtmat-tools/vre-language
1 result
Show changes
Commits on Source (12)
...@@ -6,6 +6,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ...@@ -6,6 +6,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
## [Unreleased] ## [Unreleased]
## [0.5.6] - 2025-02-05
### Added
- **docs**: add a section on resource configuration ([#411](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/411))
- **amml**: apply constraints optionally in view structure ([#405](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/405))
- **amml**: add periodic boundary conditions (PBC) to input structure automatically with Vasp calculator ([#401](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/401))
### Fixed
- **interpreter**: fix warnings not being suppressed by `-w` flag ([#412](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/412))
- **cli**: fix cases with empty search results to avoid crash of `%find ... load one` ([#410](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/410))
- **interpreter**: fix printing the type in case of evaluation error ([#408](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/408))
- **grammar**: fix a semantic version grammar rule ([#404](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/404))
### Changed
- **setup**: adapt package dependencies for the new fireworks release ([#413](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/413))
- **amml**: change default value of an environment variable to the vendor default ([#411](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/411))
- **interpreter**: do not show Python exception traceback of evaluation errors ([#402](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/402))
- **docs**: make several corrections in docs ([#400](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/400))
- **grammar**: make parse rule version requirement more precise ([#354](https://gitlab.kit.edu/kit/virtmat-tools/vre-language/-/issues/354))
## [0.5.5] - 2025-01-13 ## [0.5.5] - 2025-01-13
### Added ### Added
......
...@@ -34,17 +34,17 @@ The project can be installed into a Python virtual environment using the `pip` p ...@@ -34,17 +34,17 @@ The project can be installed into a Python virtual environment using the `pip` p
python -m pip install vre-language python -m pip install vre-language
``` ```
**NOTE: Broken install due to an open issue in FireWorks** **NOTE: Warnings due to an open issue in FireWorks**
Fresh installations of VRE Language will currently *sometimes* not work. When running `texts` this error may occur Fresh installations of VRE Language will currently *sometimes* print many warnings containing this line when running `texts`:
``` ```
ModuleNotFoundError: No module named 'pytest' ModuleNotFoundError: No module named 'pytest'
``` ```
The error is documented in this [issue](https://github.com/materialsproject/fireworks/issues/535). The issue is documented [here](https://github.com/materialsproject/fireworks/issues/535).
As a work-around, the `pytest` package can be installed via this command: The warning can be ignored or muted by installing the `pytest` package via this command:
``` ```
python -m pip install pytest python -m pip install pytest
......
...@@ -14,15 +14,15 @@ In all evaluation modes, the model is first parsed using a grammar. The grammar ...@@ -14,15 +14,15 @@ In all evaluation modes, the model is first parsed using a grammar. The grammar
#### Instant and deferred modes #### Instant and deferred modes
In the *instant* mode the evaluation is performed *immediately* and *locally*. In *deferred* mode the evaluation is deferred but still performed *locally*. In *instant* and *deferred* modes the model does not persist after the interpreter has finished, i.e. the `texts script` has returned. Only parameters of `print` statements in the program will be evaluated. In the *instant* mode the evaluation is performed *immediately* and *locally*. In *deferred* mode the evaluation is deferred but still performed *locally*. In *instant* and *deferred* modes the model does not persist after the interpreter has finished, i.e. the `texts script` has returned. Only parameters of `print` and `view` statements in the program will be evaluated.
#### Workflow mode #### Workflow mode
In the *workflow* mode the intepreter creates a workflow from the model and stores the workflow in a database. Therefore, the model is *persistent* after the interpreter returns, i.e. the *model instance* continues existing on the database. A model instance can be retrieved via a *universally unique identifier* (UUID) that is generated at the time when the model instance is created. A model instance can only be evaluated and extended but not otherwise modified. In the *workflow* mode the intepreter creates a workflow from the model and stores the workflow in a database. Therefore, the model is *persistent* after the interpreter returns, i.e. the *model instance* continues existing on the database. A model instance can be retrieved via a *universally unique identifier* (UUID) that is generated at the time when the model instance is created. A model instance can only be evaluated and extended but not otherwise modified.
If no additional flags are specified the model is not evaluated after interpretation except for parameters in `print` statements that contain no references to variables. Otherwise `n.c.` will be printed instead of the not yet computed values. Optionally, a model can be evaluated locally after the intepreter finishes by specifying the `-r | --autorun` flag. In this case all variables will be evaluated but only those in print statements will be printed. Additionally, the `-d | --on-demand` flag restricts the evaluation to only those variables that are referenced in `print` and `view` statements. If no additional flags are specified, the model is not evaluated after interpretation except for parameters in `print` and `view` statements that contain no references to variables. Otherwise `n.c.` will be printed instead of the not yet computed values and `view` statements will produce warnings. Optionally, a model can be evaluated locally after the intepreter finishes by specifying the `-r | --autorun` flag. In this case all variables will be evaluated but only those in `print`/`view` statements will be printed/displayed. Additionally, the `-d | --on-demand` flag restricts the evaluation to only those variables that are referenced in `print` and `view` statements.
In order to work in workflow mode, a launchpad describing a connection to a MongoDB database must be configured. Using the flag `-l LAUNCHPAD_FILE, --launchpad-file LAUNCHPAD_FILE` the launchpad data (such as hostname, database name and credentials) can be optionally specified. Otherwise the script looks up the current working directory and then the folder `$HOME/.fireworks` for a launchpad configuration. More information about configuring a launchpad can be found [here](https://vre-middleware.readthedocs.io/en/latest/launchpad.html). In order to work in workflow mode, a launchpad describing a connection to a MongoDB database must be configured. Using the flag `-l LAUNCHPAD_FILE, --launchpad-file LAUNCHPAD_FILE` the launchpad data (such as hostname, database name and credentials) can be optionally specified. Otherwise `texts` looks up the current working directory and then the folder `$HOME/.fireworks` for a launchpad configuration. More information about configuring a launchpad can be found [here](https://vre-middleware.readthedocs.io/en/latest/installation.html#setting-up-fireworks-with-a-mongodb-instance).
By using the `-h, --help` flag a summarized help can be obtained: By using the `-h, --help` flag a summarized help can be obtained:
...@@ -204,7 +204,7 @@ Repeated initialization error is issued by the interpreter when it applies seman ...@@ -204,7 +204,7 @@ Repeated initialization error is issued by the interpreter when it applies seman
### Runtime errors ### Runtime errors
Some errors occur only during the evaluation. These are called *runtime errors*. Runtime errors have the same format as the static errors. Runtime errors only occur if the evaluation is requested, e.g. by `print` statements. For example, this input: Some errors occur only during the evaluation. These are called *runtime errors*. Runtime errors have the same format as the static errors. Runtime errors only occur if the evaluation is requested, e.g. by `print` or `view` statements. For example, this input:
``` ```
length = 1 [m] length = 1 [m]
......
[metadata] [metadata]
name = vre-language name = vre-language
version = 0.5.5 version = 0.5.6
author = The Virtmat Tools Team author = The Virtmat Tools Team
author_email = virtmat-tools@lists.kit.edu author_email = virtmat-tools@lists.kit.edu
description = VRE Language description = VRE Language
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
from textx import get_children_of_type, textx_isinstance from textx import get_children_of_type, textx_isinstance
from virtmat.language.utilities.textx import get_reference from virtmat.language.utilities.textx import get_reference
from virtmat.language.utilities.errors import StaticValueError, raise_exception from virtmat.language.utilities.errors import StaticValueError, raise_exception
from virtmat.language.utilities.errors import issue_warning from virtmat.language.utilities.warnings import warnings, TextSUserWarning
from virtmat.language.utilities.warnings import TextSUserWarning
from virtmat.language.utilities.chemistry import is_equation_balanced from virtmat.language.utilities.chemistry import is_equation_balanced
...@@ -25,7 +24,7 @@ def check_chem_reaction_balance(react, metamodel): ...@@ -25,7 +24,7 @@ def check_chem_reaction_balance(react, metamodel):
if len(lcomps+rcomps) != len(react.educts+react.products): if len(lcomps+rcomps) != len(react.educts+react.products):
msg = ('reaction balance check skipped due to missing ' msg = ('reaction balance check skipped due to missing '
'composition in some terms') 'composition in some terms')
issue_warning(react, TextSUserWarning, msg) warnings.warn(TextSUserWarning(msg, obj=react))
return return
if not is_equation_balanced(lcomps, lcoeff, rcomps, rcoeff): if not is_equation_balanced(lcomps, lcoeff, rcomps, rcoeff):
msg = ('Reaction equation is not balanced. Check ' msg = ('Reaction equation is not balanced. Check '
......
...@@ -17,8 +17,8 @@ from virtmat.language.constraints.processors import add_constraints_processors ...@@ -17,8 +17,8 @@ from virtmat.language.constraints.processors import add_constraints_processors
from virtmat.language.constraints.processors import check_variable_update_processor from virtmat.language.constraints.processors import check_variable_update_processor
from virtmat.language.interpreter.workflow_executor import workflow_model_processor from virtmat.language.interpreter.workflow_executor import workflow_model_processor
from virtmat.language.utilities.textx import isinstance_m from virtmat.language.utilities.textx import isinstance_m
from virtmat.language.utilities.errors import raise_exception, StaticTypeError, error_handler from virtmat.language.utilities.errors import raise_exception, StaticTypeError
from virtmat.language.utilities.warnings import TextSUserWarning from virtmat.language.utilities.warnings import warnings, TextSUserWarning
from .function import function_call_processor from .function import function_call_processor
from .workflow import source_code_statement_processor, qadapter_processor from .workflow import source_code_statement_processor, qadapter_processor
from .workflow import default_worker_name_processor, resources_processor from .workflow import default_worker_name_processor, resources_processor
...@@ -84,17 +84,15 @@ def print_parameter_processor(obj): ...@@ -84,17 +84,15 @@ def print_parameter_processor(obj):
setattr(obj, 'inp_units', getattr(obj, 'units', None)) setattr(obj, 'inp_units', getattr(obj, 'units', None))
@error_handler
def tag_processor(obj): def tag_processor(obj):
"""warn if tag is found in instant or in deferred evaluation modes""" """warn if tag is found in instant or in deferred evaluation modes"""
msg = 'tags are interpreted only in workflow evaluation mode' msg = 'tags are interpreted only in workflow evaluation mode'
raise_exception(obj, TextSUserWarning, msg) warnings.warn(TextSUserWarning(msg, obj=obj))
@error_handler
def vary_processor(obj): def vary_processor(obj):
"""warn if vary is found in instant or in deferred evaluation modes""" """warn if vary is found in instant or in deferred evaluation modes"""
raise_exception(obj, TextSUserWarning, 'vary statement has no effect') warnings.warn(TextSUserWarning('vary statement has no effect', obj=obj))
def add_obj_processors(metamodel, wflow_processors=False): def add_obj_processors(metamodel, wflow_processors=False):
......
...@@ -6,7 +6,7 @@ from matplotlib import pyplot ...@@ -6,7 +6,7 @@ from matplotlib import pyplot
from virtmat.language.utilities.types import is_array_type, is_array, is_numeric, NC from virtmat.language.utilities.types import is_array_type, is_array, is_numeric, NC
from virtmat.language.utilities.errors import RuntimeTypeError, RuntimeValueError from virtmat.language.utilities.errors import RuntimeTypeError, RuntimeValueError
from virtmat.language.utilities.errors import textxerror_wrap, raise_exception, error_handler from virtmat.language.utilities.errors import textxerror_wrap, raise_exception, error_handler
from virtmat.language.utilities.warnings import TextSUserWarning from virtmat.language.utilities.warnings import warnings, TextSUserWarning
from virtmat.language.utilities.units import get_units, get_df_units from virtmat.language.utilities.units import get_units, get_df_units
from virtmat.language.utilities.units import convert_df_units, strip_units, ureg from virtmat.language.utilities.units import convert_df_units, strip_units, ureg
from virtmat.language.utilities.arrays import get_nested_array from virtmat.language.utilities.arrays import get_nested_array
...@@ -165,7 +165,9 @@ def display(self, show=True): ...@@ -165,7 +165,9 @@ def display(self, show=True):
"""define display() method in View metamodel class""" """define display() method in View metamodel class"""
if any(get_par_value(par) is NC for par in self.params): if any(get_par_value(par) is NC for par in self.params):
par = next(p for p in self.params if get_par_value(p) is NC) par = next(p for p in self.params if get_par_value(p) is NC)
raise_exception(par, TextSUserWarning, 'parameter value is not computed yet') msg = 'parameter value is not computed yet'
warnings.warn(TextSUserWarning(msg, obj=par))
return
if self.mode in ('lineplot', 'scatterplot'): if self.mode in ('lineplot', 'scatterplot'):
display_seaborn(self, show=show) display_seaborn(self, show=show)
elif self.mode == 'bs': elif self.mode == 'bs':
......
...@@ -19,7 +19,7 @@ from virtmat.language.utilities.lists import list_apply ...@@ -19,7 +19,7 @@ from virtmat.language.utilities.lists import list_apply
spec = { spec = {
'vasp': { 'vasp': {
'module': 'ase.calculators.vasp', 'module': 'virtmat.language.utilities.ase_wrappers',
'class': 'Vasp', 'class': 'Vasp',
'modulefile': {'name': 'vasp', 'verspec': '>=5.0.0'}, 'modulefile': {'name': 'vasp', 'verspec': '>=5.0.0'},
'envvars': {'VASP_COMMAND': 'vasp_std'}, 'envvars': {'VASP_COMMAND': 'vasp_std'},
......
...@@ -15,9 +15,11 @@ from ase.dft.dos import DOS ...@@ -15,9 +15,11 @@ from ase.dft.dos import DOS
from ase.mep import NEBTools, DimerControl, MinModeAtoms, MinModeTranslate from ase.mep import NEBTools, DimerControl, MinModeAtoms, MinModeTranslate
from ase.vibrations import Vibrations from ase.vibrations import Vibrations
from ase.calculators.singlepoint import SinglePointCalculator from ase.calculators.singlepoint import SinglePointCalculator
from ase.calculators.vasp import Vasp
from ase.md import velocitydistribution from ase.md import velocitydistribution
from virtmat.language.utilities.errors import RuntimeValueError from virtmat.language.utilities.errors import RuntimeValueError
from virtmat.language.utilities.ase_params import spec from virtmat.language.utilities.ase_params import spec
from virtmat.language.utilities.warnings import warnings, TextSUserWarning
@contextmanager @contextmanager
...@@ -287,3 +289,16 @@ class VibrationsWrapper(IOContext): ...@@ -287,3 +289,16 @@ class VibrationsWrapper(IOContext):
'eigen_imag': enes.imag, 'eigen_modes': modes, 'eigen_imag': enes.imag, 'eigen_modes': modes,
'transition_state': imag == 1, 'energy_minimum': imag == 0} 'transition_state': imag == 1, 'energy_minimum': imag == 0}
return True return True
def vasp_calculate_decorator(func):
"""perform modifications of Vasp.calculate's arguments"""
def calculate_wrapper(self, atoms, *args, **kwargs):
if not all(p for p in atoms.pbc):
warnings.warn('setting PBC for structure in Vasp', TextSUserWarning)
atoms.pbc = True
return func(self, atoms, *args, **kwargs)
return calculate_wrapper
Vasp.calculate = vasp_calculate_decorator(vars(Vasp)['calculate'])
...@@ -6,7 +6,6 @@ from pint.errors import PintError, DimensionalityError, UndefinedUnitError ...@@ -6,7 +6,6 @@ from pint.errors import PintError, DimensionalityError, UndefinedUnitError
from pint.errors import OffsetUnitCalculusError from pint.errors import OffsetUnitCalculusError
from ase.calculators.calculator import CalculatorSetupError from ase.calculators.calculator import CalculatorSetupError
from virtmat.middleware.exceptions import ResourceConfigurationError from virtmat.middleware.exceptions import ResourceConfigurationError
from virtmat.language.utilities.warnings import TextSUserWarning
from virtmat.language.utilities.compatibility import CompatibilityError from virtmat.language.utilities.compatibility import CompatibilityError
from virtmat.language.utilities.textx import get_location_context from virtmat.language.utilities.textx import get_location_context
...@@ -290,8 +289,6 @@ def process_error(err): ...@@ -290,8 +289,6 @@ def process_error(err):
err_type = 'File exists error' err_type = 'File exists error'
elif isinstance(err.__cause__, OSError): elif isinstance(err.__cause__, OSError):
err_type = 'Operating system error' err_type = 'Operating system error'
elif isinstance(err.__cause__, TextSUserWarning):
err_type = 'Warning'
else: else:
raise err.__cause__ raise err.__cause__
else: else:
...@@ -340,9 +337,3 @@ def error_handler(func): ...@@ -340,9 +337,3 @@ def error_handler(func):
except Exception as err: except Exception as err:
raise RuntimeError('non-handled exception') from err raise RuntimeError('non-handled exception') from err
return wrapper return wrapper
@error_handler
def issue_warning(*args, **kwargs):
"""issue a user warning or any other exception as a warning"""
raise_exception(*args, **kwargs)
"""handling domain-specific warnings""" """handling domain-specific warnings"""
import warnings import warnings
from virtmat.language.utilities.textx import get_location_context
from virtmat.language.utilities.errors import format_textxerr_msg
class TextSUserWarning(UserWarning): class TextSUserWarning(UserWarning):
"""warning to use within the processors""" """warning to use within the processors"""
def __init__(self, *args, obj=None, **kwargs):
self.obj = obj
super().__init__(*args, **kwargs)
if obj:
for key, val in get_location_context(obj).items():
setattr(self, key, val)
self.message = str(self)
def format_warning_wrapper(func): def format_warning_wrapper(func):
...@@ -13,6 +22,8 @@ def format_warning_wrapper(func): ...@@ -13,6 +22,8 @@ def format_warning_wrapper(func):
warning_cls = args[1] warning_cls = args[1]
if isinstance(warning, TextSUserWarning): if isinstance(warning, TextSUserWarning):
assert warning_cls is TextSUserWarning assert warning_cls is TextSUserWarning
if warning.obj:
return 'Warning: ' + format_textxerr_msg(warning) + '\n'
return 'Warning: ' + str(warning) + '\n' return 'Warning: ' + str(warning) + '\n'
return func(*args, **kwargs) return func(*args, **kwargs)
return wrapper return wrapper
......
...@@ -5,6 +5,7 @@ import os ...@@ -5,6 +5,7 @@ import os
import pytest import pytest
from textx import get_children_of_type from textx import get_children_of_type
from textx.exceptions import TextXError from textx.exceptions import TextXError
from ase.calculators.calculator import CalculatorSetupError
from virtmat.language.utilities.typemap import typemap from virtmat.language.utilities.typemap import typemap
from virtmat.language.utilities.amml import AMMLStructure from virtmat.language.utilities.amml import AMMLStructure
from virtmat.language.utilities.errors import StaticValueError, RuntimeValueError from virtmat.language.utilities.errors import StaticValueError, RuntimeValueError
...@@ -182,7 +183,7 @@ def test_amml_property_literal(meta_model, model_kwargs): ...@@ -182,7 +183,7 @@ def test_amml_property_literal(meta_model, model_kwargs):
" )" " )"
" )," " ),"
" (cell: [[10., 0., 0.], [0., 10., 0.], [0., 0., 10.]] [angstrom])," " (cell: [[10., 0., 0.], [0., 10., 0.], [0., 0., 10.]] [angstrom]),"
" (pbc: [true, true, true])" " (pbc: [true, true, false])"
" );" " );"
"calc = Calculator vasp >= 5.4.4 (" "calc = Calculator vasp >= 5.4.4 ("
" (algo: 'Fast')," " (algo: 'Fast'),"
...@@ -207,7 +208,14 @@ def test_amml_property_literal(meta_model, model_kwargs): ...@@ -207,7 +208,14 @@ def test_amml_property_literal(meta_model, model_kwargs):
" (xc: 'PBE')" " (xc: 'PBE')"
" );" " );"
"props = Property energy, forces ((structure: h2o), (calculator: calc))") "props = Property energy, forces ((structure: h2o), (calculator: calc))")
meta_model.model_from_str(inp, **model_kwargs) prog = meta_model.model_from_str(inp, **model_kwargs)
var_list = get_children_of_type('Variable', prog)
msg = (r'Please set either command in calculator or one of the following '
r'environment variables \(prioritized as follows\): ASE_VASP_COMMAND, '
r'VASP_COMMAND, VASP_SCRIPT')
with pytest.raises(TextXError, match=msg) as err:
_ = next(v for v in var_list if v.name == 'props').value
assert isinstance(err.value.__cause__, CalculatorSetupError)
def test_amml_property_access_properties(meta_model, model_kwargs): def test_amml_property_access_properties(meta_model, model_kwargs):
......
...@@ -6,6 +6,7 @@ from textx import get_children_of_type ...@@ -6,6 +6,7 @@ from textx import get_children_of_type
from textx.exceptions import TextXError, TextXSyntaxError, TextXSemanticError from textx.exceptions import TextXError, TextXSyntaxError, TextXSemanticError
from virtmat.language.utilities.typemap import typemap from virtmat.language.utilities.typemap import typemap
from virtmat.language.utilities.errors import VaryError from virtmat.language.utilities.errors import VaryError
from virtmat.language.utilities.warnings import TextSUserWarning
def test_empty_program(meta_model, model_kwargs): def test_empty_program(meta_model, model_kwargs):
...@@ -516,12 +517,13 @@ def test_scalar_complex_real_imag_parts(meta_model, model_kwargs): ...@@ -516,12 +517,13 @@ def test_scalar_complex_real_imag_parts(meta_model, model_kwargs):
assert next(v for v in var_list if v.name == 'h').value is True assert next(v for v in var_list if v.name == 'h').value is True
def test_pointless_use_of_vary_statement(meta_model, model_kwargs, capsys): def test_pointless_use_of_vary_statement(meta_model, model_kwargs):
"""test pointless use of vary statement""" """test pointless use of vary statement"""
warn_msg = 'vary statement has no effect' if model_kwargs.get('model_instance'):
meta_model.model_from_str('vary ((a: 1, 2))', **model_kwargs) meta_model.model_from_str('vary ((a: 1, 2))', **model_kwargs)
if not model_kwargs.get('model_instance'): else:
assert warn_msg in capsys.readouterr().err with pytest.warns(TextSUserWarning, match='vary statement has no effect'):
meta_model.model_from_str('vary ((a: 1, 2))', **model_kwargs)
def test_invalid_reference_to_vary_statement(meta_model, model_kwargs): def test_invalid_reference_to_vary_statement(meta_model, model_kwargs):
......
...@@ -6,6 +6,7 @@ from textx import get_children_of_type ...@@ -6,6 +6,7 @@ from textx import get_children_of_type
from textx.exceptions import TextXError from textx.exceptions import TextXError
from virtmat.language.utilities.errors import StaticTypeError, StaticValueError from virtmat.language.utilities.errors import StaticTypeError, StaticValueError
from virtmat.language.utilities.errors import RuntimeValueError from virtmat.language.utilities.errors import RuntimeValueError
from virtmat.language.utilities.warnings import TextSUserWarning
from virtmat.language.utilities.formatters import formatter from virtmat.language.utilities.formatters import formatter
...@@ -110,13 +111,13 @@ def test_reaction_not_balanced_composition_ref(meta_model, model_kwargs): ...@@ -110,13 +111,13 @@ def test_reaction_not_balanced_composition_ref(meta_model, model_kwargs):
assert isinstance(err.value.__cause__, RuntimeValueError) assert isinstance(err.value.__cause__, RuntimeValueError)
def test_reaction_balance_check_skipped(meta_model, model_kwargs, capsys): def test_reaction_balance_check_skipped(meta_model, model_kwargs):
"""test when the reaction equation balance check is skipped""" """test when the reaction equation balance check is skipped"""
inp = ("r = Reaction 2 H2 + O2 -> 2 H2O; H2O = Species H2O;" inp = ("r = Reaction 2 H2 + O2 -> 2 H2O; H2O = Species H2O;"
"H2 = Species H2, composition: 'H2'; O2 = Species O2, composition: 'O2'") "H2 = Species H2, composition: 'H2'; O2 = Species O2, composition: 'O2'")
meta_model.model_from_str(inp, **model_kwargs) msg = 'reaction balance check skipped due to missing composition'
std_err = capsys.readouterr().err with pytest.warns(TextSUserWarning, match=msg):
assert 'reaction balance check skipped due to missing composition' in std_err meta_model.model_from_str(inp, **model_kwargs)
def test_chem_species_iterable(meta_model, model_kwargs): def test_chem_species_iterable(meta_model, model_kwargs):
......
...@@ -13,6 +13,7 @@ from virtmat.language.interpreter.workflow_executor import NonCompletedException ...@@ -13,6 +13,7 @@ from virtmat.language.interpreter.workflow_executor import NonCompletedException
from virtmat.language.utilities.errors import error_handler, ModelNotFoundError from virtmat.language.utilities.errors import error_handler, ModelNotFoundError
from virtmat.language.utilities.errors import VaryError, ReuseError, TagError from virtmat.language.utilities.errors import VaryError, ReuseError, TagError
from virtmat.language.utilities.errors import ConfigurationError, StaticValueError from virtmat.language.utilities.errors import ConfigurationError, StaticValueError
from virtmat.language.utilities.warnings import TextSUserWarning
from virtmat.language.utilities.textx import GRAMMAR_LOC from virtmat.language.utilities.textx import GRAMMAR_LOC
from virtmat.language.utilities.formatters import formatter from virtmat.language.utilities.formatters import formatter
...@@ -204,7 +205,7 @@ def test_session_model_with_uuid_and_grammar(lpad): ...@@ -204,7 +205,7 @@ def test_session_model_with_uuid_and_grammar(lpad):
old_session = Session(lpad, grammar_path=GRAMMAR_LOC, model_str='a = 1') old_session = Session(lpad, grammar_path=GRAMMAR_LOC, model_str='a = 1')
assert old_session.uuid is not None assert old_session.uuid is not None
msg = 'provided grammar ignored in favor of grammar from provided uuid' msg = 'provided grammar ignored in favor of grammar from provided uuid'
with pytest.warns(UserWarning, match=msg): with pytest.warns(TextSUserWarning, match=msg):
Session(lpad, uuid=old_session.uuid, grammar_path=GRAMMAR_LOC) Session(lpad, uuid=old_session.uuid, grammar_path=GRAMMAR_LOC)
......