本文整理汇总了Python中pelican.Pelican类的典型用法代码示例。如果您正苦于以下问题:Python Pelican类的具体用法?Python Pelican怎么用?Python Pelican使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pelican类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
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 ()
示例2: test_sites_generation
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))
示例3: test_custom_generation_works
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))
示例4: TestPelicanResume
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")))
示例5: test_custom_generation_works
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)
示例6: run_pelican
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()
示例7: setUp
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']
示例8: testKnitrSettings2
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))
示例9: test_custom_generation_works
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, [])
示例10: test_basic_generation_works
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, [])
示例11: test_custom_generation_works
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))
示例12: test_basic_generation_works
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))
示例13: test_if_DELETE_OUTPUT_DIRECTORY_is_true_then_raise
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()
示例14: call_pelican
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()
示例15: test_order_of_generators
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")