From 19a9eeb97520fd0e922d2ed4d5189f5f13cb3bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 3 Nov 2017 16:03:35 +0100 Subject: [PATCH 1/3] Test that THEME_STATIC_PATHS works for both dirs and files. It's documented like that. Doesn't work for files, though. --- pelican/tests/test_generators.py | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pelican/tests/test_generators.py b/pelican/tests/test_generators.py index 5f2151c3..139fda10 100644 --- a/pelican/tests/test_generators.py +++ b/pelican/tests/test_generators.py @@ -699,6 +699,53 @@ class TestStaticGenerator(unittest.TestCase): def set_ancient_mtime(self, path, timestamp=1): os.utime(path, (timestamp, timestamp)) + def test_theme_static_paths_dirs(self): + """Test that StaticGenerator properly copies also files mentioned in + TEMPLATE_STATIC_PATHS, not just directories.""" + settings = get_settings( + PATH=self.content_path, + filenames={}) + context = settings.copy() + context['staticfiles'] = [] + + StaticGenerator( + context=context, settings=settings, + path=settings['PATH'], output_path=self.temp_output, + theme=settings['THEME']).generate_output(None) + + # The content of dirs listed in THEME_STATIC_PATHS (defaulting to + # "static") is put into the output + self.assertTrue(os.path.isdir(os.path.join(self.temp_output, + "theme/css/"))) + self.assertTrue(os.path.isdir(os.path.join(self.temp_output, + "theme/fonts/"))) + + def test_theme_static_paths_files(self): + """Test that StaticGenerator properly copies also files mentioned in + TEMPLATE_STATIC_PATHS, not just directories.""" + settings = get_settings( + PATH=self.content_path, + THEME_STATIC_PATHS=['static/css/fonts.css', 'static/fonts/'], + filenames={}) + context = settings.copy() + context['staticfiles'] = [] + + StaticGenerator( + context=context, settings=settings, + path=settings['PATH'], output_path=self.temp_output, + theme=settings['THEME']).generate_output(None) + + # Only the content of dirs and files listed in THEME_STATIC_PATHS are + # put into the output, not everything from static/ + self.assertFalse(os.path.isdir(os.path.join(self.temp_output, + "theme/css/"))) + self.assertFalse(os.path.isdir(os.path.join(self.temp_output, + "theme/fonts/"))) + self.assertTrue(os.path.isfile(os.path.join(self.temp_output, + "theme/font.css"))) + self.assertTrue(os.path.isfile(os.path.join(self.temp_output, + "theme/fonts.css"))) + def test_static_excludes(self): """Test that StaticGenerator respects STATIC_EXCLUDES. """ From 430868e85934a5a048ff75a9549f316943b1dec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 3 Nov 2017 16:04:52 +0100 Subject: [PATCH 2/3] Make THEME_STATIC_PATHS work for files as well. The test passes now. --- pelican/generators.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index eb97c115..3a8909e4 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -696,14 +696,21 @@ class StaticGenerator(Generator): final_path=None): """Copy all the paths from source to destination""" for path in paths: + source_path = os.path.join(source, path) + if final_path: - copy(os.path.join(source, path), - os.path.join(output_path, destination, final_path), - self.settings['IGNORE_FILES']) + if os.path.isfile(source_path): + destination_path = os.path.join(output_path, destination, + final_path, + os.path.basename(path)) + else: + destination_path = os.path.join(output_path, destination, + final_path) else: - copy(os.path.join(source, path), - os.path.join(output_path, destination, path), - self.settings['IGNORE_FILES']) + destination_path = os.path.join(output_path, destination, path) + + copy(source_path, destination_path, + self.settings['IGNORE_FILES']) def _file_update_required(self, staticfile): source_path = os.path.join(self.path, staticfile.source_path) From 4995a5c641c21c6230e2cedaa456a78489530a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 10 Feb 2018 18:07:33 +0100 Subject: [PATCH 3/3] test: explicitly verify that all static files are present. --- pelican/tests/test_generators.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pelican/tests/test_generators.py b/pelican/tests/test_generators.py index 139fda10..804b3fdf 100644 --- a/pelican/tests/test_generators.py +++ b/pelican/tests/test_generators.py @@ -741,6 +741,17 @@ class TestStaticGenerator(unittest.TestCase): "theme/css/"))) self.assertFalse(os.path.isdir(os.path.join(self.temp_output, "theme/fonts/"))) + + self.assertTrue(os.path.isfile(os.path.join( + self.temp_output, "theme/Yanone_Kaffeesatz_400.eot"))) + self.assertTrue(os.path.isfile(os.path.join( + self.temp_output, "theme/Yanone_Kaffeesatz_400.svg"))) + self.assertTrue(os.path.isfile(os.path.join( + self.temp_output, "theme/Yanone_Kaffeesatz_400.ttf"))) + self.assertTrue(os.path.isfile(os.path.join( + self.temp_output, "theme/Yanone_Kaffeesatz_400.woff"))) + self.assertTrue(os.path.isfile(os.path.join( + self.temp_output, "theme/Yanone_Kaffeesatz_400.woff2"))) self.assertTrue(os.path.isfile(os.path.join(self.temp_output, "theme/font.css"))) self.assertTrue(os.path.isfile(os.path.join(self.temp_output,