diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index e3681fd..3628cb2 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -2,6 +2,13 @@ Changelog ================================ +1.5.7-beta +--------------------------------------- + +**Improvements:** + - Strict mode validation now checks for separators count + + 1.5.4-beta --------------------------------------- diff --git a/docs/source/usage/validating.rst b/docs/source/usage/validating.rst index 3482cfc..0acc8f7 100644 --- a/docs/source/usage/validating.rst +++ b/docs/source/usage/validating.rst @@ -14,7 +14,7 @@ Many times the only thing we need is to know if a name is valid or not for a giv - The number of expected separators must match with the rule. - If tokens have options, the given name must use one of those options. - If token is a number, validates suffix, prefix and padding. -- If strict is passed as True to the validate function, the name must match exactly the casing the rule. +- If 'strict' is passed as True to the validate function, the name must match exactly the casing of the rule and tokens and the separators counts is also matched. - If no rule names are passed to with_rules, only the active rule is validated. Let's set these Tokens and Rule. diff --git a/pyproject.toml b/pyproject.toml index b59d994..2057a4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "vfxnaming" -version = "1.5.6-beta" +version = "1.5.7-beta" authors = [ { name="Chris Granados", email="info@chrisgranados.com" }, ] diff --git a/src/vfxnaming/rules.py b/src/vfxnaming/rules.py index 50297b6..72514da 100644 --- a/src/vfxnaming/rules.py +++ b/src/vfxnaming/rules.py @@ -194,7 +194,13 @@ def validate(self, name: AnyStr, strict: bool = False, **validate_values) -> boo return False name_separators = self.__SEPARATORS_REGEX.findall(name) - if len(expected_separators) > len(name_separators): + if not strict and len(expected_separators) > len(name_separators): + logger.warning( + f"Separators count mismatch between given name '{name}':'{len(name_separators)}' " + f"and rule's pattern '{self._pattern}':'{len(expected_separators)}'." + ) + return False + elif strict and len(expected_separators) != len(name_separators): logger.warning( f"Separators count mismatch between given name '{name}':'{len(name_separators)}' " f"and rule's pattern '{self._pattern}':'{len(expected_separators)}'." diff --git a/tests/naming_test.py b/tests/naming_test.py index 987798d..2bb33a0 100644 --- a/tests/naming_test.py +++ b/tests/naming_test.py @@ -1,8 +1,7 @@ from pathlib import Path import pytest import tempfile -import types -from typing import Dict, List, Union +from typing import Dict, List from vfxnaming import naming as n import vfxnaming.rules as rules