コード例 #1
0
def test_that_construction_with_invalid_types_throw() -> None:
    dash_app = Dash("dummyAppName")
    run_mode = WebvizRunMode.NON_PORTABLE
    theme = WebvizConfigTheme("dummyThemeName")
    storage_folder = Path("dummyPath")

    with pytest.raises(TypeError):
        WebvizInstanceInfo().initialize(
            dash_app=cast(Dash, None),
            run_mode=run_mode,
            theme=theme,
            storage_folder=storage_folder,
        )
    with pytest.raises(TypeError):
        WebvizInstanceInfo().initialize(
            dash_app=dash_app,
            run_mode=cast(WebvizRunMode, None),
            theme=theme,
            storage_folder=storage_folder,
        )
    with pytest.raises(TypeError):
        WebvizInstanceInfo().initialize(
            dash_app=dash_app,
            run_mode=run_mode,
            theme=cast(WebvizConfigTheme, None),
            storage_folder=storage_folder,
        )
    with pytest.raises(TypeError):
        WebvizInstanceInfo().initialize(
            dash_app=dash_app,
            run_mode=run_mode,
            theme=theme,
            storage_folder=cast(Path, None),
        )
コード例 #2
0
def test_construction_with_invalid_types() -> None:
    with pytest.raises(TypeError):
        theme = WebvizConfigTheme("dummyThemeName")
        _settings_obj = WebvizSettings(cast(dict, None), theme)

    with pytest.raises(TypeError):
        shared_settings = {"somenumber": 10, "somestring": "abc"}
        _settings_obj = WebvizSettings(shared_settings,
                                       cast(WebvizConfigTheme, None))
コード例 #3
0
def test_construction_and_basic_access() -> None:
    # pylint: disable=unidiomatic-typecheck
    the_shared_settings = {"somenumber": 10, "somestring": "abc"}
    the_theme = WebvizConfigTheme("dummyThemeName")
    settings_obj = WebvizSettings(the_shared_settings, the_theme)

    copy_of_shared_settings = settings_obj.shared_settings
    assert copy_of_shared_settings is not the_shared_settings
    assert type(copy_of_shared_settings) == type(the_shared_settings)
    assert copy_of_shared_settings == the_shared_settings
    the_shared_settings["somestring"] = "MODIFIED"
    assert copy_of_shared_settings != the_shared_settings

    copy_of_theme = settings_obj.theme
    assert copy_of_theme is not the_theme
    assert type(copy_of_theme) == type(the_theme)
    assert copy_of_theme.__dict__ == the_theme.__dict__
    the_theme.theme_name = "MODIFIED"
    assert copy_of_theme.__dict__ != the_theme.__dict__
コード例 #4
0
def test_immutability() -> None:
    my_dash_app = Dash("dummyAppName")
    my_run_mode = WebvizRunMode.NON_PORTABLE
    my_theme = WebvizConfigTheme("dummyThemeName")
    my_storage_folder = Path("dummyPath")

    instance_info = WebvizInstanceInfo()
    instance_info.initialize(
        dash_app=my_dash_app,
        run_mode=my_run_mode,
        theme=my_theme,
        storage_folder=my_storage_folder,
    )

    # Ony allowed to initialize once
    with pytest.raises(RuntimeError):
        instance_info.initialize(
            dash_app=my_dash_app,
            run_mode=my_run_mode,
            theme=my_theme,
            storage_folder=my_storage_folder,
        )

    # This is ok and necessary since we want to share the actual dash app
    assert instance_info.dash_app is my_dash_app

    # This two are also ok since integer enums and Path themselves is immutable
    assert instance_info.run_mode is my_run_mode
    assert instance_info.storage_folder is my_storage_folder

    returned_theme = instance_info.theme
    assert returned_theme is not my_theme
    assert isinstance(returned_theme, WebvizConfigTheme)
    assert returned_theme.__dict__ == my_theme.__dict__
    my_theme.theme_name = "MODIFIED"
    assert returned_theme.__dict__ != my_theme.__dict__

    with pytest.raises(AttributeError):
        # pylint: disable=assigning-non-slot
        instance_info.some_new_attribute = "myAttributeValue"  # type: ignore[attr-defined]
コード例 #5
0
def test_construction_and_basic_access() -> None:
    my_dash_app = Dash("dummyAppName")
    my_run_mode = WebvizRunMode.NON_PORTABLE
    my_theme = WebvizConfigTheme("dummyThemeName")
    my_storage_folder = Path("dummyPath")

    instance_info = WebvizInstanceInfo()
    instance_info.initialize(
        dash_app=my_dash_app,
        run_mode=my_run_mode,
        theme=my_theme,
        storage_folder=my_storage_folder,
    )

    assert instance_info.dash_app is my_dash_app
    assert instance_info.run_mode is WebvizRunMode.NON_PORTABLE
    assert instance_info.theme.__dict__ == my_theme.__dict__
    assert instance_info.storage_folder == Path("dummyPath")
コード例 #6
0
def test_create_themed_layout():
    # Make an instance of the theme class
    test_theme = WebvizConfigTheme(theme_name="test")
    # Add a plotly theme to the new theme
    test_theme.plotly_theme = {
        "layout": {
            "font": {
                "family": "Arial"
            },
            "colorscale": {
                "diverging": [
                    [0, "rgb(255, 0, 0)"],
                    [0.5, "rgb(255, 255, 0)"],
                    [1, "rgb(255, 255, 255)"],
                ],
                "sequential": [
                    [0, "rgb(0, 0, 255)"],
                    [0.5, "rgb(0, 255, 0)"],
                    [1, "rgb(255, 0, 0)"],
                ],
            },
            "xaxis": {
                "title": {
                    "text": "Hi",
                    "font": {
                        "size": 10
                    }
                }
            },
            "yaxis2": {
                "color": "#000"
            },
        },
    }
    # Define a layout that should be themed
    test_layout = {
        "font": {
            "size": 12
        },
        "colorscale": {
            "sequential": [
                [0, "rgb(0, 0, 0)"],
                [0.25, "rgb(255, 0, 0)"],
                [0.5, "rgb(0, 255, 0)"],
                [0.75, "rgb(0, 0, 255)"],
                [1, "rgb(255, 255, 255)"],
            ],
        },
        "xaxis": {
            "title": {
                "text": "New",
                "standoff": 2
            },
            "type": "log"
        },
        "xaxis2": {},
        "yaxis": {
            "color": "#111"
        },
    }
    # The expected layout after theming is applied
    expected_themed_layout = {
        "font": {
            "family": "Arial",
            "size": 12
        },
        "colorscale": {
            "diverging": [
                [0, "rgb(255, 0, 0)"],
                [0.5, "rgb(255, 255, 0)"],
                [1, "rgb(255, 255, 255)"],
            ],
            "sequential": [
                [0, "rgb(0, 0, 0)"],
                [0.25, "rgb(255, 0, 0)"],
                [0.5, "rgb(0, 255, 0)"],
                [0.75, "rgb(0, 0, 255)"],
                [1, "rgb(255, 255, 255)"],
            ],
        },
        "xaxis": {
            "title": {
                "text": "New",
                "font": {
                    "size": 10
                },
                "standoff": 2
            },
            "type": "log",
        },
        "xaxis2": {
            "title": {
                "text": "Hi",
                "font": {
                    "size": 10
                }
            }
        },
        "yaxis": {
            "color": "#111"
        },
        "yaxis2": {
            "color": "#000"
        },
    }

    # Make a themed layout using the create_themed_layout method
    themed_layout = test_theme.create_themed_layout(test_layout)

    # Verify that the themed layout is as expected
    assert themed_layout == expected_themed_layout

    # Verify that the theme layout is unchanged (same as when set)
    assert test_theme.plotly_theme == {
        "layout": {
            "font": {
                "family": "Arial"
            },
            "colorscale": {
                "diverging": [
                    [0, "rgb(255, 0, 0)"],
                    [0.5, "rgb(255, 255, 0)"],
                    [1, "rgb(255, 255, 255)"],
                ],
                "sequential": [
                    [0, "rgb(0, 0, 255)"],
                    [0.5, "rgb(0, 255, 0)"],
                    [1, "rgb(255, 0, 0)"],
                ],
            },
            "yaxis2": {
                "color": "#000"
            },
            "xaxis": {
                "title": {
                    "text": "Hi",
                    "font": {
                        "size": 10
                    }
                }
            },
        },
    }

    # Verify that the test_layout unchanged (same as when set)
    assert test_layout == {
        "font": {
            "size": 12
        },
        "colorscale": {
            "sequential": [
                [0, "rgb(0, 0, 0)"],
                [0.25, "rgb(255, 0, 0)"],
                [0.5, "rgb(0, 255, 0)"],
                [0.75, "rgb(0, 0, 255)"],
                [1, "rgb(255, 255, 255)"],
            ],
        },
        "xaxis": {
            "title": {
                "text": "New",
                "standoff": 2
            },
            "type": "log"
        },
        "yaxis": {
            "color": "#111"
        },
        "xaxis2": {},
    }
コード例 #7
0
import os
import glob
from pkg_resources import get_distribution, DistributionNotFound

from webviz_config import WebvizConfigTheme

try:
    __version__ = get_distribution(__name__).version
except DistributionNotFound:
    # package is not installed
    pass

equinor_theme = WebvizConfigTheme(theme_name="equinor")

equinor_theme.external_stylesheets = [
    "https://eds-static.equinor.com/font/equinor-font.css"
]

equinor_theme.adjust_csp(
    {
        "font-src": ["https://eds-static.equinor.com"],
        "img-src": ["https://eds-static.equinor.com"],
        "style-src": ["https://eds-static.equinor.com"],
    },
    append=True,
)

equinor_theme.assets = glob.glob(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "*"))

equinor_theme.plotly_theme = {
コード例 #8
0
import glob
import pathlib

from plotly.io import templates

from webviz_config import WebvizConfigTheme

default_theme = WebvizConfigTheme(theme_name="default")  # pylint: disable=invalid-name

default_theme.assets = glob.glob(
    str(pathlib.Path(__file__).resolve().parent / "default_assets" / "*"))

default_theme.plotly_theme = templates["plotly"].to_plotly_json()
コード例 #9
0
import os
import glob
from pkg_resources import get_distribution, DistributionNotFound

from webviz_config import WebvizConfigTheme
from plotly import colors

try:
    __version__ = get_distribution(__name__).version
except DistributionNotFound:
    # package is not installed
    pass


equinor_theme = WebvizConfigTheme(theme_name="equinor")

equinor_theme.external_stylesheets = [
    "https://eds-static.equinor.com/font/equinor-font.css"
]

equinor_theme.adjust_csp(
    {
        "font-src": ["https://eds-static.equinor.com"],
        "img-src": ["https://eds-static.equinor.com"],
        "style-src": ["https://eds-static.equinor.com"],
    },
    append=True,
)

equinor_theme.assets = glob.glob(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "*")
コード例 #10
0
import os
import glob

from plotly.io import templates

from webviz_config import WebvizConfigTheme

default_theme = WebvizConfigTheme(theme_name="default")  # pylint: disable=invalid-name

default_theme.assets = glob.glob(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "default_assets",
                 "*"))

default_theme.plotly_theme = templates["plotly"].to_plotly_json()
コード例 #11
0
import os
import glob

from webviz_config import WebvizConfigTheme

default_theme = WebvizConfigTheme(theme_name="default")  # pylint: disable=invalid-name

default_theme.assets = glob.glob(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "default_assets",
                 "*"))

default_theme.plotly_layout = {
    "paper_bgcolor":
    "rgba(90, 90, 90)",
    "plot_bgcolor":
    "rgba(90, 90, 90)",
    "colorway": [
        "#14213d",
        "#3a2d58",
        "#69356a",
        "#9a3a6f",
        "#c84367",
        "#ea5954",
        "#fe7c37",
        "#ffa600",
    ],
}