Skip to content

test_plugins

3DEqualizer plugin tests.

These test need to be run in 3DEqualizer.

Container dataclass

Container dataclass.

Source code in client/ayon_equalizer/test/test_plugins.py
18
19
20
21
22
23
24
25
26
@dataclass
class Container:
    """Container dataclass."""

    name: str = None
    id: str = AYON_CONTAINER_ID
    namespace: str = ""
    loader: str = None
    representation: str = None

Tde4Mock

Simple class to mock few 3dequalizer functions.

Just to run the test outside the host itself.

Source code in client/ayon_equalizer/test/test_plugins.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Tde4Mock:
    """Simple class to mock few 3dequalizer functions.

    Just to run the test outside the host itself.
    """

    _notes = ""

    def isProjectUpToDate(self) -> bool:  # noqa: N802
        """Mock function to check if project is up to date."""
        return True

    def setProjectNotes(self, notes: str) -> None:  # noqa: N802
        """Mock function to set project notes."""
        self._notes = notes

    def getProjectNotes(self) -> str:  # noqa: N802
        """Mock function to get project notes."""
        return self._notes

getProjectNotes()

Mock function to get project notes.

Source code in client/ayon_equalizer/test/test_plugins.py
45
46
47
def getProjectNotes(self) -> str:  # noqa: N802
    """Mock function to get project notes."""
    return self._notes

isProjectUpToDate()

Mock function to check if project is up to date.

Source code in client/ayon_equalizer/test/test_plugins.py
37
38
39
def isProjectUpToDate(self) -> bool:  # noqa: N802
    """Mock function to check if project is up to date."""
    return True

setProjectNotes(notes)

Mock function to set project notes.

Source code in client/ayon_equalizer/test/test_plugins.py
41
42
43
def setProjectNotes(self, notes: str) -> None:  # noqa: N802
    """Mock function to set project notes."""
    self._notes = notes

TestEqualizer

Bases: TestCase

Test 3DEqualizer plugin.

Source code in client/ayon_equalizer/test/test_plugins.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
class TestEqualizer(unittest.TestCase):
    """Test 3DEqualizer plugin."""

    def test_context_data(self) -> None:
        """Test context data."""
        # ensure empty project notest

        data = get_context_data()
        assert data == {}, "context data is not empty"  # noqa: S101

        # add container
        add_container(
            Container(name="test", representation="test_A")
        )

        assert len(get_containers()) == 1, "container not added"  # noqa: S101
        assert get_containers()[0]["name"] == "test",\
            "container name is not correct"  # noqa: S101

        # add another container
        add_container(
            Container(name="test2", representation="test_B")
        )

        assert len(get_containers()) == 2, "container not added"  # noqa: S101,PLR2004
        assert get_containers()[1]["name"] == "test2",\
            "container name is not correct"  # noqa: S101

        # update container
        add_container(
            Container(name="test2", representation="test_C")
        )
        assert len(get_containers()) == 2, "container not updated"  # noqa: S101,PLR2004
        assert get_containers()[1]["representation"] == "test_C",\
            "container name is not correct"  # noqa: S101

test_context_data()

Test context data.

Source code in client/ayon_equalizer/test/test_plugins.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def test_context_data(self) -> None:
    """Test context data."""
    # ensure empty project notest

    data = get_context_data()
    assert data == {}, "context data is not empty"  # noqa: S101

    # add container
    add_container(
        Container(name="test", representation="test_A")
    )

    assert len(get_containers()) == 1, "container not added"  # noqa: S101
    assert get_containers()[0]["name"] == "test",\
        "container name is not correct"  # noqa: S101

    # add another container
    add_container(
        Container(name="test2", representation="test_B")
    )

    assert len(get_containers()) == 2, "container not added"  # noqa: S101,PLR2004
    assert get_containers()[1]["name"] == "test2",\
        "container name is not correct"  # noqa: S101

    # update container
    add_container(
        Container(name="test2", representation="test_C")
    )
    assert len(get_containers()) == 2, "container not updated"  # noqa: S101,PLR2004
    assert get_containers()[1]["representation"] == "test_C",\
        "container name is not correct"  # noqa: S101

add_container(container)

Add container to context data.

Source code in client/ayon_equalizer/test/test_plugins.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def add_container(container: Container) -> None:
    """Add container to context data."""
    context_data = get_context_data()
    containers = get_context_data().get("containers", [])

    for _container in containers:
        if _container["name"] == container.name and _container["namespace"] == container.namespace:  # noqa: E501
            containers.remove(_container)
            break

    containers.append(container)

    context_data["containers"] = containers
    update_context_data(context_data, {})

get_containers()

Get containers from context data.

Source code in client/ayon_equalizer/test/test_plugins.py
74
75
76
def get_containers() -> list:
    """Get containers from context data."""
    return get_context_data().get("containers", [])

get_context_data()

Get context data from project notes.

Source code in client/ayon_equalizer/test/test_plugins.py
53
54
55
56
def get_context_data() -> dict:
    """Get context data from project notes."""
    m = re.search(CONTEXT_REGEX, tde4.getProjectNotes())
    return json.loads(m["context"]) if m else {}

update_context_data(data, _)

Update context data in project notes.

Source code in client/ayon_equalizer/test/test_plugins.py
59
60
61
62
63
64
65
66
67
68
69
70
71
def update_context_data(data: dict, _: dict) -> None:
    """Update context data in project notes."""
    m = re.search(CONTEXT_REGEX, tde4.getProjectNotes())
    if not m:
        tde4.setProjectNotes("AYON_CONTEXT::::AYON_CONTEXT_END")
    update = json.dumps(data, indent=4)
    tde4.setProjectNotes(
        re.sub(
            CONTEXT_REGEX,
            f"AYON_CONTEXT::{update}::AYON_CONTEXT_END",
            tde4.getProjectNotes()
        )
    )