def test_yamlargs_filterargs(): with wrap() as wrapper: doc = Doc("example.txt|yamlargs|filterargs", wrapper, [], contents = "%s\n---\r\nThis is the content." % YAML, ) wrapper.run_docs(doc) output = doc.output_data().as_text() assert "abc: xyz" in output assert "foo: 5" in output wrapper = Wrapper() doc = Doc("example.txt|yamlargs|filterargs", wrapper, [], contents = "%s\n---\r\nThis is the content." % YAML, ) wrapper.run_docs(doc) output = doc.output_data().as_text() assert "abc: xyz" in output assert "foo: 5" in output
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']) == """\
def test_ps2pdf_filter(): with wrap() as wrapper: node = Doc("hello.ps|ps2pdf", wrapper, [], contents = PS) wrapper.run_docs(node) assert node.output_data().is_cached() assert node.output_data().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') wrapper=Wrapper() node = Doc("example.pdf|pdf2img", wrapper) wrapper.run_docs(node) assert node.output_data().is_cached() assert node.output_data().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') wrapper = Wrapper() node = Doc("example.pdf|pdf2img", wrapper) wrapper.run_docs(node) assert node.output_data().is_cached() assert node.output_data().filesize() > 1000
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 str( node.output_data()['assign-vars']) == "> x <- 6\n> y <- 7\n> \n" assert str(node.output_data()['multiply']) == "> x * y\n[1] 42\n> \n"
def test_sweave_filter(): with open(sweave_file, 'r') as f: sweave_content = f.read() with wrap() as wrapper: node = Doc("example.Snw|sweave", wrapper, [], contents=sweave_content) wrapper.run_docs(node) assert node.output_data().is_cached() assert "Coefficients:" in str(node.output_data())
def test_key_value_example(): with wrap() as wrapper: doc = Doc("hello.txt|keyvalueexample", wrapper, [], contents="hello") wrapper.run_docs(doc) assert doc.output_data()["foo"] == "bar" assert str( doc.output_data()) == "KeyValue('hello.txt|keyvalueexample')"
def test_yamlargs(): with wrap() as wrapper: doc = Doc("example.txt|yamlargs", wrapper, [], contents="title: My Title\n---\r\nThis is the content.") wrapper.run_docs(doc) assert doc.output_data().title() == "My Title" assert doc.output_data().as_text() == "This is the content."
def test_rst_meta(): with wrap() as wrapper: node = Doc("example.rst|rstmeta", wrapper, [], contents = rst_meta ) wrapper.run_docs(node) print node.output_data()
def test_yamlargs(): with wrap() as wrapper: doc = Doc("example.txt|yamlargs", wrapper, [], contents = "title: My Title\n---\r\nThis is the content." ) wrapper.run_docs(doc) assert doc.output_data().title() == "My Title" assert doc.output_data().as_text() == "This is the content."
def test_custom_name_in_subdir(): with wrap() as wrapper: doc = Doc("data.txt", wrapper, [], output_name="subdir/data.abc", contents="12345.67") wrapper.run_docs(doc) wrapper.report() assert doc.output_data().output_name() == "subdir/data.abc" assert doc.output_data().parent_output_dir() == "subdir"
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"
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) print node.output_data() assert node.output_data().as_text() == "1 + 1 is 2"
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()
def test_key_value_example(): with wrap() as wrapper: doc = Doc( "hello.txt|keyvalueexample", wrapper, [], contents="hello" ) wrapper.run_docs(doc) assert doc.output_data()["foo"] == "bar" assert str(doc.output_data()) == "KeyValue('hello.txt|keyvalueexample')"
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'
def run_kramdown(ext): with open(markdown_file, 'r') as f: example_markdown = f.read() with wrap() as wrapper: node = Doc("markdown.md|kramdown", wrapper, [], kramdown = { 'ext' : ext }, contents = example_markdown ) wrapper.run_docs(node) assert node.output_data().is_cached() return node.output_data()
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()
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()
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")
def test_custom_name_in_subdir(): with wrap() as wrapper: doc = Doc( "data.txt", wrapper, [], output_name="subdir/data.abc", contents="12345.67" ) wrapper.run_docs(doc) wrapper.report() assert doc.output_data().output_name() == "subdir/data.abc" assert doc.output_data().parent_output_dir() == "subdir"
def test_casperjs_svg2pdf_filter(): # TODO find smaller file - make test go faster? with wrap() as wrapper: orig = os.path.join(TEST_DATA_DIR, 'butterfly.svg') shutil.copyfile(orig, 'butterfly.svg') from dexy.wrapper import Wrapper wrapper = Wrapper() node = Doc("butterfly.svg|svg2pdf", wrapper) wrapper.run_docs(node) assert node.output_data().is_cached() assert node.output_data().filesize() > 1000
def test_pydoc_filter_on_module_names(): with wrap() as wrapper: doc = Doc("modules.txt|pydoc", wrapper, [], contents="os math") wrapper.run_docs(doc) data = doc.output_data() assert len(data.keys()) > 100 assert data["math.e:value"].startswith("2.71828")
def test_pydoc_filter_on_module_names(): with wrap() as wrapper: doc = Doc("modules.txt|pydoc", wrapper, [], contents="os math") wrapper.run_docs(doc) data = doc.output_data() assert len(data.keys()) > 100 assert data['math.e:value'].startswith("2.71828")
def test_pyparse_filter_on_python_files(): with wrap() as wrapper: doc = Doc("source.py|pyparse", wrapper, [], contents=python_file_content) wrapper.run_docs(doc) data = doc.output_data() keys = list(data.keys()) assert 'bar:source' in keys assert 'foo:source' in keys assert data['foo:doc'] == "docstring for foo" assert data['foo:source'].startswith("def foo():\n") assert data['bar:doc'] == "docstring for bar" assert data['bar:source'].startswith("def bar():\n") assert data['decorated:source'].startswith( "@decorator\n@another\ndef decorated():\n") assert data['Foo:source'].startswith("class Foo(object):\n") assert data['Foo.decorated:source'].startswith( " @decorator\n @another\n def decorated(self):\n")
def test_jinja_pass_through(): with wrap() as wrapper: with open("_template.html", "w") as f: f.write("{{ content }}") wrapper.reports = 'ws' contents = u"{{ 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 unicode(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>"""
def test_jinja_pass_through(): with wrap() as wrapper: with open("_template.html", "w") as f: f.write("{{ content }}") wrapper.reports = 'ws' contents = u"{{ 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 unicode(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>"""
def test_casperjs_svg2pdf_filter(): raise SkipTest() # TODO fix this - if casper is missing should raise error before reach assertions # TODO find smaller file - make test go faster? with wrap() as wrapper: orig = os.path.join(TEST_DATA_DIR, 'butterfly.svg') shutil.copyfile(orig, 'butterfly.svg') from dexy.wrapper import Wrapper wrapper = Wrapper() node = Doc("butterfly.svg|svg2pdf", wrapper) wrapper.run_docs(node) assert node.output_data().is_cached() assert node.output_data().filesize() > 1000
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 """ node = Doc("subdir/example.html|splithtml", wrapper, [], contents=contents) wrapper.run_docs(node) assert node.children[0].key == "subdir/a-page.html" assert node.children[1].key == "subdir/another-page.html" od = str(node.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 od = str(node.children[0].output_data()) assert "<p>This is at the top.</p>" in od assert "some content on a page" in od assert "bottom" in od od = str(node.children[1].output_data()) assert "<p>This is at the top.</p>" in od assert "some content on another page" in od assert "bottom" in od
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
def test_jinja_invalid_attribute(): def make_sections_doc(wrapper): return Doc("sections.txt", wrapper, [], contents=[{}, { "name": "foo", "contents": "This is foo." }]) with wrap() as wrapper: node = Doc( "ok.txt|jinja", wrapper, [make_sections_doc(wrapper)], contents="""hello! foo contents are: {{ d['sections.txt'].foo }}""" ) wrapper.run_docs(node) assert str( node.output_data()) == """hello! foo contents are: This is foo.""" with wrap() as wrapper: node = Doc("broken.txt|jinja", wrapper, [make_sections_doc(wrapper)], contents="""There is no {{ d['sections.txt'].bar }}""") try: wrapper.run_docs(node) except UserFeedback as e: assert str( e) == "No value for bar available in sections or metadata."
def run_calibre(ext): with wrap() as wrapper: node = Doc("book.html|calibre", wrapper, [], calibre={'ext': ext}, contents=HTML) wrapper.run_docs(node) assert node.output_data().is_cached()
def test_jinja_filter(): with wrap() as wrapper: node = Doc("template.txt|jinja", wrapper, [], contents="1 + 1 is {{ 1+1 }}") wrapper.run_docs(node) assert node.output_data().as_text() == "1 + 1 is 2"
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")
def test_rst2odt(): with wrap() as wrapper: node = Doc("example.txt|rst2odt", wrapper, [], contents=RST) wrapper.run_docs(node) assert node.output_data().filesize() > 8000
def test_jinja_filter_tex_extension(): with wrap() as wrapper: node = Doc("template.tex|jinja", wrapper, [], contents="1 + 1 is << 1+1 >>") wrapper.run_docs(node) assert node.output_data().as_text() == "1 + 1 is 2"
def test_yamlargs_no_yaml(): with wrap() as wrapper: doc = Doc("example.txt|yamlargs", wrapper, [], contents="This is the content.") wrapper.run_docs(doc) assert doc.output_data().as_text() == "This is the content."
def test_jinja_filter_set_vars(): with wrap() as wrapper: node = Doc("template.txt|jinja", wrapper, [], contents="""{% set foo = 'bar' -%}\nfoo is {{ foo }}\n""") wrapper.run_docs(node) assert node.output_data().as_text() == "foo is bar"
def test_sed_filter_single_simple_input_file(): with wrap() as wrapper: node = Doc("example.sed|sed", wrapper, [Doc("input.txt", wrapper, [], contents="hello")], contents="s/e/E/g") wrapper.run_docs(node) assert str(node.output_data()) == "hEllo"
def test_word_wrap_filter(): with wrap() as wrapper: node = Doc("example.txt|wrap", wrapper, [], contents="this is a line of text", wrap={"width": 5}) wrapper.run_docs(node) assert str(node.output_data()) == "this\nis a\nline\nof\ntext"
def test_jinja_filter_using_inflection(): with wrap() as wrapper: node = Doc("template.txt|jinja", wrapper, [], contents="""{{ humanize("abc_def") }}""") wrapper.run_docs(node) assert node.output_data().as_text() == "Abc def"
def test_rust(): with wrap() as wrapper: doc = Doc("example.rs|rustc", wrapper, [], contents = RUST ) wrapper.run_docs(doc) assert str(doc.output_data()) == "hello?\n"
def test_jinja_filter_tex_extension(): with wrap() as wrapper: node = Doc("template.tex|jinja", wrapper, [], contents = "1 + 1 is << 1+1 >>") wrapper.run_docs(node) assert node.output_data().as_text() == "1 + 1 is 2"
def test_force_text(): with wrap() as wrapper: node = Doc("example.py|idio|t", wrapper, [], contents="print 'hello'\n") wrapper.run_docs(node) assert str(node.output_data()) == "print 'hello'\n"
def test_javac_filter(): # not using runfilter() because file has to be named 'hello.java' with wrap() as wrapper: doc = Doc("hello.java|javac", wrapper, [], contents=JAVA_SRC) wrapper.run_docs(doc) assert doc.output_data().is_cached()
def test_java_filter(): # not using runfilter() because file has to be named 'hello.java' with wrap() as wrapper: doc = Doc("hello.java|java", wrapper, [], contents=JAVA_SRC) wrapper.run_docs(doc) assert str(doc.output_data()) == "Java Hello World!\n"
def test_scala_repl(): with wrap() as wrapper: doc = Doc("HelloWorld.scala|scalai", wrapper, [], contents = SCALA ) wrapper.run_docs(doc) assert "defined module HelloWorld" in str(doc.output_data())
def test_yamlargs_no_yaml(): with wrap() as wrapper: doc = Doc("example.txt|yamlargs", wrapper, [], contents = "This is the content.") wrapper.run_docs(doc) assert doc.output_data().as_text() == "This is the content."
def test_rust_interactive(): raise SkipTest("Need to get rust interactive filter working.") with wrap() as wrapper: doc = Doc("example.rs|rusti", wrapper, [], contents = "1+1" ) wrapper.run_docs(doc) assert "rusti> 1+1\n2" in str(doc.output_data())
def test_jinja_filter_using_inflection(): with wrap() as wrapper: node = Doc("template.txt|jinja", wrapper, [], contents = """{{ humanize("abc_def") }}""" ) wrapper.run_docs(node) assert node.output_data().as_text() == "Abc def"
def test_jinja_filter_set_vars(): with wrap() as wrapper: node = Doc("template.txt|jinja", wrapper, [], contents = """{% set foo = 'bar' -%}\nfoo is {{ foo }}\n""" ) wrapper.run_docs(node) assert node.output_data().as_text() == "foo is bar"
def test_jinja_filter(): with wrap() as wrapper: node = Doc("template.txt|jinja", wrapper, [], contents = "1 + 1 is {{ 1+1 }}" ) wrapper.run_docs(node) assert node.output_data().as_text() == "1 + 1 is 2"
def uest_force_latex(): with wrap() as wrapper: doc = Doc("example.py|idio|l", wrapper, [], contents="print 'hello'\n") wrapper.run_docs(doc) assert "begin{Verbatim}" in str(doc.output_data())
def run_calibre(ext): with wrap() as wrapper: node = Doc("book.html|calibre", wrapper, [], calibre = { 'ext' : ext }, contents = HTML ) wrapper.run_docs(node) assert node.output_data().is_cached()
def test_pygments_line_numbering_latex_alt(): with wrap() as wrapper: doc = Doc( "hello.py|pyg|l", wrapper, [], contents=" ", pyg = { 'line-numbers' : True } ) wrapper.run_docs(doc) assert "firstnumber=1" in str(doc.output_data())
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'