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_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_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_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_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_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()
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()
def test_parse_doc_configs_no_configs(): with tempdir(): with capture_stdout() as stdout: wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked() value = stdout.getvalue() assert "didn't find any document config files" in value
def test_parse_doc_configs_no_configs(): with tempdir(): with capture_stdout() as stdout: wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked() value = stdout.getvalue() assert "didn't find any document config files" in value
def test_walked(): with tempdir(): with open("dexy.yaml", "w") as f: f.write("foo.txt") with open("foo.txt", "w") as f: f.write("foo") wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper.to_valid() wrapper.to_walked() wrapper.validate_state('walked')
def test_walked(): with tempdir(): with open("dexy.yaml", "w") as f: f.write("foo.txt") with open("foo.txt", "w") as f: f.write("foo") wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper.to_valid() wrapper.to_walked() wrapper.validate_state('walked')
def test_parse_doc_configs_single_empty_config(): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() with open("dexy.yaml", "w") as f: f.write("foo.txt") with open("foo.txt", "w") as f: f.write("foo") wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked()
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)
def test_parse_doc_configs_single_empty_config(): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() with open("dexy.yaml", "w") as f: f.write("foo.txt") with open("foo.txt", "w") as f: f.write("foo") wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked()
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)
def test_init_wrapper_if_dexy_dirs_exist(): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() with open("hello.txt", "w") as f: f.write("hello") wrapper = Wrapper() wrapper.to_valid() assert wrapper.project_root wrapper.to_walked() assert 'hello.txt' in wrapper.filemap assert 'dexy.log' in os.listdir('.dexy') assert not '.dexy/dexy.log' in wrapper.filemap
def test_init_wrapper_if_dexy_dirs_exist(): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() with open("hello.txt", "w") as f: f.write("hello") wrapper = Wrapper() wrapper.to_valid() assert wrapper.project_root wrapper.to_walked() assert 'hello.txt' in wrapper.filemap assert 'dexy.log' in os.listdir('.dexy') assert not '.dexy/dexy.log' in wrapper.filemap
def test_ran(): with tempdir(): with open("dexy.yaml", "w") as f: f.write("foo.txt") with open("foo.txt", "w") as f: f.write("foo") wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper.run_from_new() for node in wrapper.roots: assert node.state == 'ran' wrapper.validate_state('ran') wrapper = Wrapper() wrapper.run_from_new() for node in wrapper.roots: assert node.state == 'consolidated' wrapper.validate_state('ran')
def test_batch_with_docs(): with tempdir(): wrapper = Wrapper(log_level='DEBUG', debug=True) wrapper.create_dexy_dirs() with open("hello.txt", "w") as f: f.write("hello") with open("dexy.yaml", "w") as f: f.write("hello.txt") wrapper = Wrapper() wrapper.run_from_new() batch = dexy.batch.Batch.load_most_recent(wrapper) assert batch for doc_key in batch.docs: assert batch.input_data(doc_key) assert batch.output_data(doc_key)
def test_ran(): with tempdir(): with open("dexy.yaml", "w") as f: f.write("foo.txt") with open("foo.txt", "w") as f: f.write("foo") wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper.run_from_new() for node in wrapper.roots: assert node.state == 'ran' wrapper.validate_state('ran') wrapper = Wrapper() wrapper.run_from_new() for node in wrapper.roots: assert node.state == 'consolidated' wrapper.validate_state('ran')
def test_batch_with_docs(): with tempdir(): wrapper = Wrapper(log_level='DEBUG', debug=True) wrapper.create_dexy_dirs() with open("hello.txt", "w") as f: f.write("hello") with open("dexy.yaml", "w") as f: f.write("hello.txt") wrapper = Wrapper() wrapper.run_from_new() batch = dexy.batch.Batch.load_most_recent(wrapper) assert batch for doc_key in batch.docs: assert batch.input_data(doc_key) assert batch.output_data(doc_key)
def test_nodexy_files(): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() with open("hello.txt", "w") as f: f.write("hello") os.makedirs("s1/s2/s3") nodexy_path = "s1/s2/.nodexy" with open(nodexy_path, 'w') as f: f.write("dexy stop here") with open("s1/s2/ignore.txt", "w") as f: f.write("dexy should ignore this") with open("s1/s2/s3/ignore.txt", "w") as f: f.write("dexy should also ignore this") # Only the hello.txt file is visible to dexy wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked() assert len(wrapper.filemap) == 1 assert 'hello.txt' in wrapper.filemap os.remove(nodexy_path) # Now we can see all 3 text files. wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked() assert len(wrapper.filemap) == 3 assert 'hello.txt' in wrapper.filemap assert 's1/s2/ignore.txt' in wrapper.filemap assert 's1/s2/s3/ignore.txt' in wrapper.filemap
def test_nodexy_files(): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() with open("hello.txt", "w") as f: f.write("hello") os.makedirs("s1/s2/s3") nodexy_path = "s1/s2/.nodexy" with open(nodexy_path, 'w') as f: f.write("dexy stop here") with open("s1/s2/ignore.txt", "w") as f: f.write("dexy should ignore this") with open("s1/s2/s3/ignore.txt", "w") as f: f.write("dexy should also ignore this") # Only the hello.txt file is visible to dexy wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked() assert len(wrapper.filemap) == 1 assert 'hello.txt' in wrapper.filemap os.remove(nodexy_path) # Now we can see all 3 text files. wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked() assert len(wrapper.filemap) == 3 assert 'hello.txt' in wrapper.filemap assert 's1/s2/ignore.txt' in wrapper.filemap assert 's1/s2/s3/ignore.txt' in wrapper.filemap
def test_example_project(): with tempdir(): 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() example_src = os.path.join(TEST_DATA_DIR, 'example') shutil.copytree(example_src, "example") os.chdir("example") wrapper = Wrapper(log_level=LOGLEVEL) wrapper.create_dexy_dirs() wrapper.run_from_new() wrapper.report() for node in wrapper.nodes.values(): assert_node_state(node, 'ran') run_from_cache_a_bunch_of_times() # touch this file so it triggers cache updating os.utime("multiply.py", None) unaffected_keys = ('latex', 'pygments.sty|pyg', 's1/loop.py|pycon', 's1/loop.py|py', 'main.rst|idio|h', 'main.rst|idio|l', 'main.rst|pyg|l', 'main.rst|pyg|h', 's1/loop.py|idio|h', 's1/loop.py|idio|l', 's1/loop.py|pyg|l', 's1/loop.py|pyg|h', 'dexy.yaml|idio|h', 'dexy.yaml|idio|l', 'dexy.yaml|pyg|l', 'dexy.yaml|pyg|h', ) affected_keys = ('code', 'docs', "*|pyg|l", "*|pyg|h", "*|idio|l", "*|idio|h", "main.rst|jinja|rst|latex", "*.rst|jinja|rst|latex", "*.py|pycon", "*.py|py", "main.rst|jinja|rstbody|easyhtml", "*.rst|jinja|rstbody|easyhtml", "foo.txt", "multiply.py|idio|h", "multiply.py|idio|l", "multiply.py|pycon", "multiply.py|py", "multiply.py|pyg|h", "multiply.py|pyg|l", ) wrapper = Wrapper(log_level=LOGLEVEL) wrapper.run_from_new() wrapper.report() for node in wrapper.nodes.values(): if node.key in unaffected_keys: assert_node_state(node, 'consolidated') else: assert node.key in affected_keys, node.key assert_node_state(node, 'ran') run_from_cache_a_bunch_of_times() import time time.sleep(0.5) with open("multiply.py", "r") as f: old_content = f.read() with open("multiply.py", "w") as f: f.write("raise") wrapper = Wrapper(log_level=LOGLEVEL) wrapper.run_from_new() assert wrapper.state == 'error' import time time.sleep(0.9) with open("multiply.py", "w") as f: f.write(old_content) wrapper = Wrapper(log_level=LOGLEVEL) wrapper.run_from_new() for node in wrapper.nodes.values(): if node.key in unaffected_keys: assert_node_state(node, 'consolidated') else: assert node.key in affected_keys, node.key assert_node_state(node, 'ran') wrapper.remove_dexy_dirs() wrapper.remove_reports_dirs(keep_empty_dir=True) wrapper.create_dexy_dirs() assert len(os.listdir(".dexy")) == 1 wrapper = Wrapper(log_level=LOGLEVEL, dry_run=True) wrapper.run_from_new() wrapper.report() assert len(os.listdir(".dexy")) == 6 with open(".dexy/reports/graph.txt", "r") as f: graph_text = f.read() assert "BundleNode(docs) (uncached)" in graph_text os.chdir("..")
def test_state_valid_after_to_valid(): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper.to_valid() wrapper.validate_state('valid')
def test_state_valid_after_to_valid(): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper.to_valid() wrapper.validate_state('valid')
def test_run_dexy(stdout): with tempdir(): wrapper = Wrapper() wrapper.create_dexy_dirs() dexy.commands.run()
def test_example_project(): with tempdir(): 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, debug=True) wrapper.run_from_new() for node in wrapper.nodes.values(): assert_node_state(node, 'consolidated', "In iter %s" % i) wrapper.report() example_src = os.path.join(TEST_DATA_DIR, 'example') shutil.copytree(example_src, "example") os.chdir("example") wrapper = Wrapper(log_level=LOGLEVEL) wrapper.create_dexy_dirs() wrapper.run_from_new() wrapper.report() for node in wrapper.nodes.values(): assert_node_state(node, 'ran', "in first run") run_from_cache_a_bunch_of_times() # touch this file so it triggers cache updating os.utime("multiply.py", None) unaffected_keys = ( 'latex', 'pygments.sty|pyg', 's1/loop.py|pycon', 's1/loop.py|py', 'main.rst|idio|h', 'main.rst|idio|l', 'main.rst|pyg|l', 'main.rst|pyg|h', 's1/loop.py|idio|h', 's1/loop.py|idio|l', 's1/loop.py|pyg|l', 's1/loop.py|pyg|h', 'dexy.yaml|idio|h', 'dexy.yaml|idio|l', 'dexy.yaml|pyg|l', 'dexy.yaml|pyg|h', ) affected_keys = ( 'code', 'docs', "*|pyg|l", "*|pyg|h", "*|idio|l", "*|idio|h", "main.rst|jinja|rst|latex", "*.rst|jinja|rst|latex", "*.py|pycon", "*.py|py", "main.rst|jinja|rstbody|easyhtml", "*.rst|jinja|rstbody|easyhtml", "foo.txt", "multiply.py|idio|h", "multiply.py|idio|l", "multiply.py|pycon", "multiply.py|py", "multiply.py|pyg|h", "multiply.py|pyg|l", ) wrapper = Wrapper(log_level=LOGLEVEL) wrapper.run_from_new() wrapper.report() for node in wrapper.nodes.values(): if node.key in unaffected_keys: assert_node_state(node, 'consolidated', "after touching multiply.py") else: assert node.key in affected_keys, node.key assert_node_state(node, 'ran', "after touchimg multiply.py") run_from_cache_a_bunch_of_times() import time time.sleep(0.5) with open("multiply.py", "r") as f: old_content = f.read() with open("multiply.py", "w") as f: f.write("raise") wrapper = Wrapper(log_level=LOGLEVEL) wrapper.run_from_new() assert wrapper.state == 'error' import time time.sleep(0.9) with open("multiply.py", "w") as f: f.write(old_content) wrapper = Wrapper(log_level=LOGLEVEL) wrapper.run_from_new() for node in wrapper.nodes.values(): if node.key in unaffected_keys: assert_node_state(node, 'consolidated', "after restoring old multiply.py content") else: assert node.key in affected_keys, node.key assert_node_state(node, 'ran', "after restoring old multiply.py contnet") wrapper.remove_dexy_dirs() wrapper.remove_reports_dirs(keep_empty_dir=True) wrapper.create_dexy_dirs() assert len(os.listdir(".dexy")) == 1 wrapper = Wrapper(log_level=LOGLEVEL, dry_run=True) wrapper.run_from_new() wrapper.report() assert len(os.listdir(".dexy")) == 6 with open(".dexy/reports/graph.txt", "r") as f: graph_text = f.read() assert "BundleNode(docs) (uncached)" in graph_text os.chdir("..")