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
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
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
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()
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()
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"
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"
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]
def test_can_create_page_component_from_page_component(page_component): # When actual = PageComponent.create(component=page_component) # Then assert actual == page_component
def page_component(page_main): return PageComponent(name="Page", main=page_main, sidebar="sidebar")
def gallery_page_component(gallery_page_main): return PageComponent(name="Gallery", main=gallery_page_main, sidebar="sidebar")
def home_page_component(home_page_main): return PageComponent(name="Home", main=home_page_main, sidebar="sidebar")