def test_zip_archive_filter(): with tempdir(): with open("hello.py", "w") as f: f.write("print 'hello'") with open("hello.rb", "w") as f: f.write("puts 'hello'") wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper = Wrapper() doc = Doc("archive.zip|zip", wrapper, [ Doc("hello.py", wrapper), Doc("hello.rb", wrapper), Doc("hello.py|pyg", wrapper), Doc("hello.rb|pyg", wrapper) ], contents=" ") wrapper.run_docs(doc) wrapper.report() path_exists = os.path.exists("output/archive.zip") assert path_exists z = zipfile.ZipFile("output/archive.zip", "r") names = z.namelist() assert "archive/hello.py" in names assert "archive/hello.rb" in names assert "archive/hello.py-pyg.html" in names assert "archive/hello.rb-pyg.html" in names z.close()
def test_unprocessed_directory_archive_filter(): with wrap() as wrapper: with open("abc.txt", "w") as f: f.write('this is abc') with open("def.txt", "w") as f: f.write('this is def') wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper = Wrapper() doc = Doc("archive.tgz|tgzdir", wrapper, [], contents="ignore", tgzdir={'dir': '.'}) wrapper.run_docs(doc) wrapper.report() assert os.path.exists("output/archive.tgz") tar = tarfile.open("output/archive.tgz", mode="r:gz") names = tar.getnames() assert ("./abc.txt" in names) or ("abc.txt" in names) assert ("./def.txt" in names) or ("def.txt" in names) tar.close()
def test_archive_filter_with_short_names(): with wrap() as wrapper: with open("hello.py", "w") as f: f.write("print 'hello'") with open("hello.rb", "w") as f: f.write("puts 'hello'") wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper = Wrapper() doc = Doc("archive.tgz|archive", wrapper, [ Doc("hello.py", wrapper), Doc("hello.rb", wrapper), Doc("hello.py|pyg", wrapper), Doc("hello.rb|pyg", wrapper) ], contents=" ", archive={'use-short-names': True}) wrapper.run_docs(doc) wrapper.report() assert os.path.exists("output/archive.tgz") tar = tarfile.open("output/archive.tgz", mode="r:gz") names = tar.getnames() assert "archive/hello.py" in names assert "archive/hello.rb" in names assert "archive/hello.py.html" in names assert "archive/hello.rb.html" in names tar.close()
def test_pattern_node(): with wrap() as wrapper: with open("foo.txt", "w") as f: f.write("foo!") with open("bar.txt", "w") as f: f.write("bar!") wrapper = Wrapper(log_level='DEBUG') wrapper.to_valid() wrapper.nodes = {} wrapper.roots = [] wrapper.batch = dexy.batch.Batch(wrapper) wrapper.filemap = wrapper.map_files() node = PatternNode("*.txt", wrapper, [], foo="bar") assert node.args['foo'] == 'bar' wrapper.run_docs(node) assert len(node.children) == 2 for child in node.children: assert child.__class__.__name__ == "Doc" assert child.args['foo'] == 'bar' assert child.key_with_class() in ["doc:foo.txt", "doc:bar.txt"] assert child.filters == []
def test_yamlargs_with_caching(): with wrap() as wrapper: doc = Doc("example.txt|yamlargs", wrapper, [], contents = "title: My Title\n---\r\nThis is the content." ) wrapper.run_docs(doc) task = wrapper.nodes["doc:example.txt|yamlargs"] assert task.output_data().title() == "My Title" assert task.state == 'ran' wrapper = Wrapper() doc = Doc("example.txt|yamlargs", wrapper, [], contents = "title: My Title\n---\r\nThis is the content." ) wrapper.run_docs(doc) task = wrapper.nodes["doc:example.txt|yamlargs"] assert task.output_data().title() == "My Title" assert task.state == 'consolidated' wrapper = Wrapper() doc = Doc("example.txt|yamlargs", wrapper, [], contents = "title: My Title\n---\r\nThis is the content." ) wrapper.run_docs(doc) task = wrapper.nodes["doc:example.txt|yamlargs"] assert task.output_data().title() == "My Title" assert task.state == 'consolidated'
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_archive_filter(): with wrap() as wrapper: with open("hello.py", "w") as f: f.write("print 'hello'") with open("hello.rb", "w") as f: f.write("puts 'hello'") wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper = Wrapper() doc = Doc("archive.tgz|archive", wrapper, [ Doc("hello.py", wrapper), Doc("hello.rb", wrapper), Doc("hello.py|pyg", wrapper), Doc("hello.rb|pyg", wrapper) ], contents=" ") wrapper.run_docs(doc) wrapper.report() assert os.path.exists("output/archive.tgz") tar = tarfile.open("output/archive.tgz", mode="r:gz") names = tar.getnames() assert "archive/hello.py" in names assert "archive/hello.rb" in names assert "archive/hello.py-pyg.html" in names assert "archive/hello.rb-pyg.html" in names tar.close()
def test_unprocessed_directory_archive_filter(): with wrap() as wrapper: with open("abc.txt", "w") as f: f.write('this is abc') with open("def.txt", "w") as f: f.write('this is def') wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper = Wrapper() doc = Doc("archive.tgz|tgzdir", wrapper, [], contents="ignore", tgzdir={'dir' : '.'} ) wrapper.run_docs(doc) wrapper.report() assert os.path.exists("output/archive.tgz") tar = tarfile.open("output/archive.tgz", mode="r:gz") names = tar.getnames() assert ("./abc.txt" in names) or ("abc.txt" in names) assert ("./def.txt" in names) or ("def.txt" in names) tar.close()
def test_pdfcrop_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|pdfcrop|pdfinfo", wrapper) wrapper.run_docs(node) assert node.output_data().is_cached()
def test_pdfcrop_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|pdfcrop|pdfinfo", wrapper) wrapper.run_docs(node) assert node.output_data().is_cached()
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_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_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 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'