本文整理汇总了Python中dexy.wrapper.Wrapper类的典型用法代码示例。如果您正苦于以下问题:Python Wrapper类的具体用法?Python Wrapper怎么用?Python Wrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Wrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __enter__
def __enter__(self):
self.tempdir = tempfile.mkdtemp()
self.location = os.path.abspath(os.curdir)
os.chdir(self.tempdir)
wrapper = Wrapper()
wrapper.setup_run(setup_docs=False)
return wrapper
示例2: test_remove_trash_with_trash
def test_remove_trash_with_trash():
with tempdir():
wrapper = Wrapper()
os.mkdir(".trash")
assert os.path.exists(".trash")
wrapper.empty_trash()
assert not os.path.exists(".trash")
示例3: test_yamlargs_filterargs
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
示例4: test_pattern_node
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 == []
示例5: test_wrapper_register
def test_wrapper_register():
with tempdir():
doc = Doc("abc.txt")
wrapper = Wrapper()
wrapper.setup_run()
wrapper.register(doc)
assert doc in wrapper.registered
示例6: test_assert_dexy_dirs
def test_assert_dexy_dirs():
with tempdir():
wrapper = Wrapper()
try:
wrapper.assert_dexy_dirs_exist()
assert False
except UserFeedback:
assert True
示例7: test_error_if_to_valid_called_without_dirs_setup
def test_error_if_to_valid_called_without_dirs_setup():
with tempdir():
wrapper = Wrapper()
try:
wrapper.to_valid()
assert False, "should not get here"
except InternalDexyProblem:
assert True
示例8: test_deprecated_dot_dexy_file
def test_deprecated_dot_dexy_file():
with tempdir():
with open(".dexy", 'w') as f:
f.write("{}")
wrapper = Wrapper()
try:
wrapper.assert_dexy_dirs_exist()
except UserFeedback as e:
assert "this format is no longer supported" in str(e)
示例9: test_pdfcrop_filter
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()
示例10: test_script_node_caching__slow
def test_script_node_caching__slow():
with wrap():
with open("start.sh", "w") as f:
f.write("pwd")
with open("middle.sh", "w") as f:
f.write("echo `time`")
with open("end.sh", "w") as f:
f.write("echo 'done'")
with open("dexy.yaml", "w") as f:
f.write(SCRIPT_YAML)
wrapper1 = Wrapper()
wrapper1.run_from_new()
for node in wrapper1.nodes.values():
assert node.state == 'ran'
wrapper2 = Wrapper()
wrapper2.run_from_new()
for node in wrapper2.nodes.values():
assert node.state == 'consolidated'
time.sleep(1.1)
with open("middle.sh", "w") as f:
f.write("echo 'new'")
wrapper3 = Wrapper()
wrapper3.run_from_new()
for node in wrapper1.nodes.values():
assert node.state == 'ran'
示例11: test_subdir_config_with_bundle
def test_subdir_config_with_bundle():
with wrap():
with open("dexy.yaml", "w") as f:
f.write("""
foo:
- .txt
""")
os.makedirs("abc/def")
with open("abc/def/dexy.yaml", "w") as f:
f.write("""
bar:
- .py
""")
with open("abc/def/hello.py", "w") as f:
f.write("print 'hello'")
wrapper = Wrapper()
wrapper.run_from_new()
assert "doc:abc/def/hello.py" in wrapper.nodes
wrapper = Wrapper(recurse=False)
wrapper.run_from_new()
assert not "doc:abc/def/hello.py" in wrapper.nodes
wrapper = Wrapper(recurse=False, configs="abc/def/dexy.yaml")
wrapper.run_from_new()
assert "doc:abc/def/hello.py" in wrapper.nodes
示例12: test_create_remove_dexy_dirs
def test_create_remove_dexy_dirs():
with tempdir():
wrapper = Wrapper()
wrapper.create_dexy_dirs()
wrapper.to_valid()
assert wrapper.dexy_dirs_exist()
wrapper.remove_dexy_dirs()
assert not wrapper.dexy_dirs_exist()
示例13: run_from_cache_a_bunch_of_times
def run_from_cache_a_bunch_of_times():
n = random.randint(2, 10)
print "running %s times:" % n
for i in range(n):
print '', i+1
wrapper = Wrapper(log_level=LOGLEVEL)
wrapper.run_from_new()
for node in wrapper.nodes.values():
assert_node_state(node, 'consolidated', "In iter %s" % i)
wrapper.report()
示例14: test_move_cache_dir
def test_move_cache_dir():
with capture_stdout() as stdout:
with tempdir():
os.mkdir(".cache")
with open(".cache/.dexy-generated", 'w') as f:
f.write("")
wrapper = Wrapper()
wrapper.assert_dexy_dirs_exist()
assert "Moving directory '.cache'" in stdout.getvalue()
assert not os.path.exists(".cache")
assert os.path.exists(".dexy")
示例15: test_batch
def test_batch():
with tempdir():
wrapper = Wrapper()
wrapper.create_dexy_dirs()
wrapper = Wrapper()
batch = dexy.batch.Batch(wrapper)
os.makedirs(batch.batch_dir())
batch.save_to_file()
assert batch.filename() in os.listdir(".dexy/batches")
wrapper = Wrapper()
batch = dexy.batch.Batch.load_most_recent(wrapper)