fix: correction in namespace calculation
This commit is contained in:
parent
ae89e30e60
commit
19249875c3
3 changed files with 70 additions and 33 deletions
|
|
@ -758,7 +758,7 @@ class NamespaceCalculation(Calculation):
|
|||
self,
|
||||
objectspace,
|
||||
) -> dict:
|
||||
namespace = objectspace.namespace
|
||||
namespace = self.namespace
|
||||
if namespace:
|
||||
namespace = objectspace.paths[namespace].description
|
||||
return {
|
||||
|
|
|
|||
13
tests/namespace/00-rougail.yml
Normal file
13
tests/namespace/00-rougail.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
var1:
|
||||
default:
|
||||
type: namespace
|
||||
|
||||
var2:
|
||||
default:
|
||||
jinja: "{{ n }}"
|
||||
params:
|
||||
n:
|
||||
type: namespace
|
||||
|
|
@ -4,54 +4,61 @@ import logging
|
|||
from rougail import Rougail, RougailConfig
|
||||
from rougail.error import DictConsistencyError
|
||||
|
||||
from rougail_tests.utils import config_to_dict
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
|
||||
def test_mode_invalid_default():
|
||||
# default variable mode is not in modes_level
|
||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
RougailConfig['modes_level'] = ['level1', 'level2']
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||
with raises(ValueError) as err:
|
||||
RougailConfig['default_family_mode'] = 'level3'
|
||||
rougailconfig['default_family_mode'] = 'level3'
|
||||
|
||||
|
||||
def test_mode_invalid_default_family():
|
||||
# default family mode is not in modes_level
|
||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
RougailConfig['modes_level'] = ['level1', 'level2']
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||
with raises(ValueError) as err:
|
||||
RougailConfig['default_variable_mode'] = 'level3'
|
||||
rougailconfig['default_variable_mode'] = 'level3'
|
||||
|
||||
|
||||
def test_personalize_mode():
|
||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
RougailConfig['modes_level'] = ['level1', 'level2']
|
||||
RougailConfig['default_variable_mode'] = 'level1'
|
||||
RougailConfig['default_family_mode'] = 'level1'
|
||||
RougailConfig['tiramisu_cache'] = None
|
||||
eolobj = Rougail()
|
||||
eolobj.get_config()
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||
rougailconfig['default_variable_mode'] = 'level1'
|
||||
rougailconfig['default_family_mode'] = 'level1'
|
||||
rougailconfig['tiramisu_cache'] = None
|
||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||
eolobj.run()
|
||||
|
||||
|
||||
def test_personalize_mode_unknown():
|
||||
# a variable has an unknown mode
|
||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
RougailConfig['modes_level'] = ['level1']
|
||||
RougailConfig['default_variable_mode'] = 'level1'
|
||||
RougailConfig['default_family_mode'] = 'level1'
|
||||
eolobj = Rougail()
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
rougailconfig['modes_level'] = ['level1']
|
||||
rougailconfig['default_variable_mode'] = 'level1'
|
||||
rougailconfig['default_family_mode'] = 'level1'
|
||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||
with raises(DictConsistencyError) as err:
|
||||
eolobj.converted.annotate()
|
||||
assert err.value.errno == 71
|
||||
|
||||
|
||||
def test_personalize_annotate_twice():
|
||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
RougailConfig['modes_level'] = ['level1', 'level2']
|
||||
RougailConfig['default_variable_mode'] = 'level1'
|
||||
RougailConfig['default_family_mode'] = 'level1'
|
||||
eolobj = Rougail()
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||
rougailconfig['default_variable_mode'] = 'level1'
|
||||
rougailconfig['default_family_mode'] = 'level1'
|
||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||
eolobj.converted.annotate()
|
||||
with raises(DictConsistencyError) as err:
|
||||
eolobj.converted.annotate()
|
||||
|
|
@ -59,14 +66,31 @@ def test_personalize_annotate_twice():
|
|||
|
||||
|
||||
def test_option_params():
|
||||
RougailConfig['dictionaries_dir'] = ['tests/default_option_params/structure']
|
||||
RougailConfig["default_params.unix_filename.test_existence"] = True
|
||||
eolobj = Rougail()
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['dictionaries_dir'] = ['tests/default_option_params/structure']
|
||||
rougailconfig["default_params.unix_filename.test_existence"] = True
|
||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||
with raises(ValueError):
|
||||
eolobj.get_config()
|
||||
eolobj = Rougail()
|
||||
eolobj.run()
|
||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||
with raises(ValueError):
|
||||
eolobj.get_config()
|
||||
RougailConfig["default_params.unix_filename.test_existence"] = False
|
||||
eolobj = Rougail()
|
||||
eolobj.get_config()
|
||||
eolobj.run()
|
||||
rougailconfig["default_params.unix_filename.test_existence"] = False
|
||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||
eolobj.run()
|
||||
|
||||
|
||||
def test_namespace():
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['main_namespace'] = 'NS1'
|
||||
rougailconfig['dictionaries_dir'] = ['tests/namespace']
|
||||
rougailconfig['extra_dictionaries'] = {'NS2': ['tests/namespace'],
|
||||
'NS3': ['tests/namespace'],
|
||||
}
|
||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||
assert dict(config_to_dict(eolobj.run().value.get())) == {'ns1.var1': 'NS1',
|
||||
'ns1.var2': 'NS1',
|
||||
'ns2.var1': 'NS2',
|
||||
'ns2.var2': 'NS2',
|
||||
'ns3.var1': 'NS3',
|
||||
'ns3.var2': 'NS3'}
|
||||
|
|
|
|||
Loading…
Reference in a new issue