当前位置: 首页>>代码示例>>Python>>正文


Python post.create函数代码示例

本文整理汇总了Python中tinkerer.post.create函数的典型用法代码示例。如果您正苦于以下问题:Python create函数的具体用法?Python create怎么用?Python create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_disqus

    def test_disqus(self):
        TEST_SHORTNAME = "test_shortname"

        # add disqus_shortname in conf.py
        utils.update_conf(
            {"disqus_shortname = None":
             'disqus_shortname = "%s"' % TEST_SHORTNAME})

        # create a post
        post.create("post1", datetime.date(2010, 10, 1))
        POST_ID = "2010/10/01/post1"
        POST_LINK = "http://127.0.0.1/blog/html/" + POST_ID + ".html"

        # build blog
        self.build()

        # ensure disqus script is added to html output
        output = os.path.join(utils.TEST_ROOT,
                              "blog", "html", "2010", "10", "01", "post1.html")
        output_html = open(output, "r").read()

        self.assertTrue(
            disqus.create_thread(TEST_SHORTNAME, POST_ID) in output_html)

        output = os.path.join(utils.TEST_ROOT,
                              "blog", "html", "index.html")
        output_html = open(output, "r").read()

        # ensure script to enable comment count is added to aggregated page
        self.assertTrue(
            disqus.enable_count(TEST_SHORTNAME) in output_html)

        # ensure comment count is added to aggregated page
        self.assertTrue(
            disqus.get_count(POST_LINK, POST_ID) in output_html)
开发者ID:lakhman,项目名称:tinkerer,代码行数:35,代码来源:test_disqus.py

示例2: test_create_with_template

 def test_create_with_template(self, render):
     post.create("with-template", template="the_template.rst")
     render.assert_called_once_with(
         "the_template.rst",
         mock.ANY,
         mock.ANY,
     )
开发者ID:lakhman,项目名称:tinkerer,代码行数:7,代码来源:test_post.py

示例3: check_posts

    def check_posts(self, filenames, posts, expected):
        # helper function which creates given list of files and posts, runs a 
        # build, then ensures expected content exists in each file
        for filename in filenames:
            with open(os.path.join(paths.root, filename), "w") as f:
                f.write("content not important")

        # posts are tuples consisting of post title and content
        # all posts are created on 2010/10/1 as date is not relevant here
        for new_post in posts:
            post.create(new_post[0], datetime.date(2010, 10, 1)).write(
                    content = new_post[1])

        # build and check output
        self.build()

        # tests are tuples consisting of file path (as a list) and the list of 
        # expected content
        for test in expected:
            with open(os.path.join(paths.html, *test[0]), "r") as f:
                content = f.read()
                for data in test[1]:
                    if data not in content:
                        print(data)
                        print(content)
                    self.assertTrue(data in content)
开发者ID:AnthonyTruchet,项目名称:tinkerer,代码行数:26,代码来源:test_patch.py

示例4: test_readmore

    def test_readmore(self):
        post.create("post1", datetime.date(2010, 10, 1)).write(
            content="Text\n\n.. more::\n\nMore text")

        self.build()

        post_path = os.path.join(
            utils.TEST_ROOT,
            "blog", "html", "2010", "10", "01", "post1.html")
        post_html = open(post_path, "r").read()

        # ensure readmore div is added to post
        self.assertTrue('<div id="more"> </div>' in post_html)

        # ensure readmore is patched in aggregated page
        index_path = os.path.join(
            utils.TEST_ROOT,
            "blog", "html", "index.html")
        index_html = open(index_path, "r").read()

        expected = (
            '<p class="readmorewrapper"><a class="readmore"'
            ' href="2010/10/01/post1.html#more">Read more...</a></p>'
        )
        self.assertTrue(expected in index_html)
开发者ID:UtahDave,项目名称:tinkerer,代码行数:25,代码来源:test_readmore.py

示例5: test_landingpage

    def test_landingpage(self):
        # set landing_page option in conf.py
        utils.update_conf(
            {"landing_page = None": 'landing_page = "%s"' % LANDING_PAGE})

        # create some posts
        for new_post in [("Post1", "Post2", "Post3")]:
            post.create(new_post[0]).write()

        # create the landing page
        page.create(LANDING_PAGE)

        self.build()

        # index.html should redirect to landing page
        self.assertTrue(
            '<meta http-equiv="REFRESH" content="0; url=./pages/%s.html" />'
            % LANDING_PAGE in self.__get_index_text())

        # there should be page1.html aggregated page
        self.assertTrue(
            os.path.exists(os.path.join(
                utils.TEST_ROOT,
                "blog",
                "html",
                "page1.html")))
开发者ID:vladris,项目名称:tinkerer,代码行数:26,代码来源:test_landingpage.py

示例6: benchmark

def benchmark(post_count, iterations):
    print("Running benchmark with %d posts, %d iterations" %
            (post_count, iterations))

    times = []

    # setup blog
    setup()

    # load content
    lorem = load_content()

    # create posts
    for i in range(post_count):
        post.create("Post %d" % i).write(
                tags="tag #%d" % i,
                content=lorem)

    for i in range(iterations):
        print("Iteration %d..." % i)

        start = datetime.datetime.now()
        cmdline.build()
        times.append(datetime.datetime.now() - start)

        print(times[-1])

    # cleanup test dir
    cleanup()

    print("Average time: %s" % (sum(times, datetime.timedelta(0)) / len(times)))
开发者ID:bbangert,项目名称:tinkerer,代码行数:31,代码来源:utils.py

示例7: test_create_without_template

 def test_create_without_template(self, render):
     post.create("no-template")
     render.assert_called_once_with(
         paths.post_template,
         mock.ANY,
         mock.ANY,
     )
开发者ID:lakhman,项目名称:tinkerer,代码行数:7,代码来源:test_post.py

示例8: test_build

    def test_build(self):
        # create a new post
        post.create("My Post", datetime.date(2010, 10, 1))

        self.build()

        # assert html is produced
        self.assertTrue(os.path.exists(
            os.path.join(utils.TEST_ROOT, "blog", "html", "2010",
                         "10", "01", "my_post.html")))
开发者ID:Brother-Simon,项目名称:tinkerer,代码行数:10,代码来源:test_cmdline.py

示例9: test_tags

    def test_tags(self):
        utils.test = self

        # create some tagged posts
        for new_post in [("Post1", "tag #1"),
                         ("Post2", "tag #2"),
                         ("Post12", "tag #1, tag #2")]:
            post.create(new_post[0], datetime.date(2010, 10, 1)).write(tags=new_post[1])

        utils.hook_extension("test_tags")
        self.build()
开发者ID:AnthonyTruchet,项目名称:tinkerer,代码行数:11,代码来源:test_tags.py

示例10: test_categories

    def test_categories(self):
        utils.test = self

        # create some posts with categories
        for new_post in [("Post1", "category #1"),
                         ("Post2", "category #2"),
                         ("Post12", "category #1, category #2")]:
            post.create(new_post[0], datetime.date(2010, 10, 1)).write(
                    categories=new_post[1])

        utils.hook_extension("test_categories")
        self.build()
开发者ID:AnthonyTruchet,项目名称:tinkerer,代码行数:12,代码来源:test_categories.py

示例11: test_missing

    def test_missing(self):
        # set landing_page option in conf.py
        utils.update_conf(
            {"landing_page = None": 'landing_page = "%s"' % LANDING_PAGE})

        # create some posts
        for new_post in [("Post1", "Post2", "Post3")]:
            post.create(new_post[0]).write()

        # hide Sphinx stderr output for the extension exception
        with mock.patch.object(sys, "stderr"):
            # build should fail
            self.build(expected_return=1)
开发者ID:vladris,项目名称:tinkerer,代码行数:13,代码来源:test_landingpage.py

示例12: test_metadata

    def test_metadata(self):
        utils.test = self

        # create some posts
        for i in range(20):
            post.create("Post %d" % i, datetime.date(2010, 10, i + 1)).write(content=" ".join("a" * 100))

        # ... and some pages
        for i in range(10):
            page.create("Page %d" % i)

        utils.hook_extension("test_metadata")
        self.build()
开发者ID:johnnywsd,项目名称:tinkerer,代码行数:13,代码来源:test_metadata.py

示例13: test_master_update

    def test_master_update(self):
        post.create("Post 1", datetime.date(2010, 10, 1))
        post.create("Post 2", datetime.date(2010, 11, 2))

        with open(tinkerer.paths.master_file, "r") as f:
            lines = f.readlines()

            for lineno, line in enumerate(lines):
                if "maxdepth" in line:
                    break

            self.assertEquals("\n", lines[lineno+1])
            self.assertEquals("   2010/11/02/post_2\n", lines[lineno+2])
            self.assertEquals("   2010/10/01/post_1\n", lines[lineno+3])
            self.assertEquals("\n", lines[lineno+4])
开发者ID:dhellmann,项目名称:tinkerer,代码行数:15,代码来源:test_post.py

示例14: test_move

    def test_move(self):
        # create a post and a page
        new_post = post.create("A post", datetime.datetime(2010, 10, 1))
        new_page = page.create("A page")

        # page and posts should be in master doc (precondition)
        lines = master.read_master()
        self.assertTrue("   %s\n" % new_post.docname in lines)
        self.assertTrue("   %s\n" % new_page.docname in lines)

        new_draft = draft.move(os.path.join(utils.TEST_ROOT, "pages", "a_page.rst"))
        self.assertTrue(os.path.exists(new_draft))

        # page should no longer be in TOC
        lines = master.read_master()
        self.assertTrue("   %s\n" % new_post.docname in lines)
        self.assertFalse("   %s\n" % new_page.docname in lines)

        new_draft = draft.move(os.path.join(utils.TEST_ROOT, "2010", "10", "01", "a_post.rst"))
        self.assertTrue(os.path.exists(new_draft))

        # post should no longer be in TOC either
        lines = master.read_master()
        self.assertFalse("   %s\n" % new_post.docname in lines)
        self.assertFalse("   %s\n" % new_page.docname in lines)
开发者ID:johnnywsd,项目名称:tinkerer,代码行数:25,代码来源:test_draft.py

示例15: test_create_dashed

    def test_create_dashed(self):
        # chdir to test root and create a dummy conf.py to set the
        # slug_word_separator
        cwd = os.getcwd()
        os.chdir(utils.TEST_ROOT)

        with open("conf.py", "w") as f:
            lines = f.write("slug_word_separator = '-'")

        # create post with current date and dash as word separator
        new_post = post.create("My __Second  Post.")

        os.chdir(cwd)

        year, month, day = tinkerer.utils.split_date()
        self.assertEquals(year, new_post.year)
        self.assertEquals(month, new_post.month)
        self.assertEquals(day, new_post.day)

        self.assertEquals(
                os.path.abspath(os.path.join(
                                    utils.TEST_ROOT, 
                                    year, 
                                    month, 
                                    day, 
                                    "my-second-post.rst")),
                new_post.path)                                        

        self.assertTrue(os.path.exists(new_post.path))
开发者ID:dhellmann,项目名称:tinkerer,代码行数:29,代码来源:test_post.py


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