예제 #1
0
def test_can_create_page_component_from_string():
    component = "A"
    # When
    actual = PageComponent.create(component=component)
    # Then
    assert isinstance(actual, PageComponent)
    assert actual.main == component
예제 #2
0
def test_can_create_page_component_from_reactive():
    component = pn.Column("A")
    # When
    actual = PageComponent.create(component=component)
    # Then
    assert isinstance(actual, PageComponent)
    assert actual.main == component
예제 #3
0
def test_can_create_page_component_from_instance_of_page_component_subclass():
    # Given
    class MyClass(PageComponent):
        pass

    component = MyClass()
    # When
    actual = PageComponent.create(component=component)
    # Then
    assert actual == component
예제 #4
0
def test_can_create_page_component_from_callable():
    # Given
    def my_func():
        return "A"

    component = my_func
    # When
    actual = PageComponent.create(component=component)
    # Then
    assert isinstance(actual, PageComponent)
    assert actual.main == my_func()
예제 #5
0
def test_can_create_page_component_from_instance_with_view_func():
    # Given
    class MyClass:  # pylint: disable=too-few-public-methods
        @staticmethod
        def view():
            return "A"

    component = MyClass()
    # When
    actual = PageComponent.create(component=component)
    # Then
    assert isinstance(actual, PageComponent)
    assert actual.main == component.view()
예제 #6
0
def test_can_create_page_component_from_instance_with_main_and_sidebar():
    # Given
    class MyClass:
        @staticmethod
        def main():
            return "A"

        @staticmethod
        def sidebar():
            return "B"

    component = MyClass()
    # When
    actual = PageComponent.create(component=component)
    # Then
    assert isinstance(actual, PageComponent)
    assert actual.main == "A"
    assert actual.sidebar == "B"
예제 #7
0
def test_can_create_page_component_from_class_with_main_and_sidebar():
    # Given
    class MyClass:  # pylint: disable=too-few-public-methods
        @staticmethod
        def main():
            return "A"

        @staticmethod
        def sidebar():
            return "B"

    component = MyClass
    # When
    actual = PageComponent.create(component=component)
    # Then
    assert isinstance(actual, PageComponent)
    assert actual.main == "A"
    assert actual.sidebar == "B"
예제 #8
0
    def _application_page_instance(self):
        # pylint: disable=unsubscriptable-object,unsupported-membership-test
        # pylint: disable=unsupported-assignment-operation
        page = self.services.page_service.page
        if not page in self._page_instances:
            instance = PageComponent.create(page.component)
            self._page_instances[page] = instance

            if instance.main and not isinstance(instance.main,
                                                pn.layout.Reactive):
                instance.main = pn.panel(instance.main)
            if instance.sidebar and not isinstance(instance.sidebar,
                                                   pn.layout.Reactive):
                instance.sidebar = pn.panel(instance.sidebar)

            if instance.main and self.services.page_service.page.restrict_max_width:
                instance.main.max_width = 1140
            else:
                instance.main.max_width = None

        return self._page_instances[page]
예제 #9
0
def test_can_create_page_component_from_page_component(page_component):
    # When
    actual = PageComponent.create(component=page_component)
    # Then
    assert actual == page_component
예제 #10
0
def page_component(page_main):
    return PageComponent(name="Page", main=page_main, sidebar="sidebar")
예제 #11
0
def gallery_page_component(gallery_page_main):
    return PageComponent(name="Gallery",
                         main=gallery_page_main,
                         sidebar="sidebar")
예제 #12
0
def home_page_component(home_page_main):
    return PageComponent(name="Home", main=home_page_main, sidebar="sidebar")