Esempio n. 1
0
def test_pydoc_filter():
    with wrap() as wrapper:
        doc = Doc("modules.txt|pydoc", contents="os math", wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()
        assert "os.ttyname:html-source" in doc.output().keys()

        print doc.output().query("math.log")
def test_ps2pdf_filter():
    with wrap() as wrapper:
        doc = Doc("hello.ps|ps2pdf",
                contents = PS,
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().is_cached()
        assert doc.output().filesize() > 1000
def test_html2pdf_filter():
    with wrap() as wrapper:
        doc = Doc("hello.html|html2pdf",
                contents = "<p>hello</p>",
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().is_cached()
        assert doc.output().filesize() > 1000
def test_dot_filter():
    with wrap() as wrapper:
        doc = Doc("graph.dot|dot",
                contents = "digraph { a -> b } ",
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().is_cached()
        assert doc.output().filesize() > 1000
def test_rint_mock():
    with wrap() as wrapper:
        doc = Doc("example.R|idio|rintmock",
                contents=R_SECTIONS,
                wrapper=wrapper)

        wrapper.run_docs(doc)
        assert doc.output().is_cached()
        assert doc.output().as_sectioned()['assign-vars'] == "> x <- 6\n> y <- 7\n> \n"
        assert doc.output().as_sectioned()['multiply'] == "> x * y\n[1] 42\n> \n"
def test_casperjs_svg2pdf_filter():
    with wrap() as wrapper:
        orig = os.path.join(TEST_DATA_DIR, 'butterfly.svg')
        shutil.copyfile(orig, 'butterfly.svg')
        doc = Doc("butterfly.svg|svg2pdf",
                wrapper=wrapper)

        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().is_cached()
        assert doc.output().filesize() > 1000
def test_pdf2img_filter():
    with wrap() as wrapper:
        orig = os.path.join(TEST_DATA_DIR, 'color-graph.pdf')
        shutil.copyfile(orig, 'example.pdf')
        doc = Doc("example.pdf|pdf2img",
                wrapper=wrapper)

        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().is_cached()
        assert doc.output().filesize() > 1000
Esempio n. 8
0
def test_split_html_filter():
    with temprun() as runner:
        contents = """
        <p>This is at the top.</p>
        <!-- split "a-page" -->
        some content on a page
        <!-- split "another-page" -->
        some content on another page
        <!-- endsplit -->
        bottom
        """

        doc = Doc("example.html|splithtml", contents=contents, runner=runner)
        runner.docs = [doc]
        runner.run()

        assert doc.children[2].key == "a-page.html"
        assert doc.children[3].key == "another-page.html"

        od = doc.output().data()

        assert "<p>This is at the top.</p>" in od
        assert '<a href="a-page.html">' in od
        assert '<a href="another-page.html">' in od
        assert "bottom" in od

        assert "<p>This is at the top.</p>" in doc.children[2].output().data()
        assert "some content on a page" in doc.children[2].output().data()
        assert "bottom" in doc.children[2].output().data()

        assert "<p>This is at the top.</p>" in doc.children[3].output().data()
        assert "some content on another page" in doc.children[3].output().data(
        )
        assert "bottom" in doc.children[3].output().data()
Esempio n. 9
0
def test_access_other_documents():
    with temprun() as runner:
        doc = Doc("hello.txt|newdoc", contents="hello", runner=runner)
        parent = Doc("test.txt|others", doc, contents="hello", runner=runner)
        runner.docs = [parent]
        runner.run()
        assert parent.output().data() == """Here is a list of previous docs in this tree (not including test.txt|others).
Esempio n. 10
0
def test_split_html_filter():
    with wrap() as wrapper:
        contents="""
        <p>This is at the top.</p>
        <!-- split "a-page" -->
        some content on a page
        <!-- split "another-page" -->
        some content on another page
        <!-- endsplit -->
        bottom
        """

        doc = Doc("subdir/example.html|splithtml", contents=contents, wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()

        assert doc.children[2].key == "subdir/a-page.html"
        assert doc.children[3].key == "subdir/another-page.html"

        od = doc.output().data()

        assert "<p>This is at the top.</p>" in od
        assert '<a href="a-page.html">' in od
        assert '<a href="another-page.html">' in od
        assert "bottom" in od

        assert "<p>This is at the top.</p>" in doc.children[2].output().data()
        assert "some content on a page" in doc.children[2].output().data()
        assert "bottom" in doc.children[2].output().data()

        assert "<p>This is at the top.</p>" in doc.children[3].output().data()
        assert "some content on another page" in doc.children[3].output().data()
        assert "bottom" in doc.children[3].output().data()
Esempio n. 11
0
def test_access_other_documents():
    with temprun() as runner:
        doc = Doc("hello.txt|newdoc", contents="hello", runner=runner)
        parent = Doc("test.txt|others", doc, contents="hello", runner=runner)
        runner.docs = [parent]
        runner.run()
        assert parent.output().data(
        ) == """Here is a list of previous docs in this tree (not including test.txt|others).
def test_rst2odt():
    with wrap() as wrapper:
        doc = Doc("example.txt|rst2odt",
                contents=RST,
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().filesize() > 8000
Esempio n. 13
0
def test_key_value_example():
    with wrap() as wrapper:
        doc = Doc("hello.txt|keyvalueexample", contents="hello", wrapper=wrapper)

        wrapper.docs = [doc]
        wrapper.run()

        assert doc.output().as_text() == "foo: bar"
Esempio n. 14
0
def test_java_filter():
    with wrap() as wrapper:
        doc = Doc("hello.java|java",
                contents=JAVA_SRC,
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().data() == "Java Hello World!\n"
Esempio n. 15
0
def test_choose_extension_from_overlap():
    with wrap() as wrapper:
        doc = Doc("hello.py|pyg|forcelatex",
                contents="""print "hello, world" """,
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()
        assert "begin{Verbatim}" in doc.output().as_text()
Esempio n. 16
0
def test_wordpress(MockXmlrpclib):
    with wrap() as wrapper:
        with open("wordpress.json", "wb") as f:
            json.dump({}, f)

        with open(".dexyapis", "wb") as f:
            json.dump({
                'wordpress' : {
                    'url' : 'http://example.com',
                    'username' : 'foo',
                    'password' : 'bar'
                    }}, f)

        # Create new (unpublished) draft
        doc = mk_wp_doc(wrapper)
        wrapper.run_docs(doc)

        with open("wordpress.json", "rb") as f:
            result = json.load(f)

        assert result['postid'] == 42
        assert result['publish'] == False

        # Update existing draft
        doc = mk_wp_doc(wrapper)
        wrapper.run_docs(doc)
        assert doc.output().json_as_dict().keys() == ['permaLink']

        result['publish'] = True
        with open("wordpress.json", "wb") as f:
            json.dump(result, f)

        # Publish existing draft
        doc = mk_wp_doc(wrapper)
        wrapper.run_docs(doc)
        assert doc.output().as_text() == "http://example.com/blog/42"

        # Now, separately, test an image upload.
        orig = os.path.join(TEST_DATA_DIR, 'color-graph.pdf')
        shutil.copyfile(orig, 'example.pdf')
        doc = Doc("example.pdf|wp",
                wrapper=wrapper)

        with open(".dexyapis", "wb") as f:
            json.dump({
                'wordpress' : {
                    'url' : 'http://example.com',
                    'username' : 'foo',
                    'password' : 'bar'
                    }}, f)

        wrapper.run_docs(doc)
        assert doc.output().as_text() == "http://example.com/example.pdf"

        # test list categories
        with divert_stdout() as stdout:
            WordPressFilter.docmd_list_categories()
            assert stdout.getvalue() == "categoryName\nfoo\nbar\n"
def test_jinjatext_filter_tex_extension():
    with wrap() as wrapper:
        doc = Doc("template.tex|jinjatext",
                contents = "1 + 1 is << 1+1 >>",
                wrapper=wrapper)

        wrapper.run_docs(doc)

        assert doc.output().as_text() == "1 + 1 is 2"
def test_jinja_filter_set_vars():
    with wrap() as wrapper:
        doc = Doc("template.txt|jinja",
                contents = """{% set foo = 'bar' -%}\nfoo is {{ foo }}\n""",
                wrapper=wrapper)

        wrapper.run_docs(doc)

        assert doc.output().as_text() == "foo is bar"
def test_ht_latex():
    with wrap() as wrapper:
        doc = Doc("article.tex|htlatex",
                contents=LATEX,
                wrapper=wrapper)

        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().is_cached()
def test_jinjatext_filter():
    with wrap() as wrapper:
        doc = Doc("template.txt|jinjatext",
                contents = "1 + 1 is {{ 1+1 }}",
                wrapper=wrapper)

        wrapper.run_docs(doc)

        assert doc.output().as_text() == "1 + 1 is 2"
Esempio n. 21
0
def test_force_text():
    with wrap() as wrapper:
        doc = Doc("example.py|idio|t",
                contents="print 'hello'\n",
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()

        assert doc.output().as_text() == "print 'hello'\n"
Esempio n. 22
0
def test_custom_file_extension():
    with wrap() as wrapper:
        doc = Doc("hello.py|pyg",
                contents="""print "hello, world" """,
                pyg = { "ext" : ".tex" },
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()
        assert "begin{Verbatim}" in doc.output().as_text()
Esempio n. 23
0
def test_html():
    with wrap() as wrapper:
        doc = Doc("example.py|pyg|h",
                contents="print 'hello'\n",
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()

        assert """<div class="highlight">""" in doc.output().as_text()
Esempio n. 24
0
def test_force_latex():
    with wrap() as wrapper:
        doc = Doc("example.py|idio|l",
                contents="print 'hello'\n",
                wrapper=wrapper)
        wrapper.docs = [doc]
        wrapper.run()

        assert "begin{Verbatim}" in doc.output().as_text()
def test_rest_to_tex():
    with wrap() as wrapper:
        doc = Doc("example.txt|rst",
                contents=RST,
                rst={"ext" : ".tex"},
                wrapper=wrapper)

        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().as_text() == """\
def test_espeak_filter():
    with wrap() as wrapper:
        doc = Doc("subdir/hello.txt|espeak",
                contents="hello",
                wrapper=wrapper)

        wrapper.docs = [doc]
        wrapper.run()

        assert doc.output().is_cached()
Esempio n. 27
0
def test_custom_env_in_args():
    with wrap() as wrapper:
        doc = Doc("example.py|py",
                py={"env" : {"FOO" : "bar" }},
                wrapper=wrapper,
                contents="import os\nprint os.environ['FOO']"
                )
        wrapper.docs = [doc]
        wrapper.run()

        assert doc.output().data() == "bar\n"
def test_jinja_filter_inputs():
    with wrap() as wrapper:
        doc = Doc("template.txt|jinja",
                Doc("input.txt",
                    contents = "I am the input.",
                    wrapper=wrapper),
                contents = "The input is '{{ d['input.txt'] }}'",
                wrapper=wrapper)

        wrapper.run_docs(doc)

        assert doc.output().as_text() == "The input is 'I am the input.'"
Esempio n. 29
0
def test_access_other_documents():
    with wrap() as wrapper:
        doc = Doc("hello.txt|newdoc", contents="hello", wrapper=wrapper)
        parent = Doc("test.txt|others", doc, contents="hello", wrapper=wrapper)
        wrapper.docs = [parent]
        wrapper.run()
        assert (
            parent.output().data()
            == """Here is a list of previous docs in this tree (not including test.txt|others).
        hello.txt|newdoc (3 children, 2 artifacts, length 19)
        newfile.txt|processtext (2 children, 2 artifacts, length 33)"""
        )
def test_jinjatext_filter_custom_delims():
    with wrap() as wrapper:
        doc = Doc("template.tex|jinjatext",
                contents = "1 + 1 is %- 1+1 -%",
                jinjatext = {
                    "variable_start_string" : "%-",
                    "variable_end_string" : "-%"
                    },
                wrapper=wrapper)

        wrapper.run_docs(doc)

        assert doc.output().as_text() == "1 + 1 is 2"
def test_template_filter_with_custom_filter_only():
    with wrap() as wrapper:
        doc = Doc("hello.txt|testtemplatefilter",
                contents = "aaa equals %(aaa)s",
                testtemplatefilter = { "plugins" : ["testtemplate"] },
                wrapper=wrapper)

        wrapper.run_docs(doc)

        assert doc.output().as_text() == "aaa equals 1"
        plugins_used = doc.final_artifact.filter_instance.template_plugins()
        assert len(plugins_used) == 1
        assert plugins_used[0] == TestSimple
Esempio n. 32
0
def test_clang_input():
    with wrap() as wrapper:
        doc = Doc("copy.c|clanginput",
                Doc("input.txt",
                    contents = "hello, c",
                    wrapper=wrapper),

                contents = C_WITH_INPUT,
                wrapper=wrapper)

        wrapper.docs = [doc]
        wrapper.run()
        assert doc.output().as_text() == "hello, c"
Esempio n. 33
0
def test_pydoc_filter():
    with temprun() as runner:
        doc = Doc("modules.txt|pydoc", contents="dexy", runner=runner)
        runner.docs = [doc]
        runner.run()
        assert "dexy.artifact.Artifact.__class__:source" in doc.output().keys()
Esempio n. 34
0
def test_tags_filter():
    with temprun() as runner:
        doc = Doc("example.txt|tags", contents="<p>the text</p>", tags={"tags" : ["html", "body"]}, runner=runner)
        runner.docs = [doc]
        runner.run()
        assert doc.output().data() == "<html><body>\n<p>the text</p>\n</body></html>"
Esempio n. 35
0
def test_key_value_example():
    with temprun() as runner:
        doc = Doc("hello.txt|keyvalueexample", contents="hello", runner=runner)
        runner.docs = [doc]
        runner.run()
        assert doc.output().as_text() == "foo: bar"
Esempio n. 36
0
def test_word_wrap_filter():
    with temprun() as runner:
        doc = Doc("example.txt|wrap", contents="this is a line of text", wrap={"width" : 5}, runner=runner)
        runner.docs = [doc]
        runner.run()
        assert doc.output().data() == "this\nis a\nline\nof\ntext"
Esempio n. 37
0
def test_output_is_data():
    with temprun() as runner:
        doc = Doc("abc.txt", contents="these are the contents", runner=runner)
        runner.run_tasks(doc)
        assert isinstance(doc.output(), Data)