Exemplo n.º 1
0
def test_pandoc_filter_txt():
    with wrap() as wrapper:
        node = Doc("hello.md|pandoc",
            wrapper, [],
            contents = "hello",
            pandoc = { "ext" : ".txt"},
            )
        wrapper.run_docs(node)
        wrapper.report()
        assert os.path.exists("output/hello.txt")
        assert str(node.output_data()) == 'hello\n'
Exemplo n.º 2
0
def test_python_filter_record_vars():
    with wrap() as wrapper:
        doc = Doc("example.py|pycon",
                wrapper,
                [],
                pycon = { 'record-vars' :  True},
                contents = PYTHON_CONTENT
                )

        wrapper.run_docs(doc)
        assert "doc:example.py-vars.json" in wrapper.nodes
Exemplo n.º 3
0
def test_pandoc_filter_pdf():
    with wrap() as wrapper:
        node = Doc("hello.md|pandoc",
                wrapper,
                [],
                contents = "hello",
                pandoc = { "ext" : ".pdf"}
                )
        wrapper.run_docs(node)
        wrapper.report()
        assert os.path.exists("output/hello.pdf")
Exemplo n.º 4
0
def run_jinja_filter(contents):
    with wrap() as wrapper:
        doc = Doc("hello.txt|jinja",
                wrapper,
                [],
                contents = contents
                )
        wrapper.run_docs(doc)
        data = doc.output_data()
        data.data() # make sure is loaded
        return data
Exemplo n.º 5
0
def test_jinja_syntax_error():
    with wrap() as wrapper:
        wrapper.debug = False
        node = Doc("template.txt|jinja",
                wrapper,
                [],
                contents = """{% < set foo = 'bar' -%}\nfoo is {{ foo }}\n"""
                )

        wrapper.run_docs(node)
        assert wrapper.state == 'error'
Exemplo n.º 6
0
def test_access_other_documents():
    with wrap() as wrapper:
        node = Doc("hello.txt|newdoc", wrapper, [], contents="hello")
        parent = Doc("test.txt|others",
                wrapper,
                [node],
                contents="hello"
                )
        wrapper.run_docs(parent)

        expected_items = [
            "Here is a list of previous docs in this tree (not including test.txt|others).",
            "newfile.txt|processtext (0 children, 0 inputs, length 33)",
            "hello.txt|newdoc (1 children, 0 inputs, length 19)"
            ]

        output = unicode(parent.output_data())

        for item in expected_items:
            assert item in output
Exemplo n.º 7
0
def test_node_caching__slow():
    with wrap() as wrapper:
        with open("hello.py", "w") as f:
            f.write("print 1+2\n")

        with open("doc.txt", "w") as f:
            f.write("1 + 1 = {{ d['hello.py|py'] }}")

        wrapper = Wrapper(log_level='DEBUG')
        hello_py = Doc("hello.py|py", wrapper)
        doc_txt = Doc("doc.txt|jinja", wrapper, [hello_py])

        wrapper.run_docs(doc_txt)

        assert str(doc_txt.output_data()) == "1 + 1 = 3\n"
        assert str(hello_py.output_data()) == "3\n"

        assert hello_py.state == 'ran'
        assert doc_txt.state == 'ran'

        wrapper = Wrapper(log_level='DEBUG')
        hello_py = Doc("hello.py|py", wrapper)
        doc_txt = Doc("doc.txt|jinja", wrapper, [hello_py])
        wrapper.run_docs(doc_txt)

        assert hello_py.state == 'consolidated'
        assert doc_txt.state == 'consolidated'

        time.sleep(1.1)
        with open("doc.txt", "w") as f:
            f.write("1 + 1 = {{ d['hello.py|py'] }}\n")

        wrapper = Wrapper(log_level='DEBUG')
        hello_py = Doc("hello.py|py", wrapper)
        doc_txt = Doc("doc.txt|jinja", wrapper, [hello_py])
        wrapper.run_docs(doc_txt)

        assert hello_py.state == 'consolidated'
        assert doc_txt.state == 'ran'

        time.sleep(1.1)
        with open("hello.py", "w") as f:
            f.write("print 1+1\n")

        wrapper = Wrapper(log_level='DEBUG')
        hello_py = Doc("hello.py|py", wrapper)
        doc_txt = Doc("doc.txt|jinja", wrapper, [hello_py])
        wrapper.run_docs(doc_txt)

        assert hello_py.state == 'ran'
        assert doc_txt.state == 'ran'
Exemplo n.º 8
0
def test_create_doc_with_one_filter():
    with wrap() as wrapper:
        doc = Doc("foo.txt|dexy", wrapper, [], contents="foo")

        assert len(doc.filters) == 1
        f = doc.filters[0]

        assert f.doc == doc
        assert not f.prev_filter
        assert not f.next_filter

        wrapper.run_docs(doc)
Exemplo n.º 9
0
def test_generic_data_unicode():
    with wrap() as wrapper:
        doc = Doc("hello.txt", wrapper, [], contents=u"\u2042 we know\n")

        wrapper.run_docs(doc)
        data = doc.output_data()

        assert data.alias == 'generic'
        assert unicode(data) == u"\u2042 we know\n"

        assert isinstance(str(data), str)
        assert isinstance(unicode(data), unicode)
Exemplo n.º 10
0
def test_pandoc_filter_odt():
    # TODO Why isn't this checking for inactive filters?
    with wrap() as wrapper:
        node = Doc("hello.md|pandoc",
                wrapper,
                [],
                contents = "hello",
                pandoc = { "ext" : ".odt"}
                )
        wrapper.run_docs(node)
        wrapper.report()
        assert os.path.exists("output/hello.odt")
Exemplo n.º 11
0
def test_mkdirs():
    with wrap() as wrapper:
        doc = Doc("hello.c|c",
                wrapper,
                contents = C_HELLO_WORLD,
                c = {'mkdir' : 'foo', 'mkdirs' : ['bar', 'baz']}
                )
        wrapper.run_docs(doc)
        dirs = os.listdir(doc.filters[-1].workspace())
        assert 'foo' in dirs
        assert 'bar' in dirs
        assert 'baz' in dirs
Exemplo n.º 12
0
def test_rint_mock():
    with wrap() as wrapper:
        node = Doc("example.R|idio|rintmock",
                wrapper,
                [],
                contents=R_SECTIONS
                )

        wrapper.run_docs(node)
        assert node.output_data().is_cached()
        assert unicode(node.output_data()['assign-vars']) == u"> x <- 6\n> y <- 7\n> \n"
        assert unicode(node.output_data()['multiply']) == u"> x * y\n[1] 42\n> \n"
Exemplo n.º 13
0
def test_subdirectories():
    with wrap() as wrapper:
        os.makedirs("s1")
        os.makedirs("s2")

        node = Doc("file.txt|testsubdir", wrapper, [], contents="hello")

        wrapper.run_docs(node)

        env = node.filters[-1].run_plugins()
        assert 's1' in env['subdirectories'][1]
        assert 's2' in env['subdirectories'][1]
Exemplo n.º 14
0
def test_key_value_example():
    with wrap() as wrapper:
        doc = Doc(
                "hello.txt|keyvalueexample",
                wrapper,
                [],
                contents="hello"
                )

        wrapper.run_docs(doc)

        assert str(doc.output_data()) == "foo: bar"
Exemplo n.º 15
0
def test_regetron_filter():
    with wrap() as wrapper:
        wrapper.debug = False
        node = Doc(
            "example.regex|regetron",
            wrapper, [
                Doc("input1.txt", wrapper, [], contents=REGETRON_INPUT_1),
                Doc("input2.txt", wrapper, [], contents=REGETRON_INPUT_2)
            ],
            contents="^[a-z\s]+$")

        wrapper.run_docs(node)

        if not wrapper.state == 'error':
            assert str(node.output_data()['input1.txt']) == """\
> ^[a-z\s]+$
0000: hello
> 

"""
            assert str(node.output_data()['input2.txt']) == """\
Exemplo n.º 16
0
def test_jinja_filter_custom_delims():
    with wrap() as wrapper:
        node = Doc("template.tex|jinja",
                   wrapper, [],
                   contents="1 + 1 is %- 1+1 -%",
                   jinja={
                       "variable_start_string": "%-",
                       "variable_end_string": "-%"
                   })

        wrapper.run_docs(node)
        assert node.output_data().as_text() == "1 + 1 is 2"
Exemplo n.º 17
0
def test_pygments_bad_file_extension():
    with wrap() as wrapper:
        wrapper.debug = False
        doc = Doc(
                "hello.xyz|pyg",
                wrapper,
                [],
                contents=" ",
                pyg = { 'allow_unknown_ext' : False }
                )
        wrapper.run_docs(doc)
        assert wrapper.state == 'error'
Exemplo n.º 18
0
def test_jinja_pass_through():
    with wrap() as wrapper:
        with open("_template.html", "w") as f:
            f.write("{{ content }}")

        wrapper.reports = 'ws'
        contents = "{{ link(\"input.txt\") }}"
        doc = Doc(
            "lines.html|jinja",
            wrapper,
            [Doc("input.txt", wrapper, [], contents="nothing to see here")],
            contents=contents,
            apply_ws_to_content=True)
        wrapper.run_docs(doc)
        assert str(doc.output_data()) == contents

        wrapper.report()

        with open("output-site/lines.html", 'r') as f:
            lines_html = f.read()
            assert lines_html == """<a href="input.txt">Input</a>"""
Exemplo n.º 19
0
def test_command_line_args():
    with wrap() as wrapper:
        node = Doc("example.py|py",
                   wrapper, [],
                   py={"args": "-B"},
                   contents="print('hello')")
        wrapper.run_docs(node)

        assert str(node.output_data()) == "hello" + os.linesep

        command_used = node.filters[-1].command_string()
        assert command_used == "python -B  \"example.py\" "
Exemplo n.º 20
0
def test_template_filter_with_custom_filter_only():
    with wrap() as wrapper:
        node = Doc("hello.txt|testtemplatefilter",
                   wrapper, [],
                   contents="aaa equals %(aaa)s",
                   testtemplatefilter={"plugins": ["testtemplate"]})

        wrapper.run_docs(node)
        assert node.output_data().as_text() == "aaa equals 1"
        plugins_used = node.filters[-1].template_plugins()
        assert len(plugins_used) == 1
        assert isinstance(plugins_used[0], TestSimple)
Exemplo n.º 21
0
def test_assert_selector_invalid():
    with wrap() as wrapper:
        node = Doc(
            "hello.txt|jinja",
            wrapper, [
                Doc("input.html",
                    wrapper, [],
                    contents=inspect.cleandoc("""
                        <div id="foo">
                        This is contents of foo div.
                        </div>
                        """))
            ],
            contents=
            "{{ d['input.html'] | assert_selector_text('#foo', 'Not right.') }}"
        )

        try:
            wrapper.run_docs(node)
            raise Exception("should raise AssertionError")
        except AssertionError as e:
            assert str(e) == "element '#foo' did not contain 'Not right.'"
Exemplo n.º 22
0
def run_filter(alias):
    with open(markdown_file, 'r') as f:
        example_markdown = f.read()

    with wrap() as wrapper:
        node = Doc("example.md|%s" % alias,
                wrapper,
                [],
                contents = example_markdown
                )
        wrapper.run_docs(node)
        assert node.output_data().is_cached()
        return node.output_data()
Exemplo n.º 23
0
def test_scriptargs():
    with wrap() as wrapper:
        node = Doc(
            "example.py|py",
            wrapper, [],
            py={"scriptargs": "--foo"},
            contents="""import sys\nprint("args are: '%s'" % sys.argv[1])""")
        wrapper.run_docs(node)

        assert "args are: '--foo'" in str(node.output_data())

        command_used = node.filters[-1].command_string()
        assert command_used == "python   \"example.py\" --foo"
Exemplo n.º 24
0
def test_shint_filter():
    with wrap() as wrapper:
        src = """
### @export "touch"
touch newfile.txt

### @export "ls"
ls
"""
        doc = Doc("example.sh|idio|shint|pyg", wrapper, [], contents=src)
        wrapper.run_docs(doc)

        assert doc.output_data().keys() == ['1', 'touch', 'ls']
Exemplo n.º 25
0
def test_walk_working_dir():
    with wrap() as wrapper:
        node = Doc("example.sh|sh",
                   wrapper, [],
                   contents="echo 'hello' > newfile.txt",
                   sh={
                       "walk-working-dir": True,
                   })

        wrapper.run_docs(node)

        files_list = wrapper.nodes['doc:example.sh-sh.txt-files']
        assert files_list.output_data()['newfile.txt'] == "hello" + os.linesep
Exemplo n.º 26
0
def test_pytest_filter():
    raise SkipTest()  # this is running dexy's tests, not cashew's tests
    with wrap() as wrapper:
        doc = Doc("modules.txt|pytest", wrapper, [], contents="cashew")
        wrapper.run_docs(doc)
        data = doc.output_data()

        testname = "test_cashew.test_standardize_alias_or_aliases"
        assert data[testname + ':doc'] == "docstring for test"
        assert data[testname + ':name'] == "test_standardize_alias_or_aliases"
        assert data[testname + ':comments'] == "# comment before test\n"
        assert bool(data[testname + ':passed'])
        assert "def test_standardize_alias_or_aliases():" in data[testname +
                                                                  ':source']
Exemplo n.º 27
0
def test_header_footer_filters():
    with wrap() as wrapper:
        os.makedirs('subdir/subsubdir')
        node = Doc("subdir/file.txt|hd|ft",
                   wrapper, [
                       Doc("_header.txt",
                           wrapper, [],
                           contents="This is a header in parent dir."),
                       Doc("subdir/_header.txt|jinja",
                           wrapper, [],
                           contents="This is a header."),
                       Doc("subdir/_footer.txt|jinja",
                           wrapper, [],
                           contents="This is a footer."),
                       Doc("subdir/subsubdir/_header.txt",
                           wrapper, [],
                           contents="This is a header in a subdirectory.")
                   ],
                   contents="These are main contents.")

        wrapper.run_docs(node)
        assert str(node.output_data(
        )) == "This is a header.\nThese are main contents.\nThis is a footer."
Exemplo n.º 28
0
Arquivo: utils.py Projeto: dexy/dexy
        def run_example(doc_key, doc_contents):
            wrapper = make_wrapper()

            if isinstance(doc_contents, str):
                data_class = 'generic'
            else:
                data_class = 'sectioned'

            doc = Doc(doc_key,
                      wrapper, [],
                      contents=doc_contents,
                      data_class=data_class)
            wrapper.run_docs(doc)
            return doc
Exemplo n.º 29
0
def test_xxml_no_pygments():
    with wrap() as wrapper:
        doc = Doc("example.xml|xxml",
                  wrapper, [],
                  contents=XML,
                  xxml={
                      'pygments': False,
                      'ext': '.sqlite3'
                  })
        wrapper.run_docs(doc)

        assert "foo:source" in doc.output_data().keys()
        assert not "foo:html-source" in doc.output_data().keys()
        assert not "foo:latex-source" in doc.output_data().keys()
Exemplo n.º 30
0
def test_custom_name_with_args():
    with wrap() as wrapper:
        doc = Doc("data.txt",
                  wrapper, [],
                  output_name="%(bar)s/data-%(foo)s.abc",
                  foo='bar',
                  bar='baz',
                  contents="12345.67")
        wrapper.run_docs(doc)
        wrapper.report()

        assert doc.output_data().output_name() == "baz/data-bar.abc"
        assert doc.output_data().parent_output_dir() == "baz"
        assert os.path.exists("output/baz/data-bar.abc")