mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
🎨 add get_versionless_id() helper (and test)
This commit is contained in:
parent
b9e430e2a5
commit
db5d997ce7
2 changed files with 33 additions and 0 deletions
|
|
@ -94,6 +94,16 @@ class TraitBase(ABC, BaseModel):
|
|||
match = re.search(version_regex, str(cls.id))
|
||||
return int(match[1]) if match else None
|
||||
|
||||
@classmethod
|
||||
def get_versionless_id(cls) -> str:
|
||||
"""Get trait ID without version.
|
||||
|
||||
Returns:
|
||||
str: Trait ID without version.
|
||||
|
||||
"""
|
||||
return re.sub(r"\.v\d+$", "", str(cls.id))
|
||||
|
||||
|
||||
class Representation:
|
||||
"""Representation of products.
|
||||
|
|
@ -416,6 +426,9 @@ class Representation:
|
|||
bool: True if the representations are equal, False otherwise.
|
||||
|
||||
"""
|
||||
if self.representation_id != other.representation_id:
|
||||
return False
|
||||
|
||||
if not isinstance(other, Representation):
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -252,6 +252,26 @@ def test_get_version_from_id() -> None:
|
|||
|
||||
assert TestMimeType(mime_type="foo/bar").get_version() is None
|
||||
|
||||
def test_get_versionless_id() -> None:
|
||||
"""Test getting versionless trait ID."""
|
||||
assert Image().get_versionless_id() == "ayon.2d.Image"
|
||||
|
||||
class TestOverscan(Overscan):
|
||||
id = "ayon.2d.Overscan.v2"
|
||||
|
||||
assert TestOverscan(
|
||||
left=0,
|
||||
right=0,
|
||||
top=0,
|
||||
bottom=0
|
||||
).get_versionless_id() == "ayon.2d.Overscan"
|
||||
|
||||
class TestMimeType(MimeType):
|
||||
id = "ayon.content.MimeType"
|
||||
|
||||
assert TestMimeType(mime_type="foo/bar").get_versionless_id() == \
|
||||
"ayon.content.MimeType"
|
||||
|
||||
|
||||
def test_from_dict() -> None:
|
||||
"""Test creating representation from dictionary."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue