class TestPelicanResume(unittest.TestCase): def setUp(self): self.temp_path = mkdtemp(prefix="pelican_resume.") self.settings = read_settings(path=None, override={ "PATH": INPUT_PATH, "OUTPUT_PATH": self.temp_path, "PLUGINS": [pelican_resume], "FEED_ALL_ATOM": None, "CATEGORY_FEED_ATOM": None, "TRANSLATION_FEED_ATOM": None, "AUTHOR_FEED_ATOM": None, "AUTHOR_FEED_RSS": None, }) self.pelican = Pelican(self.settings) self.pelican.run() def tearDown(self): rmtree(self.temp_path) def test_resume_exists(self): pdf = os.path.join(self.temp_path, "pdfs", "resume.pdf") self.assertTrue(os.path.exists(pdf)) self.assertTrue(os.stat(pdf).st_size > 0) def test_moderncv(self): self.assertTrue(os.path.exists(os.path.join(pelican_resume.CSS_DIR, "moderncv.css")))
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 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_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 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 # Don't render feeds, we don't want to test them all the time 'FEED_ALL_ATOM': None, 'CATEGORY_FEED_ATOM': None, '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 compile(): settings = get_settings() p = Pelican(settings) try: p.run() except SystemExit as e: pass
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 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 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 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_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(out))
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 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 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_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_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 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 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 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_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 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 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(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.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 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 pelican_generate(files_path): content_path = os.path.join(files_path, 'content') conf_path = os.path.join(files_path, 'pelicanconf.py') output_path = os.path.join(files_path, 'output') settings = read_settings(conf_path) pelican = Pelican( settings=settings, path=content_path, output_path=output_path, theme='notmyidea' ) pelican.run()
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() # the same thing with a specified set of settins should work with temporary_folder() as temp_path: pelican = Pelican(path=INPUT_PATH, output_path=temp_path, settings=read_settings(SAMPLE_CONFIG))
def test_if_DELETE_OUTPUT_DIRECTORY_is_true_then_raise(self): """ WHEN DELETE_OUTPUT_DIRECTORY is True THEN we'll raise an exception """ settings = read_settings(path=None, override={ 'DELETE_OUTPUT_DIRECTORY': True, 'PLUGINS': [pelican_ab]}) pelican = Pelican(settings) with self.assertRaises(RuntimeError): pelican.run()
def call_pelican(settings_path, content_path): settings_path = os.path.abspath(settings_path) content_path = os.path.abspath(content_path) settings = read_settings(settings_path) settings_dir = os.path.split(settings_path)[0] curdir = os.getcwd() os.chdir(settings_dir) settings["THEME"] = os.path.abspath(settings["THEME"]) os.chdir(curdir) p = Pelican(settings=settings) p.run()
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(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)) self.assertEqual( self.logcount_handler.count_logs(msg="Unable to find.*skipping url replacement", level=logging.WARNING), 10, msg="bad number of occurences found for this log", )
def setUp(self, override=None): self.temp_path = mkdtemp() settings = { 'PATH': os.path.join(CUR_DIR, 'content', 'TestCategory'), 'OUTPUT_PATH': self.temp_path, 'PLUGINS': ['pelican.plugins.assets', ], 'THEME': THEME_DIR, } if override: settings.update(override) self.settings = read_settings(override=settings) pelican = Pelican(settings=self.settings) pelican.run()
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: 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 setUp(self, override=None): self.temp_path = mkdtemp(prefix="pelicantests.") settings = { "PATH": os.path.join(CUR_DIR, "test_data"), "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) pelican.run()
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" 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_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(path=None, 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.sep.join((OUTPUT_PATH, "basic"))) self.assertFilesEqual(recursiveDiff(dcmp)) self.assertLogCountEqual( count=10, msg="Unable to find.*skipping url replacement", level=logging.WARNING)
def setUp(self, override=None): import assets 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': [assets], 'THEME': THEME_DIR, 'LOCALE': locale.normalize('en_US'), } if override: settings.update(override) self.settings = read_settings(override=settings) pelican = Pelican(settings=self.settings) pelican.run()
def setUp(self, override=None): self.temp_path = mkdtemp(prefix="pelicantests.") settings = { "PATH": os.path.join(CUR_DIR, "test_data"), "OUTPUT_PATH": self.temp_path, "PLUGINS": [nginx_alias_map], "LOCALE": locale.normalize("en_US"), "TIMEZONE": "UTC", "SITEURL": "https://mysite.dev", } if override: settings.update(override) self.settings = read_settings(override=settings) pelican = Pelican(settings=self.settings) pelican.run()
def setUp (self, encoding = None, base_path = 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': [md_include], 'CACHE_CONTENT': False } if base_path: include_dir = os.path.join (self.content_path, base_path) os.makedirs (include_dir) else: include_dir = self.content_path settings ['MD_INCLUDE_BASE_PATH'] = include_dir if encoding: settings ['MD_INCLUDE_ENCODING'] = encoding ## Create the article file fid = open (os.path.join (self.content_path, '%s.md' % TEST_FILE_STEM), 'w') fid.write ('''Title: Test Date: {!%s!} ''' % INCLUDE_FILENAME) fid.close () ## Create the included file if encoding: encoded_content = INCLUDED_CONTENT.decode ('utf-8').encode (encoding) else: encoded_content = INCLUDED_CONTENT fid = open (os.path.join (include_dir, INCLUDE_FILENAME), 'w') fid.write (encoded_content) fid.write ('\n') fid.close () ## Run the Pelican instance self.settings = read_settings (override = settings) pelican = Pelican (settings = self.settings) pelican.run ()
def testKnitrSettings(self): settings = read_settings(path=None, override={ 'PATH': self.contentdir, 'OUTPUT_PATH': self.outputdir, 'KNITR_OPTS_CHUNK': {'fig.path' : '%s/' % self.figpath}, '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.') images = glob.glob('%s/*' % imagesdir) self.assertTrue(len(images) == 1,'Contents of images dir is not correct: %s' % ','.join(images))
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)) self.assertEqual(self.logcount_handler.count_logs( msg="Unable to find.*skipping url replacement", level=logging.WARNING, ), 10, msg="bad number of occurences found for this log")
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_EXCLUDES': [os.path.join(self.path, 'output')], 'ARTICLE_EXCLUDES': [os.path.join(self.path, 'output')], 'FEED_ALL_ATOM': None, # Don't render feeds, we're not testing them *ever* } implicit_settings.update(settings) settings = read_settings(path=None, override=implicit_settings) pelican = Pelican(settings=settings) pelican.run()
def __execute_pelican(self, settings_override=None): """ Executes pelican. Uses the minimal config of self.settings_default (that will fail!) merged with the given additional settings. :param settings_override: dictionary with pelican setting values to set :type settings_override: dict """ if not settings_override: settings_override = {} settings = self.settings_default.copy() settings.update(settings_override) pelican_settings = read_settings( path=None, override=settings ) pelican = Pelican(settings=pelican_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_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.assertEqual( diff.left_only, [], msg="some generated " "files are absent from the expected functional " "tests output.\n" "This is probably because the HTML generated files " "changed. If these changes are normal, please refer " "to docs/contribute.rst to update the expected " "output of the functional tests.", ) self.assertEqual( diff.right_only, [], msg="some files from " "the expected functional tests output are absent " "from the current output.\n" "This is probably because the HTML generated files " "changed. If these changes are normal, please refer " "to docs/contribute.rst to update the expected " "output of the functional tests.", ) self.assertEqual( diff.diff_files, [], msg="some generated " "files differ from the expected functional tests " "output.\n" "This is probably because the HTML generated files " "changed. If these changes are normal, please refer " "to docs/contribute.rst to update the expected " "output of the functional tests.", )
def mkpelican(): """runs pelican build""" def fullthemepath(tpath): """joins theme path""" return path.join(PELIC_PATH, tpath) psettings = get_settings_from_file(PELIC_CONFIG) psettings["PATH"] = PELIC_CONTENT psettings["OUTPUT_PATH"] = PELIC_OUTPUT psettings["THEME"] = fullthemepath(psettings["THEME"]) message( "running something similar to 'pelican -t %s -s %s %s -o %s'" % (psettings["THEME"], PELIC_CONFIG, PELIC_CONTENT, PELIC_OUTPUT), shout=True, ) pinst = Pelican(configure_settings(psettings)) pinst.run()
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_EXCLUDES': [os.path.join(self.path, 'output')], 'ARTICLE_EXCLUDES': [os.path.join(self.path, 'output')], # Don't render feeds, we don't want to test them all the time 'FEED_ALL_ATOM': None, 'CATEGORY_FEED_ATOM': None } implicit_settings.update(settings) settings = read_settings(path=None, override=implicit_settings) pelican = Pelican(settings=settings) pelican.run()
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