Пример #1
0
def test__valid() -> None:

    Globals.init(root=TestSites.valid)

    site = Site()
    site.build()

    repr(site)

    assert site.index is not None

    assert site.get_page("page-layout") is not None
    assert site.get_page("page-layout-gallery") is not None
    assert site.get_page("page-lazy") is not None
    assert site.get_page("page-lazy-gallery") is not None

    assert site.get_page("page-missing") is None

    assert site.config.title == "Testing Title"
    assert site.config.author == "Testing Author"
    assert site.config.copyright == "Testing Copyright"
    assert site.config.description == "Testing Description"
    assert site.config.favicon == "./testing-favicon.ico"

    assert site.config.header == {
        Key.TITLE: {
            Key.LABEL: "Testing Header Title Label",
            Key.IMAGE: "./testing-header-title-image.jpg",
        },
    }

    assert Globals.site_paths.static_url_path == "/site"
Пример #2
0
def test__custom_valid() -> None:

    Globals.init(root=TestSites.theme_custom_valid)

    # The directory for 'custom-theme' is located inside the site directory
    # for 'theme-custom-valid' at ./tests/data/sites/site-theme-custom-valid.
    assert Globals.theme_paths.root == TestSites.theme_custom_valid / "custom-theme"
Пример #3
0
def test__rebuild_cache() -> None:

    Globals.init(root=TestSites.valid)

    site = Site()
    site.build()
    site.rebuild_cache()
Пример #4
0
def run__Page__valid(cls: "PageClass", ptc: "PageTestConfig") -> None:

    Globals.init(root=ptc.site)

    page = cls(path=ptc.path, config=ptc.page_yaml)

    repr(page)

    assert page.config.type == ptc.type
    assert page.config.is_index is ptc.is_index
    assert page.config.title == ptc.title
    assert page.config.date == ptc.date
    assert page.config.description == ptc.path_description
    assert page.config.cover == ptc.path_cover

    assert len(page.contents) == ptc.contents_count

    for index, content in enumerate(page.contents):
        content_type: "ContentClass" = ptc.contents_types[index]
        assert isinstance(content, content_type)  # type: ignore

    assert page.directory_name == ptc.path.name
    assert page.path == ptc.path
    assert page.url == ptc.url
    assert page.is_index is ptc.is_index
    assert page.title == ptc.title
    assert page.date == ptc.datetime_date
    assert isinstance(page.description, TextBlock)
    assert isinstance(page.cover, Image)
Пример #5
0
def test__index_missing() -> None:

    Globals.init(root=TestSites.index_missing)

    site = Site()

    with pytest.raises(SiteConfigError):
        site.build()
Пример #6
0
def test__builtin_valid_default() -> None:

    Globals.init(root=TestSites.theme_builtin_valid_default)

    assert Globals.theme_paths.assets is not None
    assert Globals.theme_paths.template_main_html is not None
    assert Globals.theme_paths.template_404_html is not None
    assert Globals.theme_paths.static_url_path == "/theme"
Пример #7
0
def test__config_menu_empty() -> None:

    Globals.init(root=TestSites.config_menu_empty)

    site = Site()
    site.build()

    assert site.menu == []
Пример #8
0
def test__config_menu_missing_page() -> None:

    Globals.init(root=TestSites.config_menu_missing_page)

    site = Site()

    with pytest.raises(SiteConfigError):
        site.build()
Пример #9
0
def run__GalleryMixin__column_count_unset(cls: "PageClassGallery",
                                          ptc: "PageTestConfig") -> None:

    Globals.init(root=ptc.site)

    page = cls(path=ptc.path, config=ptc.page_yaml)

    assert page.config.options[Key.COLUMN_COUNT] is None
    assert page.column_count is None
Пример #10
0
def run__ShowCaptionsMixin__unset(cls: "PageClass",
                                  ptc: "PageTestConfig") -> None:

    Globals.init(root=ptc.site)

    page = cls(path=ptc.path, config=ptc.page_yaml)

    assert page.config.options[Key.SHOW_CAPTIONS] is False
    assert page.show_captions is False
Пример #11
0
def run__LayoutMixin__no_contents(cls: "PageClassLayout",
                                  ptc: "PageTestConfig") -> None:

    Globals.init(root=ptc.site)

    page_yaml = ptc.page_yaml.copy()
    page_yaml[Key.CONTENTS] = []

    cls(path=ptc.path, config=page_yaml)
Пример #12
0
def test__installed_valid() -> None:

    theme_path = str(TESTING_DATA_ROOT / "themes-installed")

    sys.path.append(theme_path)

    Globals.init(root=TestSites.theme_installed_valid)

    sys.path.pop()
Пример #13
0
def test__SafeDict() -> None:

    Globals.init(root=TestSites.valid)

    assert isinstance(Globals.theme_config.missing_attr, SafeDict)
    assert isinstance(Globals.theme_config["missing_item"], SafeDict)
    assert isinstance(Globals.theme_config.missing_attr.missing_attr, SafeDict)
    assert isinstance(Globals.theme_config["missing_item"]["missing_item"],
                      SafeDict)
Пример #14
0
def test__debug() -> None:

    Globals.init(root=TestSites.valid)

    Globals.debug = True
    assert Globals.debug is True

    Globals.debug = False
    assert Globals.debug is False
Пример #15
0
def test__testing() -> None:

    Globals.init(root=TestSites.valid)

    Globals.testing = True
    assert Globals.testing is True

    Globals.testing = False
    assert Globals.testing is False
Пример #16
0
def test__LazyMixin__directory_contents() -> None:

    Globals.init(root=TestSites.misc_tests)

    path = (TestSites.misc_tests / "contents" / "pages" /
            "page-test-lazy-mixin-directory-contents")

    Lazy(path=path, config={})
    LazyGallery(path=path, config={})
Пример #17
0
def test__installed_missing() -> None:

    theme_path = str(TESTING_DATA_ROOT / "themes-installed")

    sys.path.append(theme_path)

    with pytest.raises(SiteConfigError):
        Globals.init(root=TestSites.theme_installed_missing)

    sys.path.pop()
Пример #18
0
def test__not_built() -> None:

    Globals.init(root=TestSites.valid)

    site = Site()

    with pytest.raises(Error):
        site.pages

    with pytest.raises(Error):
        site.menu

    with pytest.raises(Error):
        site.index
Пример #19
0
def run__GalleryMixin__column_count_set(cls: "PageClassGallery",
                                        ptc: "PageTestConfig") -> None:

    Globals.init(root=ptc.site)

    count = 3

    page_yaml = ptc.page_yaml.copy()
    page_yaml[Key.OPTIONS] = {Key.COLUMN_COUNT: count}

    page = cls(path=ptc.path, config=page_yaml)

    assert page.config.options[Key.COLUMN_COUNT] == count
    assert page.column_count == count
Пример #20
0
def page_test_content_types() -> "PageObj":
    """Returns an instantiated Layout page referring to the page directory in
    ./tests/sites/site-misc-tests/contents/pages/page-test-content-types. This
    is primarily used to test Content-like object creation. It's a dummy page
    to pass in when a Content-like object is instantiated."""
    """ NOTE: Creating Content-like objects *requires* 'Globals.init()' to be
    called (which essentially sets 'Globals.site_paths.root'). This is because
    Content-like objects that implement 'File' must be able return their path
    relative to the site. However Menu-like and Page-like objects can be
    created without calling the 'Globals.init()'. """

    Globals.init(root=test_config__test_content_types.site)

    return Layout(
        path=test_config__test_content_types.path,
        config=test_config__test_content_types.page_yaml,
    )
Пример #21
0
def run__Page__no_date_cover_description(cls: "PageClass",
                                         ptc: "PageTestConfig") -> None:

    Globals.init(root=ptc.site)

    page_yaml = ptc.page_yaml

    del page_yaml["date"]
    del page_yaml["description"]
    del page_yaml["cover"]

    page = cls(path=ptc.path, config=page_yaml)

    assert page.config.date is None
    assert page.config.description is None
    assert page.config.cover is None

    assert page.date is None
    assert page.description is None
    assert page.cover is None
Пример #22
0
def test__custom_missing() -> None:

    with pytest.raises(SiteConfigError):
        Globals.init(root=TestSites.theme_custom_missing)
Пример #23
0
def test__custom_valid_warning() -> None:

    Globals.init(root=TestSites.theme_custom_valid_warning)
Пример #24
0
def test__SitePaths__root_missing() -> None:

    with pytest.raises(SiteConfigError):
        Globals.init(root="/path/to/missing-site")
Пример #25
0
def test__custom_missing_main_html() -> None:

    with pytest.raises(ThemeConfigError):
        Globals.init(root=TestSites.theme_custom_missing_main_html)
Пример #26
0
def test__SiteConfig__config_theme_type_invalid() -> None:

    with pytest.raises(SiteConfigError):
        Globals.init(root=TestSites.config_theme_type_invalid)
Пример #27
0
def test__SitePaths__pages_directory_empty() -> None:

    with pytest.raises(SiteConfigError):
        Globals.init(root=TestSites.pages_directory_empty)
Пример #28
0
def test__SitePaths__contents_directory_missing() -> None:

    with pytest.raises(SiteConfigError):
        Globals.init(root=TestSites.contents_directory_missing)
Пример #29
0
def test__SitePaths__missing_site_yaml() -> None:

    with pytest.raises(SiteConfigError):
        Globals.init(root=TestSites.missing_site_yaml)
Пример #30
0
def test__SitePaths__assets() -> None:

    Globals.init(root=TestSites.valid)

    Globals.site_paths.assets