def setUp(self): self.old_locale = locale.setlocale(locale.LC_ALL) locale.setlocale(locale.LC_ALL, str('C')) self.settings = get_settings() self.settings['READERS'] = {'asc': None} self.generator = Generator(self.settings.copy(), self.settings, CUR_DIR, self.settings['THEME'], None)
def test_theme_overrides(self): """ Test that the THEME_TEMPLATES_OVERRIDES configuration setting is utilized correctly in the Generator. """ override_dirs = (os.path.join(CUR_DIR, 'theme_overrides', 'level1'), os.path.join(CUR_DIR, 'theme_overrides', 'level2')) self.settings['THEME_TEMPLATES_OVERRIDES'] = override_dirs generator = Generator(context=self.settings.copy(), settings=self.settings, path=CUR_DIR, theme=self.settings['THEME'], output_path=None) filename = generator.get_template('article').filename self.assertEqual(override_dirs[0], os.path.dirname(filename)) self.assertEqual('article.html', os.path.basename(filename)) filename = generator.get_template('authors').filename self.assertEqual(override_dirs[1], os.path.dirname(filename)) self.assertEqual('authors.html', os.path.basename(filename)) filename = generator.get_template('taglist').filename self.assertEqual(os.path.join(self.settings['THEME'], 'templates'), os.path.dirname(filename)) self.assertNotIn(os.path.dirname(filename), override_dirs) self.assertEqual('taglist.html', os.path.basename(filename))
def test_get_files_exclude(self): """Test that Generator.get_files() properly excludes directories. """ # We use our own Generator so we can give it our own content path generator = Generator(context=self.settings.copy(), settings=self.settings, path=os.path.join(CUR_DIR, 'nested_content'), theme=self.settings['THEME'], output_path=None) filepaths = generator.get_files(paths=['maindir']) found_files = {os.path.basename(f) for f in filepaths} expected_files = {'maindir.md', 'subdir.md'} self.assertFalse(expected_files - found_files, "get_files() failed to find one or more files") filepaths = generator.get_files(paths=[''], exclude=['maindir']) found_files = {os.path.basename(f) for f in filepaths} self.assertNotIn('maindir.md', found_files, "get_files() failed to exclude a top-level directory") self.assertNotIn('subdir.md', found_files, "get_files() failed to exclude a subdir of an excluded directory") filepaths = generator.get_files(paths=[''], exclude=[os.path.join('maindir', 'subdir')]) found_files = {os.path.basename(f) for f in filepaths} self.assertNotIn('subdir.md', found_files, "get_files() failed to exclude a subdirectory") filepaths = generator.get_files(paths=[''], exclude=['subdir']) found_files = {os.path.basename(f) for f in filepaths} self.assertIn('subdir.md', found_files, "get_files() excluded a subdirectory by name, ignoring its path")
def test_custom_jinja_environment(self): """ Test that setting the JINJA_ENVIRONMENT properly gets set from the settings config """ settings = get_settings() comment_start_string = 'abc' comment_end_string = '/abc' settings['JINJA_ENVIRONMENT'] = { 'comment_start_string': comment_start_string, 'comment_end_string': comment_end_string } generator = Generator(settings.copy(), settings, CUR_DIR, settings['THEME'], None) self.assertEqual(comment_start_string, generator.env.comment_start_string) self.assertEqual(comment_end_string, generator.env.comment_end_string)
def setUp(self): self.settings = get_settings() self.settings['READERS'] = {'asc': None} self.generator = Generator(self.settings.copy(), self.settings, CUR_DIR, self.settings['THEME'], None)
def setUp(self): self.settings = get_settings() self.generator = Generator(self.settings.copy(), self.settings, CUR_DIR, self.settings['THEME'], None, self.settings['MARKUP'])