def test_runner_register(): with tempdir(): doc = Doc("abc.txt") runner = Runner() runner.setup_dexy_dirs() runner.register(doc) assert doc in runner.registered
def test_caching(): with tempdir(): runner1 = Runner() with open("abc.txt", "w") as f: f.write("these are the contents") doc1 = Doc("abc.txt|dexy", runner=runner1) runner1.docs = [doc1] runner1.run() assert isinstance(doc1.artifacts[0], InitialArtifact) hashstring_0_1 = doc1.artifacts[0].hashstring assert isinstance(doc1.artifacts[1], FilterArtifact) hashstring_1_1 = doc1.artifacts[1].hashstring runner2 = Runner() doc2 = Doc("abc.txt|dexy", runner=runner2) runner2.docs = [doc2] runner2.run() assert isinstance(doc2.artifacts[0], InitialArtifact) hashstring_0_2 = doc2.artifacts[0].hashstring assert isinstance(doc2.artifacts[1], FilterArtifact) hashstring_1_2 = doc2.artifacts[1].hashstring assert hashstring_0_1 == hashstring_0_2 assert hashstring_1_1 == hashstring_1_2
def test_caching_virtual_file(): with tempdir(): runner1 = Runner() doc1 = Doc("abc.txt|dexy", contents="these are the contents", runner=runner1) runner1.docs = [doc1] runner1.run() assert isinstance(doc1.artifacts[0], InitialVirtualArtifact) hashstring_0_1 = doc1.artifacts[0].hashstring assert isinstance(doc1.artifacts[1], FilterArtifact) hashstring_1_1 = doc1.artifacts[1].hashstring runner2 = Runner() doc2 = Doc("abc.txt|dexy", contents="these are the contents", runner=runner2) runner2.docs = [doc2] runner2.run() assert isinstance(doc2.artifacts[0], InitialVirtualArtifact) hashstring_0_2 = doc2.artifacts[0].hashstring assert isinstance(doc2.artifacts[1], FilterArtifact) hashstring_1_2 = doc2.artifacts[1].hashstring assert hashstring_0_1 == hashstring_0_2 assert hashstring_1_1 == hashstring_1_2
def test_add_new_subtask(): with divert_stdout() as stdout: runner = Runner() t1 = AddNewSubtask("parent", runner=runner) runner.docs = [t1] runner.run() assert stdout.getvalue() == "pre 'new' run 'new' post 'new'"
def test_run_demo_single(): with divert_stdout() as stdout: runner = Runner() doc = SubclassTask("demo", runner=runner) runner.docs = [doc] runner.run() assert "pre 'demo' run 'demo' post 'demo'" == stdout.getvalue()
def test_run_demo_parent_child(): with divert_stdout() as stdout: runner = Runner() doc = SubclassTask( "parent", SubclassTask("child", runner=runner), runner=runner ) runner.docs = [doc] runner.run() assert "pre 'parent' pre 'child' run 'child' post 'child' run 'parent' post 'parent'" == stdout.getvalue()
def test_caching_virtual_file(): with tempdir(): runner1 = Runner() doc1 = Doc("abc.txt|dexy", contents = "these are the contents", runner=runner1) runner1.docs = [doc1] runner1.run() assert isinstance(doc1.artifacts[0], InitialVirtualArtifact) hashstring_0_1 = doc1.artifacts[0].hashstring assert isinstance(doc1.artifacts[1], FilterArtifact) hashstring_1_1 = doc1.artifacts[1].hashstring runner2 = Runner() doc2 = Doc( "abc.txt|dexy", contents = "these are the contents", runner=runner2) runner2.docs = [doc2] runner2.run() assert isinstance(doc2.artifacts[0], InitialVirtualArtifact) hashstring_0_2 = doc2.artifacts[0].hashstring assert isinstance(doc2.artifacts[1], FilterArtifact) hashstring_1_2 = doc2.artifacts[1].hashstring assert hashstring_0_1 == hashstring_0_2 assert hashstring_1_1 == hashstring_1_2
def test_dependencies_only_run_once(): with divert_stdout() as stdout: runner = Runner() t1 = SubclassTask("1", runner=runner) t2 = SubclassTask("2", t1, runner=runner) t3 = SubclassTask("3", t1, runner=runner) runner.docs = [t1, t2, t3] runner.run() assert stdout.getvalue() == "pre '1' run '1' post '1' pre '2' run '2' post '2' pre '3' run '3' post '3'" assert len(t1.completed_children) == 0 assert t1 in t2.completed_children.values() assert t1 in t3.completed_children.values()
def __enter__(self): self.tempdir = tempfile.mkdtemp() self.location = os.path.abspath(os.curdir) os.chdir(self.tempdir) runner = Runner() runner.setup_dexy_dirs() runner.setup_log() runner.setup_db() return runner
def __enter__(self): # Create a temporary working dir and move to it self.tempdir = tempfile.mkdtemp() self.location = os.path.abspath(os.curdir) os.chdir(self.tempdir) # Create a document. Skip testing documents with inactive filters. try: params = RunParams() doc_key = "example%s|%s" % (self.ext, self.filter_alias) doc_spec = [[doc_key, {"contents": self.doc_contents}]] runner = Runner(params, doc_spec) runner.run() except InactiveFilter: raise SkipTest return runner.docs[0]
def __enter__(self): # Create a temporary working dir and move to it self.tempdir = tempfile.mkdtemp() self.location = os.path.abspath(os.curdir) os.chdir(self.tempdir) # Create a document. Skip testing documents with inactive filters. try: params = RunParams() doc_key = "example%s|%s" % (self.ext, self.filter_alias) doc_spec = [[doc_key, {"contents" : self.doc_contents}]] runner = Runner(params, doc_spec) runner.run() except InactiveFilter: raise SkipTest return runner.docs[0]
def test_circular(): runner = Runner() d1 = Task("1",runner=runner) d2 = Task("2",runner=runner) d1.children.append(d2) d2.children.append(d1) try: for t in d1: t() assert False except CircularDependency: assert True
def test_circular_4_docs(): runner = Runner() d1 = Task("1", runner=runner) d2 = Task("2", runner=runner) d3 = Task("3", runner=runner) d4 = Task("4", runner=runner) d1.children.append(d2) d2.children.append(d3) d3.children.append(d4) d4.children.append(d1) for t in d1: t()
def test_parent_doc_hash(): with tempdir(): params = RunParams() args = [["hello.txt|newdoc", {"contents": "hello"}]] runner = Runner(params, args) runner.run() doc = runner.docs[-1] runner.setup_db() rows = runner.get_child_hashes_in_previous_batch( doc.final_artifact.hashstring) assert len(rows) == 3
def test_parent_doc_hash_2(): with tempdir(): params = RunParams() args = [["hello.txt|newdoc", {"contents": "hello"}]] runner = Runner(params, args) runner.run() for doc in runner.registered: if doc.__class__.__name__ == 'FilterArtifact': assert doc.source == 'generated' runner = Runner(params, args) runner.run() for doc in runner.registered: if doc.__class__.__name__ == 'FilterArtifact': assert doc.source == 'cached'
def test_runner_run(): with tempdir(): runner = Runner() runner.setup_dexy_dirs() d1 = Doc("abc.txt|outputabc", contents="these are the contents", runner=runner) d2 = Doc("hello.txt|outputabc", contents="these are more contents", runner=runner) assert d1.state == 'setup' assert d2.state == 'setup' runner.docs = [d1, d2] runner.run() assert d1.state == 'complete' assert d2.state == 'complete'
def test_parent_doc_hash(): with tempdir(): params = RunParams() args = [["hello.txt|newdoc", { "contents" : "hello" }]] runner = Runner(params, args) runner.run() doc = runner.docs[-1] runner.setup_db() rows = runner.get_child_hashes_in_previous_batch(doc.final_artifact.hashstring) assert len(rows) == 3
def test_parent_doc_hash_2(): with tempdir(): params = RunParams() args = [["hello.txt|newdoc", { "contents" : "hello" }]] runner = Runner(params, args) runner.run() for doc in runner.registered: if doc.__class__.__name__ == 'FilterArtifact': assert doc.source == 'generated' runner = Runner(params, args) runner.run() for doc in runner.registered: if doc.__class__.__name__ == 'FilterArtifact': assert doc.source == 'cached'
def run(*args, **kwargs): params = RunParams(**kwargs) runner = Runner(params, args) runner.run() runner.report()
def test_runner_setup(): with tempdir(): assert not os.path.exists('artifacts') runner = Runner() runner.setup_dexy_dirs() assert os.path.exists('artifacts')
def test_runner_init(): runner = Runner() assert isinstance(runner.params, RunParams) assert isinstance(runner.registered, list) assert runner.params.artifacts_dir == 'artifacts'