diff --git a/pyproject.toml b/pyproject.toml index 9a9d9e69e..f2033c599 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,11 +26,14 @@ dependencies = [ "ruamel.yaml ~= 0.17.40", "pydantic ~= 2.5.2", "jinja2 ~= 3.1.2", - "tiramisu ~= 4.1.0", + "tiramisu ~= 4.1.0" ] -[project.optional-dependancies] + +[project.optional-dependencies] dev = [ "pylint ~= 3.0.3", + "pytest ~= 8.2.2", + "lxml ~= 5.2.2" ] [tool.commitizen] diff --git a/tests/data/dict1/dict.yml b/tests/data/dict1/dict.yml new file mode 100644 index 000000000..d0783e716 --- /dev/null +++ b/tests/data/dict1/dict.yml @@ -0,0 +1,5 @@ +# dict with a correct version declared +#version: "1.1" +hello: + type: string + default: world diff --git a/tests/data/dict2/dict.yml b/tests/data/dict2/dict.yml new file mode 100644 index 000000000..c12d1ce7e --- /dev/null +++ b/tests/data/dict2/dict.yml @@ -0,0 +1,5 @@ +# dict with a correct version declared +version: "1.0" +hello: + type: string + default: world diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 000000000..c4453afd1 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,82 @@ +from shutil import rmtree # , copyfile, copytree +from os import getcwd, makedirs +from os.path import isfile, join, isdir +from pytest import fixture, raises +from os import listdir + +from rougail import Rougail, RougailConfig +from rougail.error import DictConsistencyError + +from ruamel.yaml import YAML + +# dico_dirs = 'tests/data' +# test_ok = set() +# for test in listdir(dico_dirs): +# if isdir(join(dico_dirs, test)): +# test_ok.add(test) +# excludes = set([]) +# test_ok -= excludes + +# ORI_DIR = getcwd() + +# test_ok = list(test_ok) +# test_ok.sort() +##print(test_ok) + +# @fixture(scope="module", params=test_ok) +# def test_dir(request): +# return request.param + +""" +the kinematics are as follows: +- if no version attribute is defined in the yaml file, then the default version attribute of rougailconfig is taken +- if a version attribute is defined in the yaml file, this is the one that is taken +""" + + +def test_validate_default_version(): + "retrieves the default_dictionary_format_version if no version in the yaml file" + + RougailConfig["dictionaries_dir"] = ["tests/data/dict1"] + RougailConfig["default_dictionary_format_version"] = "1.1" + rougail = Rougail() + config = rougail.get_config() + + filename = "tests/data/dict1/dict.yml" + with open(filename, encoding="utf8") as file_fh: + objects = YAML(typ="safe").load(file_fh) + version = rougail.converted.validate_file_version(objects, filename) + assert version == RougailConfig["default_dictionary_format_version"] + + +def test_validate_file_version_from_yml(): + "retrives the yaml file version defined in the yaml file" + + RougailConfig["dictionaries_dir"] = ["tests/data/dict2"] + RougailConfig["default_dictionary_format_version"] = "1.1" + rougail = Rougail() + config = rougail.get_config() + + filename = "tests/data/dict2/dict.yml" + with open(filename, encoding="utf8") as file_fh: + objects = YAML(typ="safe").load(file_fh) + version = rougail.converted.validate_file_version(objects, filename) + assert version == "1.0" + + +def test_retrieve_version_from_config(): + + RougailConfig["dictionaries_dir"] = ["tests/data/dict2"] + RougailConfig["default_dictionary_format_version"] = "1.1" + rougail = Rougail() + # FIXME replace with rougail.annotator() + # rougail.converted.annotator() + rougail.get_config() + assert rougail.converted.paths._data["rougail.hello"].version == "1.0" + + +# def test_dictionary(test_dir): +# assert getcwd() == ORI_DIR +# test_dir = join(dico_dirs, test_dir) +# launch_test(test_dir, 'dict') +# assert getcwd() == ORI_DIR