tests: tests about version
This commit is contained in:
parent
a7c862cccd
commit
80e3b73785
4 changed files with 97 additions and 2 deletions
|
@ -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]
|
||||
|
|
5
tests/data/dict1/dict.yml
Normal file
5
tests/data/dict1/dict.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
# dict with a correct version declared
|
||||
#version: "1.1"
|
||||
hello:
|
||||
type: string
|
||||
default: world
|
5
tests/data/dict2/dict.yml
Normal file
5
tests/data/dict2/dict.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
# dict with a correct version declared
|
||||
version: "1.0"
|
||||
hello:
|
||||
type: string
|
||||
default: world
|
82
tests/test_version.py
Normal file
82
tests/test_version.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue