-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from pathlib import Path | ||
from unittest import TestCase, mock | ||
|
||
from sigal.gallery import Gallery | ||
from sigal.settings import read_settings | ||
|
||
from theme_153957 import full_menu | ||
|
||
|
||
class TestFullMenu(TestCase): | ||
def get_demo_gallery(self) -> Gallery: | ||
demo_settings = str(Path(__file__).parent.parent / 'demo/sigal.conf.py') | ||
settings = read_settings(demo_settings) | ||
return Gallery(settings, ncpu=1) | ||
|
||
def test_full_tree(self) -> None: | ||
gallery = self.get_demo_gallery() | ||
|
||
full_menu.full_tree(gallery) | ||
|
||
with self.subTest('Top level albums'): | ||
self.assertEqual( | ||
['Long menu', 'Nine levels deep', 'Poles', 'Sequences', 'Time-Lapse'], | ||
list(gallery.full_tree.keys()), | ||
) | ||
|
||
with self.subTest('Subalbums'): | ||
self.assertEqual( | ||
['Candle', 'Tree'], | ||
list(gallery.full_tree['Sequences']['subalbums'].keys()), | ||
) | ||
|
||
with self.subTest('References to Album objects'): | ||
self.assertEqual(gallery.albums['Poles'], gallery.full_tree['Poles']['self']) | ||
|
||
def test_path_to_root(self) -> None: | ||
gallery = self.get_demo_gallery() | ||
|
||
with self.subTest('Top level', album='.'): | ||
album = gallery.albums['.'] | ||
full_menu.path_to_root(album) | ||
self.assertEqual('', album.path_to_root) | ||
|
||
with self.subTest('First level subalbum', album='Poles'): | ||
album = gallery.albums['Poles'] | ||
full_menu.path_to_root(album) | ||
self.assertEqual('../', album.path_to_root) | ||
|
||
with self.subTest('Over nine levels deep'): | ||
album = gallery.albums['Nine levels deep/Limbo/Lust/Gluttony/Greed/Wrath/Heresy/Violence/Fraud/Treachery'] | ||
full_menu.path_to_root(album) | ||
self.assertEqual('../' * 10, album.path_to_root) | ||
|
||
def test_path_from_root(self) -> None: | ||
gallery = self.get_demo_gallery() | ||
|
||
with self.subTest('Top level', album='.'): | ||
album = gallery.albums['.'] | ||
full_menu.path_from_root(album) | ||
self.assertEqual(album.path, album.path_from_root) | ||
|
||
with self.subTest('First level subalbum', album='Poles'): | ||
album = gallery.albums['Poles'] | ||
full_menu.path_from_root(album) | ||
self.assertEqual(album.path, album.path_from_root) | ||
|
||
with self.subTest('Over nine levels deep'): | ||
album = gallery.albums['Nine levels deep/Limbo/Lust/Gluttony/Greed/Wrath/Heresy/Violence/Fraud/Treachery'] | ||
full_menu.path_from_root(album) | ||
self.assertEqual(album.path, album.path_from_root) | ||
|
||
|
||
@mock.patch('theme_153957.full_menu.signals') | ||
def test_register(self, mock_signals: mock.MagicMock) -> None: | ||
full_menu.register({}) | ||
|
||
mock_signals.gallery_initialized.connect.assert_called_once_with(full_menu.full_tree) | ||
mock_signals.album_initialized.connect.assert_any_call(full_menu.path_to_root) | ||
mock_signals.album_initialized.connect.assert_any_call(full_menu.path_from_root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters