Skip to content

MockState class

Bases: State

A mock version of the State class that enables isolated testing of state updates.

This class can be used with the unittest or pytest Python test frameworks to test side effects of changing the values of a state:

Ex:

def test_callback():
    mock_state = MockState(Gui(""), a = 1)
    on_action(mock_state)  # function to test
    assert mock_state.a == 2

Methods

assign()

assign(name: str, value: Any) -> t.Any

Assign a value to a state variable.

This should be used only from within a lambda function used as a callback in a visual element.

Parameters:

Name Type Description Default
name str

The variable name to assign to.

required
value Any

The new variable value.

required

Returns:

Name Type Description
Any Any

The previous value of the variable.

refresh()

refresh(name: str)

Refresh a state variable.

This allows to re-sync the user interface with a variable value.

Parameters:

Name Type Description Default
name str

The variable name to refresh.

required

set_favicon()

set_favicon(favicon_path: Union[str, Path])

Change the favicon for the client of this state.

This function dynamically changes the favicon (the icon associated with the application's pages) of Taipy GUI pages for the specific client of this state.

Note that the favicon parameter to run() can also be used to change the favicon when the application starts.

Parameters:

Name Type Description Default
favicon_path Union[str, Path]

The path to the image file to use.
This can be expressed as a path name or a URL (relative or not).

required