def test_sites_generation(self): '''Test generation of sites with the plugin Compare with recorded output via ``git diff``. To generate output for comparison run the command ``pelican -o test_data/output -s test_data/pelicanconf.py \ test_data/content`` Remember to remove the output/ folder before that. ''' base_path = os.path.dirname(os.path.abspath(__file__)) base_path = os.path.join(base_path, 'test_data') content_path = os.path.join(base_path, 'content') output_path = os.path.join(base_path, 'output') settings_path = os.path.join(base_path, 'pelicanconf.py') settings = read_settings(path=settings_path, override={ 'PATH': content_path, 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, 'PLUGINS': [i18ns], } ) pelican = Pelican(settings) pelican.run() # compare output out, err = subprocess.Popen( ['git', 'diff', '--no-ext-diff', '--exit-code', '-w', output_path, self.temp_path], env={'PAGER': ''}, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() self.assertFalse(out, 'non-empty `diff` stdout:\n{}'.format(out)) self.assertFalse(err, 'non-empty `diff` stderr:\n{}'.format(err))
def setUp(self, override=None): self.output_path = mkdtemp(prefix=TEST_DIR_PREFIX) self.content_path = mkdtemp(prefix=TEST_DIR_PREFIX) settings = { 'PATH': self.content_path, 'OUTPUT_PATH': self.output_path, 'PLUGINS': [linkclass], 'CACKHE_CONTENT': False, 'LINKCLASS_INTERNAL_CLASS': INTERNAL_CLASS, 'LINKCLASS_EXTERNAL_CLASS': EXTERNAL_CLASS } if override: settings.update(override) ## Generate the test Markdown source file fid = open(os.path.join(self.content_path, '%s.md' % TEST_FILE_STEM), 'w') fid.write('''Title: Test Date: [%s](%s) [%s](%s) [%s](%s) ''' % (INTERNAL_TEXT, INTERNAL_LINK, EXTERNAL_TEXT, EXTERNAL_LINK_HTTP, EXTERNAL_TEXT, EXTERNAL_LINK_HTTPS)) fid.close() ## Run teh Pelican instance self.settings = read_settings(override=settings) pelican = Pelican(settings=self.settings) pelican.run()
def compile(): settings = get_settings() p = Pelican(settings) try: p.run() except SystemExit as e: pass
def run_pelican(self, settings): implicit_settings = { # Contains just stuff that isn't required by the m.css theme itself, # but is needed to have the test setup working correctly 'RELATIVE_URLS': True, 'TIMEZONE': 'UTC', 'READERS': {'html': None}, 'SITEURL': '.', 'PATH': os.path.join(self.path), 'OUTPUT_PATH': os.path.join(self.path, 'output'), 'PAGE_PATHS': [''], 'PAGE_SAVE_AS': '{slug}.html', 'PAGE_URL': '{slug}.html', 'PAGE_EXCLUDES': ['output'], 'ARTICLE_PATHS': ['articles'], # does not exist 'FEED_ALL_ATOM': None, # Don't render feeds, we're not testing them *ever* 'THEME': '../pelican-theme', 'PLUGIN_PATHS': ['.'], 'THEME_STATIC_DIR': 'static', 'M_CSS_FILES': ['https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i', 'static/m-dark.css'], 'M_FINE_PRINT': None, 'M_DISABLE_SOCIAL_META_TAGS': True, 'DIRECT_TEMPLATES': [], 'SLUGIFY_SOURCE': 'basename' } implicit_settings.update(settings) settings = read_settings(path=None, override=implicit_settings) pelican = Pelican(settings=settings) pelican.run()
def test_generate_with_ipython2(self): '''Test generation of site with the plugin.''' base_path = os.path.dirname(os.path.abspath(__file__)) base_path = os.path.join(base_path, 'test_data') content_path = os.path.join(base_path, 'content') output_path = os.path.join(base_path, 'output') settings_path = os.path.join(base_path, 'pelicanconf.py') settings = read_settings(path=settings_path, override={ 'PATH': content_path, 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, }) pelican = Pelican(settings) pelican.run() # test existence assert os.path.exists( os.path.join(self.temp_path, 'test-ipython-notebook-nb-format-3.html')) assert os.path.exists( os.path.join(self.temp_path, 'test-ipython-notebook-nb-format-4.html'))
def test_write_only_selected(self): """Test that only the selected files are written""" settings = read_settings(path=None, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, 'WRITE_SELECTED': [ os.path.join(self.temp_path, 'oh-yeah.html'), os.path.join(self.temp_path, 'categories.html'), ], 'LOCALE': locale.normalize('en_US'), }) pelican = Pelican(settings=settings) logger = logging.getLogger() orig_level = logger.getEffectiveLevel() logger.setLevel(logging.INFO) mute(True)(pelican.run)() logger.setLevel(orig_level) self.assertLogCountEqual(count=2, msg="Writing .*", level=logging.INFO)
def test_theme_static_paths_copy(self): # the same thing with a specified set of settings should work settings = read_settings(path=SAMPLE_CONFIG, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, 'THEME_STATIC_PATHS': [ os.path.join(SAMPLES_PATH, 'very'), os.path.join(SAMPLES_PATH, 'kinda'), os.path.join(SAMPLES_PATH, 'theme_standard') ] }) pelican = Pelican(settings=settings) mute(True)(pelican.run)() theme_output = os.path.join(self.temp_path, 'theme') extra_path = os.path.join(theme_output, 'exciting', 'new', 'files') for file in ['a_stylesheet', 'a_template']: self.assertTrue(os.path.exists(os.path.join(theme_output, file))) for file in ['wow!', 'boom!', 'bap!', 'zap!']: self.assertTrue(os.path.exists(os.path.join(extra_path, file)))
def testKnitrSettings2(self): settings = read_settings(path=None, override={ 'LOAD_CONTENT_CACHE': False, 'PATH': self.contentdir, 'OUTPUT_PATH': self.outputdir, 'RMD_READER_KNITR_OPTS_CHUNK': {'fig.path' : '%s/' % self.figpath}, 'RMD_READER_KNITR_OPTS_KNIT': {'progress' : True, 'verbose': True}, 'RMD_READER_RENAME_PLOT': True, 'PLUGIN_PATHS': ['../'], 'PLUGINS': ['rmd_reader'], }) pelican = Pelican(settings=settings) pelican.run() outputfilename = os.path.join(self.outputdir,'%s.html' % self.testtitle) self.assertTrue(os.path.exists(outputfilename),'File %s was not created.' % outputfilename) imagesdir = os.path.join(self.outputdir, self.figpath) self.assertTrue(os.path.exists(imagesdir), 'figpath not created.') imagefile = os.path.join(imagesdir, os.path.splitext(os.path.split(self.contentfile)[1])[0]) + '-1-1.png' logging.debug(imagefile) self.assertTrue(os.path.exists(imagefile), 'image correctly named.') images = glob.glob('%s/*' % imagesdir) logging.debug(images) self.assertTrue(len(images) == 1,'Contents of images dir is not correct: %s' % ','.join(images))
def test_cyclic_intersite_links_no_warnings(self): settings = read_settings(path=None, override={ 'PATH': os.path.join(CURRENT_DIR, 'cyclic_intersite_links'), 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, }) pelican = Pelican(settings=settings) mute(True)(pelican.run)() # There are four different intersite links: # - one pointing to the second article from first and third # - one pointing to the first article from second and third # - one pointing to the third article from first and second # - one pointing to a nonexistent from each # If everything goes well, only the warning about the nonexistent # article should be printed. Only two articles are not sufficient, # since the first will always have _context['generated_content'] empty # (thus skipping the link resolving) and the second will always have it # non-empty, containing the first, thus always succeeding. self.assertLogCountEqual( count=1, msg="Unable to find '.*\\.rst', skipping url replacement.", level=logging.WARNING)
def test_generic_tag_with_config(self): '''Test generation of site with a generic tag that reads in a config file.''' _pj = os.path.join base_path = _pj(os.path.dirname(os.path.abspath(__file__)), 'test_data') content_path = _pj(base_path, 'content') output_path = _pj(base_path, 'output') settings_path = _pj(base_path, 'pelicanconf.py') override = { 'PATH': content_path, 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, } settings = read_settings(path=settings_path, override=override) pelican = Pelican(settings) pelican.run() # test normal tags f = _pj(self.temp_path, 'test-generic-config-tag.html') assert os.path.exists(f) assert "Tester" in open(f).read() # test differences f1 = _pj(output_path, 'test-ipython-notebook-v3.html') f2 = _pj(self.temp_path, 'test-ipython-notebook.html')
def test_generic_alt_delimiters(self): '''Test generation of site with alternatively delimited tags.''' _pj = os.path.join base_path = _pj(os.path.dirname(os.path.abspath(__file__)), 'test_data') content_path = _pj(base_path, 'content') output_path = _pj(base_path, 'output') settings_path = _pj(base_path, 'pelicanconf.py') override = { 'PATH': content_path, 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, 'LT_DELIMITERS': ('<+', '+>'), } settings = read_settings(path=settings_path, override=override) pelican = Pelican(settings) pelican.run() # test alternate delimiters f = _pj(self.temp_path, 'test-alternate-tag-delimiters.html') fc = open(f).read() assert '{% generic config author %} is stupid' in fc assert 'The Tester is smart' in fc assert 'The Tester is stupid' not in fc
def build_blog_from_git(main_dir, blog_dir): if os.path.isdir(blog_dir): shutil.rmtree( blog_dir ) # just fetch from the repo (including submodule dependencies) stdout, stderr = git.exec_command('clone', os.environ["URL_TO_GIT_REPO_HTTPS"], blog_dir, cwd=main_dir) _logger.info('Git stdout: {}, stderr: {}'.format(stdout.decode("utf-8"), stderr.decode("utf-8"))) os.chdir(blog_dir) stdout, stderr = git.exec_command( 'clone', os.environ["URL_TO_GIT_REPO_THEME_HTTPS"], blog_dir + "/" + os.environ["THEME_NAME"], cwd=blog_dir) _logger.info('Git theme stdout: {}, stderr: {}'.format( stdout.decode("utf-8"), stderr.decode("utf-8"))) settings = read_settings("publishconf.py") pelican = Pelican(settings) pelican.run() upload_recursively(blog_dir + "/output", os.environ["BUCKET_NAME"])
def test_generic_tag_with_config(self): """Test generation of site with a generic tag that reads in a config file.""" base_path = os.path.dirname(os.path.abspath(__file__)) base_path = os.path.join(base_path, "test_data") content_path = os.path.join(base_path, "content") output_path = os.path.join(base_path, "output") settings_path = os.path.join(base_path, "pelicanconf.py") settings = read_settings( path=settings_path, override={ "PATH": content_path, "OUTPUT_PATH": self.temp_path, "CACHE_PATH": self.temp_cache, }, ) pelican = Pelican(settings) pelican.run() assert os.path.exists( os.path.join(self.temp_path, "test-generic-config-tag.html")) assert ("Tester" in open( os.path.join(self.temp_path, "test-generic-config-tag.html")).read())
def setUp(self, override=None): import pdf self.temp_path = mkdtemp(prefix='pelicantests.') settings = { 'PATH': os.path.join(os.path.dirname(CUR_DIR), '..', 'test_data', 'content'), 'OUTPUT_PATH': self.temp_path, 'PLUGINS': [pdf], 'LOCALE': locale.normalize('en_US'), } if override: settings.update(override) self.settings = read_settings(override=settings) pelican = Pelican(settings=self.settings) try: pelican.run() except ValueError: logging.warn( 'Relative links in the form of |filename|images/test.png are not yet handled by the pdf generator' ) pass
def setUp(self, settings_overrides=None, count=5, categories_per_content=1, categories=None): self.temp_input_dir = tempfile.mkdtemp(prefix="cc-input-") page_directory = os.path.join(self.temp_input_dir, 'pages') os.mkdir(page_directory) self.temp_output_dir = tempfile.mkdtemp(prefix="cc-output-") if categories is None: categories = [get_random_text_and_whitespace() for _ in range(5)] self.articles = make_content( self.temp_input_dir, categories, count=count, categories_per_content=categories_per_content) self.pages = make_content( page_directory, categories, count=count, categories_per_content=categories_per_content) settings = { 'PATH': self.temp_input_dir, 'PAGE_DIR': 'pages', 'OUTPUT_PATH': self.temp_output_dir, 'PLUGINS': [cc], 'DEFAULT_DATE': (2014, 6, 8), } if settings_overrides is not None: settings.update(settings_overrides) settings = read_settings(override=settings) pelican = Pelican(settings=settings) pelican.modified_run = modified_pelican_run self.collations = pelican.modified_run(pelican)['collations']
def test_custom_generation_works(self): # the same thing with a specified set of settings should work pelican = Pelican(path=INPUT_PATH, output_path=self.temp_path, settings=read_settings(SAMPLE_CONFIG)) pelican.run() diff = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "custom"))) self.assertFilesEqual(diff)
def setUp(self, override=None): self.output_path = mkdtemp(prefix=TEST_DIR_PREFIX) self.content_path = mkdtemp(prefix=TEST_DIR_PREFIX) settings = { 'PATH': self.content_path, 'OUTPUT_PATH': self.output_path, 'PLUGINS': [linkclass], 'CACHE_CONTENT': False, 'SITEURL': 'http://example.org', 'TIMEZONE': 'UTC', 'LINKCLASS': (('INTERNAL_CLASS', INTERNAL_CLASS, ''), ('EXTERNAL_CLASS', EXTERNAL_CLASS, '')) } if override: settings.update(override) ## Generate the test Markdown source file fid = open(os.path.join(self.content_path, '%s.md' % TEST_FILE_STEM), 'w') fid.write('''Title: Test Date: 1970-01-01 This is an [%s](%s), inline-style link. This is an [%s](%s), inline-style link (with http URL). This is an [%s](%s), inline-style link (with https URL). This is an [%s][%s], reference-style link. This is an [%s][%s], reference-style link (with http URL). This is an [%s][%s], reference-style link (with https URL). [%s]: %s [%s]: %s [%s]: %s ''' % (INTERNAL_INLINE_TEXT, INTERNAL_INLINE_LINK, EXTERNAL_INLINE_TEXT_HTTP, EXTERNAL_INLINE_LINK_HTTP, EXTERNAL_INLINE_TEXT_HTTPS, EXTERNAL_INLINE_LINK_HTTP, INTERNAL_REFERENCE_TEXT, INTERNAL_REFERENCE_LABEL, EXTERNAL_REFERENCE_TEXT_HTTP, EXTERNAL_REFERENCE_LABEL_HTTP, EXTERNAL_REFERENCE_TEXT_HTTPS, EXTERNAL_REFERENCE_LABEL_HTTPS, INTERNAL_REFERENCE_LABEL, INTERNAL_REFERENCE_LINK, EXTERNAL_REFERENCE_LABEL_HTTP, EXTERNAL_REFERENCE_LINK_HTTP, EXTERNAL_REFERENCE_LABEL_HTTPS, EXTERNAL_REFERENCE_LINK_HTTPS)) fid.close() ## Run the Pelican instance self.settings = read_settings(override=settings) pelican = Pelican(settings=self.settings) saved_stdout = sys.stdout sys.stdout = StringIO() pelican.run() sys.stdout = saved_stdout
def test_custom_generation_works(self): # the same thing with a specified set of settings should work settings = read_settings(path=SAMPLE_CONFIG, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, 'LOCALE': locale.normalize('en_US'), }) pelican = Pelican(settings=settings) mute(True)(pelican.run)() self.assertDirsEqual(self.temp_path, os.path.join(OUTPUT_PATH, 'custom'))
def wksp(tmpdir): settings = get_settings( PATH=DATA_PATH, OUTPUT_PATH=tmpdir, ARTICLE_PATHS=['articles'], PAGE_PATHS=['pages'], PLUGINS=['drafts'], THEME=DATA_PATH / 'theme', ) pelican = Pelican(settings=settings) yield Workspace(tmpdir, settings, pelican)
def test_basic_generation_works(self): # when running pelican without settings, it should pick up the default # ones and generate the output without raising any exception / issuing # any warning. with patch("pelican.contents.getenv") as mock_getenv: # force getenv('USER') to always return the same value mock_getenv.return_value = "Dummy Author" pelican = Pelican(path=INPUT_PATH, output_path=self.temp_path) pelican.run() diff = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic"))) self.assertFilesEqual(diff)
def test_custom_generation_works(self): # the same thing with a specified set of settings should work settings = read_settings(filename=SAMPLE_CONFIG, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, }) pelican = Pelican(settings=settings) pelican.run() dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "custom"))) self.assertFilesEqual(recursiveDiff(dcmp))
def test_basic_generation_works(self): # when running pelican without settings, it should pick up the default # ones and generate the output without raising any exception / issuing # any warning. with temporary_folder() as temp_path: pelican = Pelican(path=INPUT_PATH, output_path=temp_path) pelican.run() diff = dircmp(temp_path, os.sep.join((OUTPUT_PATH, "basic"))) self.assertEqual(diff.left_only, []) self.assertEqual(diff.right_only, []) self.assertEqual(diff.diff_files, [])
def test_custom_generation_works(self): # the same thing with a specified set of settings should work with temporary_folder() as temp_path: pelican = Pelican(path=INPUT_PATH, output_path=temp_path, settings=read_settings(SAMPLE_CONFIG)) pelican.run() diff = dircmp(temp_path, os.sep.join((OUTPUT_PATH, "custom"))) self.assertEqual(diff.left_only, []) self.assertEqual(diff.right_only, []) self.assertEqual(diff.diff_files, [])
def test_custom_generation_works(self): # the same thing with a specified set of settings should work settings = read_settings(path=SAMPLE_CONFIG, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, 'LOCALE': locale.normalize('en_US'), }) pelican = Pelican(settings=settings) pelican.run() dcmp = dircmp(self.temp_path, os.path.join(OUTPUT_PATH, 'custom')) self.assertFilesEqual(recursiveDiff(dcmp))
def test_basic_generation_works(self): # when running pelican without settings, it should pick up the default # ones and generate correct output without raising any exception settings = read_settings(filename=None, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, }) pelican = Pelican(settings=settings) pelican.run() dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic"))) self.assertFilesEqual(recursiveDiff(dcmp))
def _test_run_without_output_file(self): import pelicanzipwriter settings = read_settings(path=None, override={ "PATH": INPUT_PATH, "OUTPUT_PATH": mkdtemp(), "CACHE_PATH": self.cache_tmp, "PLUGINS": [pelicanzipwriter], "TIMEZONE": 'UTC', "SITEURL": 'example.com', }) Pelican(settings=settings).run()
def setUp(self): self.temp_path = mkdtemp(prefix='pelicanfly.') pelicanfly_path, _ = os.path.join(os.path.split(pelicanfly.__file__)) self.pelicanfly_static = os.path.join(pelicanfly_path, 'static') self.settings = read_settings(path=None, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, 'PLUGINS': [pelicanfly] }) self.pelican = Pelican(self.settings) mute(True)(self.pelican.run)() pass
def test_order_of_generators(self): # StaticGenerator must run last, so it can identify files that # were skipped by the other generators, and so static files can # have their output paths overridden by the {attach} link syntax. pelican = Pelican(settings=read_settings(path=None)) generator_classes = pelican.get_generator_classes() self.assertTrue( generator_classes[-1] is StaticGenerator, "StaticGenerator must be the last generator, but it isn't!") self.assertIsInstance( generator_classes, collections.Sequence, "get_generator_classes() must return a Sequence to preserve order")
def test_parse_errors(self): # Verify that just an error is printed and the application doesn't # abort, exit or something. settings = read_settings(path=None, override={ 'PATH': os.path.abspath(os.path.join(CURRENT_DIR, 'parse_error')), 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, }) pelican = Pelican(settings=settings) mute(True)(pelican.run)() self.assertLogCountEqual( count=1, msg="Could not process .*parse_error.rst", level=logging.ERROR)
def test_md_extensions_deprecation(self): """Test that a warning is issued if MD_EXTENSIONS is used""" settings = read_settings(path=None, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, 'MD_EXTENSIONS': {}, }) pelican = Pelican(settings=settings) mute(True)(pelican.run)() self.assertLogCountEqual( count=1, msg="MD_EXTENSIONS is deprecated use MARKDOWN instead.", level=logging.WARNING)