Пример #1
0
def test_runner_register():
    with tempdir():
        doc = Doc("abc.txt")
        runner = Runner()
        runner.setup_dexy_dirs()
        runner.register(doc)
        assert doc in runner.registered
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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'"
Пример #5
0
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()
Пример #6
0
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()
Пример #7
0
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
Пример #8
0
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
Пример #9
0
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()
Пример #10
0
 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
Пример #11
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]
Пример #12
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]
Пример #13
0
 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
Пример #14
0
def test_runner_register():
    with tempdir():
        doc = Doc("abc.txt")
        runner = Runner()
        runner.setup_dexy_dirs()
        runner.register(doc)
        assert doc in runner.registered
Пример #15
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
Пример #16
0
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()
Пример #17
0
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
Пример #18
0
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'
Пример #19
0
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'
Пример #20
0
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
Пример #21
0
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'
Пример #22
0
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'
Пример #23
0
def run(*args, **kwargs):
    params = RunParams(**kwargs)

    runner = Runner(params, args)
    runner.run()
    runner.report()
Пример #24
0
def run(*args, **kwargs):
    params = RunParams(**kwargs)

    runner = Runner(params, args)
    runner.run()
    runner.report()
Пример #25
0
def test_runner_setup():
    with tempdir():
        assert not os.path.exists('artifacts')
        runner = Runner()
        runner.setup_dexy_dirs()
        assert os.path.exists('artifacts')
Пример #26
0
def test_runner_setup():
    with tempdir():
        assert not os.path.exists('artifacts')
        runner = Runner()
        runner.setup_dexy_dirs()
        assert os.path.exists('artifacts')
Пример #27
0
def test_runner_init():
    runner = Runner()
    assert isinstance(runner.params, RunParams)
    assert isinstance(runner.registered, list)
    assert runner.params.artifacts_dir == 'artifacts'