def test_static_excludes(self): """Test that StaticGenerator respects STATIC_EXCLUDES. """ settings = get_settings(STATIC_EXCLUDES=['subdir'], PATH=self.content_path, STATIC_PATHS=[''], filenames={}) context = settings.copy() StaticGenerator(context=context, settings=settings, path=settings['PATH'], output_path=self.temp_output, theme=settings['THEME']).generate_context() staticnames = [ os.path.basename(c.source_path) for c in context['staticfiles'] ] self.assertNotIn( 'subdir_fake_image.jpg', staticnames, "StaticGenerator processed a file in a STATIC_EXCLUDES directory") self.assertIn( 'fake_image.jpg', staticnames, "StaticGenerator skipped a file that it should have included")
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/'],) context = get_context(settings, 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/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, "theme/fonts.css")))
def test_static_links(self): """Test that StaticGenerator uses files in static_links """ settings = get_settings( STATIC_EXCLUDES=['subdir'], PATH=self.content_path, STATIC_PATHS=[],) context = get_context(settings) context['static_links'] |= {'short_page.md', 'subdir_fake_image.jpg'} StaticGenerator( context=context, settings=settings, path=settings['PATH'], output_path=self.temp_output, theme=settings['THEME']).generate_context() staticfiles_names = [ os.path.basename(c.source_path) for c in context['staticfiles']] static_content_names = [ os.path.basename(c) for c in context['static_content']] self.assertIn( 'short_page.md', staticfiles_names, "StaticGenerator skipped a file that it should have included") self.assertIn( 'short_page.md', static_content_names, "StaticGenerator skipped a file that it should have included") self.assertIn( 'subdir_fake_image.jpg', staticfiles_names, "StaticGenerator skipped a file that it should have included") self.assertIn( 'subdir_fake_image.jpg', static_content_names, "StaticGenerator skipped a file that it should have included")
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) context = get_context(settings, 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 setUp(self): self.content_path = os.path.join(CUR_DIR, 'mixed_content') self.temp_content = mkdtemp(prefix='testcontent.') self.temp_output = mkdtemp(prefix='testoutput.') self.settings = get_settings() self.settings['PATH'] = self.temp_content self.settings['STATIC_PATHS'] = ["static"] self.settings['OUTPUT_PATH'] = self.temp_output os.mkdir(os.path.join(self.temp_content, "static")) self.startfile = os.path.join(self.temp_content, "static", "staticfile") self.endfile = os.path.join(self.temp_output, "static", "staticfile") self.generator = StaticGenerator( context={'filenames': {}}, settings=self.settings, path=self.temp_content, theme="", output_path=self.temp_output, )