Esempio n. 1
0
def test_idio_filter_recognizes_startinline_as_lexer_option():
    for doc in run_dexy(TEST_IDIO_LEXER_OPTION_CONFIG):
        doc.run()
        assert doc.key() == "code.php|idio"
        assert """<span class="mi">""" in doc.output()

    TEST_IDIO_LEXER_OPTION_CONFIG["."]["@code.php|idio"]["idio"]["lexer-startinline"] = False

    for doc in run_dexy(TEST_IDIO_LEXER_OPTION_CONFIG):
        doc.run()
        assert doc.key() == "code.php|idio"
        assert not """<span class="mi">""" in doc.output()
        assert """<span class="x">""" in doc.output()
Esempio n. 2
0
def test_ignore_errors_controller():
    """
    Ensure we can ignore errors by setting the controller-wide param 'ignore' to true.
    """
    args = { "ignore" : True }
    for doc in run_dexy(TRIGGER_EXCEPTIONS_CONFIG, args):
        doc.run()
Esempio n. 3
0
def test_run():
    filters = dexy.introspect.filters()
    tested_filter_classes = []

    args = {}
    for doc in run_dexy(TRIGGER_EXCEPTIONS_CONFIG, args):
        if not doc.key() in tests_to_skip():
            try:
                doc.run()
                if not doc.key() in ["input.txt"]:
                    assert False, "expected exception for %s" % doc.key()
            except dexy.commands.UserFeedback:
                tested_filter_alias = doc.filters[-1]
                tested_filter_classes.append(filters[tested_filter_alias])
                assert True
        else:
            tested_filter_alias = doc.filters[-1]
            tested_filter_classes.append(filters[tested_filter_alias])

    for filter_class in filters.values():
        is_text_process_filter = issubclass(filter_class, ProcessFilter) and not filter_class.BINARY
        check_return = is_text_process_filter and filter_class.CHECK_RETURN_CODE
        not_tested = not filter_class in tested_filter_classes
        must_test = not filter_class.__name__ in DONT_KNOW_HOW_TO_TEST

        if is_text_process_filter and check_return and not_tested and must_test:
            raise Exception("class %s not tested! aliases: %s" % (filter_class.__name__, ", ".join(filter_class.ALIASES)))
Esempio n. 4
0
def test_basic_filter():
    for doc in run_dexy(CONFIG):
        doc.run()
        artifact = doc.last_artifact
        assert artifact.ext == ".json"
        artifact.setup_kv_storage()
        assert "Directory tree generator." in artifact["os.walk:doc"]
        assert "Directory tree generator." in artifact._storage.retrieve("os.walk:doc")
Esempio n. 5
0
def test_python_create_files():
    contents = """with open("new-file.txt", "w") as f:\n    f.write("hello!")\n"""
    config = {"." : { "@example.py|pycon" : {"pycon": {"ext" : ".json", "meta" : True}, "contents" : contents }}}
    for doc in run_dexy(config):
        doc.run()
        artifact = doc.last_artifact

        kv_artifact = artifact.inputs().values()[0]
        kv_artifact.setup_kv_storage()
        assert kv_artifact['1:files:new-file.txt'] == "hello!"
Esempio n. 6
0
def test_html():
    contents = """<div id="abc">def</div>"""
    config = {"." : { "@example.html|htmlsec" : {"contents" : contents }}}

    for doc in run_dexy(config):
        doc.run()
        artifact = doc.last_artifact
        artifact.setup_kv_storage()
        assert artifact['abc:text'] == "def"
        assert artifact['abc:source'] == contents
Esempio n. 7
0
def test_filter_storage():
    set_filter_list([ConvertLinesToKeyValueStorageFilter])
    for doc in run_dexy(CONFIG):
        doc.run()
        artifact = doc.last_artifact
        artifact.setup_kv_storage()
        assert artifact["1"] == "This is the first line."
        assert artifact["2"] == "This is the 2nd line."
        assert artifact._storage.mode == "read"
        assert artifact._storage.keys() == ["1", "2"]
Esempio n. 8
0
def test_bash_create_additional_artifacts():
    contents = """
    ls
    echo "hi" > dexy--hello.txt
    """
    config = {"." : { "@script.sh|fn|shint" : {"shint": {"ext" : ".json", "meta" : True}, "contents" : contents }}}
    for doc in run_dexy(config):
        doc.run()
        artifact = doc.last_artifact
        assert artifact.inputs()['hello.txt'].output_text() == "hi\n"
Esempio n. 9
0
def test_ignore_errors_document():
    """
    Ensure we can ignore errors by setting 'ignore-errors' to true for each individual document.
    """
    trigger_ignore_exceptions_config = TRIGGER_EXCEPTIONS_CONFIG.copy()

    for k, v in trigger_ignore_exceptions_config['.'].iteritems():
        v['ignore-errors'] = True

    for doc in run_dexy(trigger_ignore_exceptions_config):
        doc.run()
Esempio n. 10
0
def test_sed_filter():
    config = {
            "@example.sed|sed" : {
                "contents" : "s/e/E/g",
                "allinputs" : True
                },
            "@input.txt" : { "contents" : "hello" }
        }
    for doc in run_dexy({"." : config}):
        doc.run()
        if doc.key().endswith("sed"):
            assert doc.output() == "hEllo"
Esempio n. 11
0
def test_markdown():
    for doc in run_dexy(CONFIG):
        doc.run()
        if doc.key() == "example1.md|markdown":
            assert doc.output() == "<p>[TOC]</p>"
        elif doc.key() == "example2.md|markdown":
            assert doc.output() == """<div class="toc"></div>"""
        elif doc.key() == "example3.md|markdown":
            assert doc.output() == """<div class="toc"><span class="toctitle">My Table of Contents</span></div>"""
        elif doc.key() == "example4.md|markdown":
            assert doc.output() == """<p><a class="wikilink" href="/wikime/">wikime</a></p>"""
        else:
            assert False, "Should not get here."
Esempio n. 12
0
def test_used_filter():
    config = {
            "@input.txt|used" : {
                "contents" : "hello",
                "inputs" : ["@example.sed"]
                },
            "@example.sed" : { "contents" : "s/e/E/g" },
        }

    for doc in run_dexy({"." : config}):
        doc.run()
        if doc.key().endswith("used"):
            assert doc.output() == "hEllo"
Esempio n. 13
0
def test_bash_create_additional_files():
    contents = """
    mkdir abc
    ls
    echo "hi" > abc/hello.txt
    """
    config = {"." : { "@script.sh|shint" : {"shint": {"meta" : True}, "contents" : contents }}}
    for doc in run_dexy(config):
        doc.run()
        artifact = doc.last_artifact

        kv_artifact = artifact.inputs().values()[0]
        kv_artifact.setup_kv_storage()
        assert kv_artifact['1:files:abc/hello.txt'] == "hi\n"
Esempio n. 14
0
def test_irb():
    assert_output("example.rb|irb", "1+1", ">> 1+1\n=> 2")

    config = {"." : { "@example.rb|irb" : {"irb": {"ext" : ".json", "meta" : True}, "contents" : "1+1"}}}
    for doc in run_dexy(config):
        doc.run()

        artifact = doc.last_artifact
        assert artifact.output() == ">> 1+1\n=> 2"

        kv_artifact = artifact.inputs().values()[0]
        kv_artifact.setup_kv_storage()
        assert kv_artifact['1:files:example.rb'] == "1+1"
        assert kv_artifact['1:html-output']
        assert kv_artifact['1:latex-output']
        assert kv_artifact['1:output'] == ">> 1+1\n=> 2"
Esempio n. 15
0
def test_bash_create_git_repo():
    contents = """
    mkdir abc
    ls
    echo "hi" > abc/hello.txt
    git init
    git add .
    """
    config = {"." : { "@script.sh|shint" : {"shint": {"ext" : ".json", "meta" : True}, "contents" : contents }}}
    for doc in run_dexy(config):
        doc.run()
        artifact = doc.last_artifact

        kv_artifact = artifact.inputs().values()[0]
        kv_artifact.setup_kv_storage()
        assert "[core]" in kv_artifact["1:files:.git/config"]
Esempio n. 16
0
def test_python_input_filter():
    script = """import sys
for line in sys.stdin:
    line = line.strip()
    print "You said '%s', that took '%d' characters!" % (line, len(line))"""
    config = {
            "@script.py|pyinput" : {
                "contents" : script,
                "inputs" : ["@input.txt"]
                },
            "@input.txt" : { "contents" : "hello" },
        }

    for doc in run_dexy({"." : config}):
        doc.run()
        if doc.key().endswith("input"):
            assert doc.output() == "You said 'hello', that took '5' characters!\n"
Esempio n. 17
0
def test_ruby_input_filter():
    script = """
    while line = gets
        puts "you typed: #{line}"
    end
    """
    config = {
            "@script.rb|rbinput" : {
                "contents" : script,
                "inputs" : ["@input.txt"]
                },
            "@input.txt" : { "contents" : "hello" },
        }

    for doc in run_dexy({"." : config}):
        doc.run()
        if doc.key().endswith("input"):
            assert doc.output() == "you typed: hello\n"
Esempio n. 18
0
def test_basic_filter():
    set_filter_list([BasicFilter, BasicBinaryFilter])
    for doc in run_dexy(CONFIG):
        doc.run()
        assert doc.output() == DATA
Esempio n. 19
0
def test_existing_content():
    for doc in run_dexy(CONTENT_CONFIG):
        artifact = doc.last_artifact
        assert artifact["abc"] == 123