本文整理汇总了Python中nikola.post.get_meta函数的典型用法代码示例。如果您正苦于以下问题:Python get_meta函数的具体用法?Python get_meta怎么用?Python get_meta使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_meta函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_builtin_extractors_rest
def test_builtin_extractors_rest(metadata_extractors_by, meta_twofile, meta_format):
twofile_number, twofile_expected, twofile_unexpected = meta_twofile
twofile = twofile_number == 2
format_lc, format_friendly = meta_format
source_filename = "f-rest-{0}-{1}.rst".format(twofile_number, format_lc)
metadata_filename = "f-rest-{0}-{1}.meta".format(twofile_number, format_lc)
title = 'T: reST, {0}, {1}'.format(twofile_number, format_friendly)
slug = "s-rest-{0}-{1}".format(twofile_number, format_lc)
source_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'metadata_extractors', source_filename))
metadata_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'metadata_extractors', metadata_filename))
post = FakePost(source_path, metadata_path, {}, None, metadata_extractors_by)
assert os.path.exists(source_path)
if twofile:
assert os.path.exists(metadata_path)
meta, extractor = get_meta(post, None)
assert meta
if twofile:
assert extractor is None
else:
assert extractor is metadata_extractors_by['name'][format_lc]
assert meta['title'] == title
assert meta['slug'] == slug
assert twofile_expected in meta['tags']
assert twofile_unexpected not in meta['tags']
assert 'meta' in meta['tags']
assert format_friendly in meta['tags']
assert 'reST' in meta['tags']
assert meta['date'] == '2017-07-01 00:00:00 UTC'
示例2: test_get_title_from_rest
def test_get_title_from_rest(self):
file_metadata = ".. slug: write-tests-now\n"\
".. date: 2012/09/15 19:52:05\n"\
".. tags:\n"\
".. link:\n"\
".. description:\n\n"\
"Post Title\n"\
"----------\n"
opener_mock = mock.mock_open(read_data=file_metadata)
post = dummy()
post.source_path = 'file_with_metadata'
post.metadata_path = 'file_with_metadata.meta'
with mock.patch('nikola.post.io.open', opener_mock, create=True):
meta, nsm = get_meta(post)
self.assertEqual('Post Title', meta['title'])
self.assertEqual('write-tests-now', meta['slug'])
self.assertEqual('2012/09/15 19:52:05', meta['date'])
self.assertFalse('tags' in meta)
self.assertFalse('link' in meta)
self.assertFalse('description' in meta)
self.assertTrue(nsm)
示例3: test_nikola_meta_markdown
def test_nikola_meta_markdown(metadata_extractors_by, meta_twofile):
twofile_number, twofile_expected, twofile_unexpected = meta_twofile
twofile = twofile_number == 2
source_filename = "f-markdown-{0}-nikola.md".format(twofile_number)
metadata_filename = "f-markdown-{0}-nikola.meta".format(twofile_number)
title = 'T: Markdown, {0}, Nikola'.format(twofile_number)
slug = "s-markdown-{0}-nikola".format(twofile_number)
source_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'metadata_extractors', source_filename))
metadata_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'metadata_extractors', metadata_filename))
post = FakePost(source_path, metadata_path, {}, None, metadata_extractors_by)
assert os.path.exists(source_path)
if twofile:
assert os.path.exists(metadata_path)
meta, extractor = get_meta(post, None)
if twofile:
assert extractor is None
else:
assert extractor is metadata_extractors_by['name']['nikola']
assert meta['title'] == title
assert meta['slug'] == slug
assert twofile_expected in meta['tags']
assert twofile_unexpected not in meta['tags']
assert 'meta' in meta['tags']
assert 'Nikola' in meta['tags']
assert 'Markdown' in meta['tags']
assert meta['date'] == '2017-07-01 00:00:00 UTC'
示例4: test_getting_metadata_from_content
def test_getting_metadata_from_content(self):
file_metadata = [".. title: Nikola needs more tests!\n",
".. slug: write-tests-now\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n",
"Post content\n"]
opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
post = dummy()
post.source_path = 'file_with_metadata'
post.metadata_path = 'file_with_metadata.meta'
with mock.patch('nikola.post.codecs.open', opener_mock, create=True):
meta = get_meta(post)
self.assertEqual('Nikola needs more tests!', meta['title'])
self.assertEqual('write-tests-now', meta['slug'])
self.assertEqual('2012/09/15 19:52:05', meta['date'])
self.assertFalse('tags' in meta)
self.assertFalse('link' in meta)
self.assertFalse('description' in meta)
示例5: test_compiler_metadata
def test_compiler_metadata(metadata_extractors_by, compiler_data):
compiler_cls, compiler_ext, compiler_lc, compiler_name = compiler_data
source_filename = "f-{0}-1-compiler.{1}".format(compiler_lc, compiler_ext)
metadata_filename = "f-{0}-1-compiler.meta".format(compiler_lc)
title = 'T: {0}, 1, compiler'.format(compiler_name)
slug = "s-{0}-1-compiler".format(compiler_lc)
source_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'metadata_extractors', source_filename))
metadata_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'metadata_extractors', metadata_filename))
config = {'USE_REST_DOCINFO_METADATA': True, 'MARKDOWN_EXTENSIONS': ['markdown.extensions.meta']}
site = FakeSite()
site.config.update(config)
compiler_obj = compiler_cls()
compiler_obj.set_site(site)
post = FakePost(source_path, metadata_path, config, compiler_obj, metadata_extractors_by)
class FakeBorg():
current_lang = 'en'
def __call__(self):
return self
with mock.patch('nikola.plugins.compile.' + compiler_lc + '.LocaleBorg', FakeBorg):
meta, extractor = get_meta(post, None)
assert meta['title'] == title
assert meta['slug'] == slug
assert 'meta' in meta['tags']
assert 'onefile' in meta['tags']
assert 'compiler' in meta['tags']
assert compiler_name in meta['tags']
assert meta['date'] == '2017-07-01 00:00:00 UTC'
示例6: test_get_title_from_fname
def test_get_title_from_fname(self):
file_metadata = [
".. slug: write-tests-now\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n",
]
opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
post = dummy()
post.source_path = "file_with_metadata"
post.metadata_path = "file_with_metadata.meta"
with mock.patch("nikola.post.codecs.open", opener_mock, create=True):
meta = get_meta(post, "file_with_metadata")
self.assertEqual("file_with_metadata", meta["title"])
self.assertEqual("write-tests-now", meta["slug"])
self.assertEqual("2012/09/15 19:52:05", meta["date"])
self.assertFalse("tags" in meta)
self.assertFalse("link" in meta)
self.assertFalse("description" in meta)
示例7: test_use_filename_as_slug_fallback
def test_use_filename_as_slug_fallback(self):
file_metadata = [".. title: Nikola needs more tests!\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n",
"Post content\n"]
opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
post = dummy()
post.source_path = 'Slugify this'
post.metadata_path = 'Slugify this.meta'
with mock.patch('nikola.post.io.open', opener_mock, create=True):
meta, nsm = get_meta(post, 'Slugify this')
self.assertEqual('Nikola needs more tests!', meta['title'])
self.assertEqual('slugify-this', meta['slug'])
self.assertEqual('2012/09/15 19:52:05', meta['date'])
self.assertFalse('tags' in meta)
self.assertFalse('link' in meta)
self.assertFalse('description' in meta)
self.assertTrue(nsm)
示例8: test_use_filename_as_slug_fallback
def test_use_filename_as_slug_fallback(self):
file_metadata = [
".. title: Nikola needs more tests!\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n",
"Post content\n",
]
opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
post = dummy()
post.source_path = "Slugify this"
post.metadata_path = "Slugify this.meta"
with mock.patch("nikola.post.codecs.open", opener_mock, create=True):
meta = get_meta(post, "Slugify this")
self.assertEqual("Nikola needs more tests!", meta["title"])
self.assertEqual("slugify-this", meta["slug"])
self.assertEqual("2012/09/15 19:52:05", meta["date"])
self.assertFalse("tags" in meta)
self.assertFalse("link" in meta)
self.assertFalse("description" in meta)
示例9: test_get_meta_slug_only_from_filename
def test_get_meta_slug_only_from_filename(self):
post = dummy()
post.source_path = 'some/path/the_slug.md'
post.metadata_path = 'some/path/the_slug.meta'
with mock.patch('nikola.post.io.open', create=True):
meta, _ = get_meta(post)
self.assertEqual('the_slug', meta['slug'])
示例10: test_get_meta_slug_only_from_filename
def test_get_meta_slug_only_from_filename(self):
post = dummy()
post.source_path = "some/path/the_slug.md"
post.metadata_path = "some/path/the_slug.meta"
with mock.patch("nikola.post.codecs.open", create=True):
meta = get_meta(post)
self.assertEqual("the_slug", meta["slug"])
示例11: test_get_meta_slug_only_from_filename
def test_get_meta_slug_only_from_filename(self):
dummy_opener_mock = mock.mock_open(read_data="No metadata in the file!")
post = dummy()
post.source_path = 'some/path/the_slug.md'
post.metadata_path = 'some/path/the_slug.meta'
with mock.patch('nikola.post.io.open', dummy_opener_mock, create=True):
meta = get_meta(post, None)[0]
self.assertEqual('the_slug', meta['slug'])
示例12: test_extracting_metadata_from_filename
def test_extracting_metadata_from_filename(self):
post = dummy()
post.source_path = "2013-01-23-the_slug-dubdubtitle.md"
post.metadata_path = "2013-01-23-the_slug-dubdubtitle.meta"
with mock.patch("nikola.post.codecs.open", create=True):
meta = get_meta(post, "(?P<date>\d{4}-\d{2}-\d{2})-(?P<slug>.*)-(?P<title>.*)\.md")
self.assertEqual("dubdubtitle", meta["title"])
self.assertEqual("the_slug", meta["slug"])
self.assertEqual("2013-01-23", meta["date"])
示例13: test_extracting_metadata_from_filename
def test_extracting_metadata_from_filename(self):
post = dummy()
post.source_path = '2013-01-23-the_slug-dubdubtitle.md'
post.metadata_path = '2013-01-23-the_slug-dubdubtitle.meta'
with mock.patch('nikola.post.codecs.open', create=True):
meta = get_meta(post,
'(?P<date>\d{4}-\d{2}-\d{2})-(?P<slug>.*)-(?P<title>.*)\.md')
self.assertEqual('dubdubtitle', meta['title'])
self.assertEqual('the_slug', meta['slug'])
self.assertEqual('2013-01-23', meta['date'])
示例14: test_extracting_metadata_from_filename
def test_extracting_metadata_from_filename(self):
post = dummy()
post.source_path = '2013-01-23-the_slug-dub_dub_title.md'
post.metadata_path = '2013-01-23-the_slug-dub_dub_title.meta'
post.config['FILE_METADATA_REGEXP'] = r'(?P<date>\d{4}-\d{2}-\d{2})-(?P<slug>.*)-(?P<title>.*)\.md'
for unslugify, title in ((True, 'Dub dub title'), (False, 'dub_dub_title')):
post.config['FILE_METADATA_UNSLUGIFY_TITLES'] = unslugify
with mock.patch('nikola.post.io.open', create=True):
meta = get_meta(post, None)[0]
self.assertEqual(title, meta['title'])
self.assertEqual('the_slug', meta['slug'])
self.assertEqual('2013-01-23', meta['date'])
示例15: test_get_title_from_fname
def test_get_title_from_fname(self):
file_metadata = [".. slug: write-tests-now\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n"]
opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
post = dummy()
post.source_path = 'file_with_metadata'
post.metadata_path = 'file_with_metadata.meta'
with mock.patch('nikola.post.io.open', opener_mock, create=True):
meta, nsm = get_meta(post, 'file_with_metadata')
self.assertEqual('file_with_metadata', meta['title'])
self.assertEqual('write-tests-now', meta['slug'])
self.assertEqual('2012/09/15 19:52:05', meta['date'])
self.assertFalse('tags' in meta)
self.assertFalse('link' in meta)
self.assertFalse('description' in meta)
self.assertTrue(nsm)