• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python post.get_meta函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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'
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:33,代码来源:test_metadata_extractors.py


示例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)
开发者ID:davidak,项目名称:nikola,代码行数:25,代码来源:test_utils.py


示例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'
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:30,代码来源:test_metadata_extractors.py


示例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)
开发者ID:jonhedson,项目名称:nikola,代码行数:25,代码来源:test_utils.py


示例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'
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:33,代码来源:test_metadata_extractors.py


示例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)
开发者ID:renatocoutinho,项目名称:nikola,代码行数:25,代码来源:test_utils.py


示例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)
开发者ID:Drooids,项目名称:nikola,代码行数:25,代码来源:test_utils.py


示例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)
开发者ID:renatocoutinho,项目名称:nikola,代码行数:26,代码来源:test_utils.py


示例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'])
开发者ID:davidak,项目名称:nikola,代码行数:8,代码来源:test_utils.py


示例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"])
开发者ID:renatocoutinho,项目名称:nikola,代码行数:8,代码来源:test_utils.py


示例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'])
开发者ID:humitos,项目名称:nikola,代码行数:9,代码来源:test_utils.py


示例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"])
开发者ID:renatocoutinho,项目名称:nikola,代码行数:10,代码来源:test_utils.py


示例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'])
开发者ID:AndreaCrotti,项目名称:nikola,代码行数:11,代码来源:test_utils.py


示例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'])
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:13,代码来源:test_utils.py


示例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)
开发者ID:Drooids,项目名称:nikola,代码行数:24,代码来源:test_utils.py



注:本文中的nikola.post.get_meta函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.apply_filters函数代码示例发布时间:2022-05-27
下一篇:
Python __main__.main函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap