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,
|
self,
|
||||||
objectspace,
|
objectspace,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
namespace = objectspace.namespace
|
namespace = self.namespace
|
||||||
if namespace:
|
if namespace:
|
||||||
namespace = objectspace.paths[namespace].description
|
namespace = objectspace.paths[namespace].description
|
||||||
return {
|
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 import Rougail, RougailConfig
|
||||||
from rougail.error import DictConsistencyError
|
from rougail.error import DictConsistencyError
|
||||||
|
|
||||||
|
from rougail_tests.utils import config_to_dict
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def test_mode_invalid_default():
|
def test_mode_invalid_default():
|
||||||
# default variable mode is not in modes_level
|
# default variable mode is not in modes_level
|
||||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
rougailconfig = RougailConfig.copy()
|
||||||
RougailConfig['modes_level'] = ['level1', 'level2']
|
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||||
|
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||||
with raises(ValueError) as err:
|
with raises(ValueError) as err:
|
||||||
RougailConfig['default_family_mode'] = 'level3'
|
rougailconfig['default_family_mode'] = 'level3'
|
||||||
|
|
||||||
|
|
||||||
def test_mode_invalid_default_family():
|
def test_mode_invalid_default_family():
|
||||||
# default family mode is not in modes_level
|
# default family mode is not in modes_level
|
||||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
rougailconfig = RougailConfig.copy()
|
||||||
RougailConfig['modes_level'] = ['level1', 'level2']
|
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||||
|
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||||
with raises(ValueError) as err:
|
with raises(ValueError) as err:
|
||||||
RougailConfig['default_variable_mode'] = 'level3'
|
rougailconfig['default_variable_mode'] = 'level3'
|
||||||
|
|
||||||
|
|
||||||
def test_personalize_mode():
|
def test_personalize_mode():
|
||||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
rougailconfig = RougailConfig.copy()
|
||||||
RougailConfig['modes_level'] = ['level1', 'level2']
|
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||||
RougailConfig['default_variable_mode'] = 'level1'
|
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||||
RougailConfig['default_family_mode'] = 'level1'
|
rougailconfig['default_variable_mode'] = 'level1'
|
||||||
RougailConfig['tiramisu_cache'] = None
|
rougailconfig['default_family_mode'] = 'level1'
|
||||||
eolobj = Rougail()
|
rougailconfig['tiramisu_cache'] = None
|
||||||
eolobj.get_config()
|
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||||
|
eolobj.run()
|
||||||
|
|
||||||
|
|
||||||
def test_personalize_mode_unknown():
|
def test_personalize_mode_unknown():
|
||||||
# a variable has an unknown mode
|
# a variable has an unknown mode
|
||||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
rougailconfig = RougailConfig.copy()
|
||||||
RougailConfig['modes_level'] = ['level1']
|
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||||
RougailConfig['default_variable_mode'] = 'level1'
|
rougailconfig['modes_level'] = ['level1']
|
||||||
RougailConfig['default_family_mode'] = 'level1'
|
rougailconfig['default_variable_mode'] = 'level1'
|
||||||
eolobj = Rougail()
|
rougailconfig['default_family_mode'] = 'level1'
|
||||||
|
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||||
with raises(DictConsistencyError) as err:
|
with raises(DictConsistencyError) as err:
|
||||||
eolobj.converted.annotate()
|
eolobj.converted.annotate()
|
||||||
assert err.value.errno == 71
|
assert err.value.errno == 71
|
||||||
|
|
||||||
|
|
||||||
def test_personalize_annotate_twice():
|
def test_personalize_annotate_twice():
|
||||||
RougailConfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
rougailconfig = RougailConfig.copy()
|
||||||
RougailConfig['modes_level'] = ['level1', 'level2']
|
rougailconfig['dictionaries_dir'] = ['tests/personalize_mode/dictionary']
|
||||||
RougailConfig['default_variable_mode'] = 'level1'
|
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||||
RougailConfig['default_family_mode'] = 'level1'
|
rougailconfig['default_variable_mode'] = 'level1'
|
||||||
eolobj = Rougail()
|
rougailconfig['default_family_mode'] = 'level1'
|
||||||
|
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||||
eolobj.converted.annotate()
|
eolobj.converted.annotate()
|
||||||
with raises(DictConsistencyError) as err:
|
with raises(DictConsistencyError) as err:
|
||||||
eolobj.converted.annotate()
|
eolobj.converted.annotate()
|
||||||
|
|
@ -59,14 +66,31 @@ def test_personalize_annotate_twice():
|
||||||
|
|
||||||
|
|
||||||
def test_option_params():
|
def test_option_params():
|
||||||
RougailConfig['dictionaries_dir'] = ['tests/default_option_params/structure']
|
rougailconfig = RougailConfig.copy()
|
||||||
RougailConfig["default_params.unix_filename.test_existence"] = True
|
rougailconfig['dictionaries_dir'] = ['tests/default_option_params/structure']
|
||||||
eolobj = Rougail()
|
rougailconfig["default_params.unix_filename.test_existence"] = True
|
||||||
|
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||||
with raises(ValueError):
|
with raises(ValueError):
|
||||||
eolobj.get_config()
|
eolobj.run()
|
||||||
eolobj = Rougail()
|
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||||
with raises(ValueError):
|
with raises(ValueError):
|
||||||
eolobj.get_config()
|
eolobj.run()
|
||||||
RougailConfig["default_params.unix_filename.test_existence"] = False
|
rougailconfig["default_params.unix_filename.test_existence"] = False
|
||||||
eolobj = Rougail()
|
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||||
eolobj.get_config()
|
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