rougail/tests/test_others.py

59 lines
2 KiB
Python
Raw Normal View History

2021-02-22 19:28:51 +01:00
from pytest import raises
2023-10-12 08:17:30 +02:00
import logging
2021-02-22 19:28:51 +01:00
2023-10-12 08:17:30 +02:00
from rougail import Rougail, RougailConfig
2021-02-22 19:28:51 +01:00
from rougail.error import DictConsistencyError
2023-10-12 08:17:30 +02:00
logger = logging.getLogger()
logger.setLevel(logging.INFO)
2021-02-22 19:28:51 +01:00
def test_mode_invalid_default():
2022-10-01 22:27:22 +02:00
# default variable mode is not in modes_level
2021-02-22 19:28:51 +01:00
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
RougailConfig['modes_level'] = ['level1', 'level2']
with raises(ValueError) as err:
RougailConfig['default_family_mode'] = 'level3'
2021-02-22 19:28:51 +01:00
def test_mode_invalid_default_family():
2022-10-01 22:27:22 +02:00
# default family mode is not in modes_level
2021-02-22 19:28:51 +01:00
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
RougailConfig['modes_level'] = ['level1', 'level2']
with raises(ValueError) as err:
RougailConfig['default_variable_mode'] = 'level3'
2021-02-22 19:28:51 +01:00
def test_personalize_mode():
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
RougailConfig['modes_level'] = ['level1', 'level2']
2021-02-22 19:28:51 +01:00
RougailConfig['default_variable_mode'] = 'level1'
RougailConfig['default_family_mode'] = 'level1'
2023-10-12 08:17:30 +02:00
RougailConfig['tiramisu_cache'] = None
eolobj = Rougail()
eolobj.get_config()
2021-02-22 19:28:51 +01:00
def test_personalize_mode_unknown():
2022-10-01 22:27:22 +02:00
# a variable has an unknown mode
2021-02-22 19:28:51 +01:00
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
RougailConfig['modes_level'] = ['level1']
2021-02-22 19:28:51 +01:00
RougailConfig['default_variable_mode'] = 'level1'
RougailConfig['default_family_mode'] = 'level1'
2023-10-12 08:17:30 +02:00
eolobj = Rougail()
2022-10-01 22:27:22 +02:00
with raises(DictConsistencyError) as err:
2023-10-12 08:17:30 +02:00
eolobj.converted.annotate()
2022-10-01 22:27:22 +02:00
assert err.value.errno == 71
2023-10-12 08:17:30 +02:00
def test_personalize_annotate_twice():
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
RougailConfig['modes_level'] = ['level1', 'level2']
2023-10-12 08:17:30 +02:00
RougailConfig['default_variable_mode'] = 'level1'
RougailConfig['default_family_mode'] = 'level1'
eolobj = Rougail()
eolobj.converted.annotate()
with raises(DictConsistencyError) as err:
eolobj.converted.annotate()
assert err.value.errno == 85