Beispiel #1
0
def test_commands_filters_source():
    with divert_stdout() as stdout:
        filters_command(alias="tgzdir", source=True)
        with_color = stdout.getvalue()

    with divert_stdout() as stdout:
        filters_command(alias="tgzdir", source=True, nocolor=True)
        without_color = stdout.getvalue()

    assert len(with_color) > len(without_color)
Beispiel #2
0
def test_commands_filters_individual_filter():
    with divert_stdout() as stdout:
        filters_command(alias="tgzdir")
        assert "UnprocessedDirectoryArchiveFilter" in stdout.getvalue()
        assert "Aliases: tgzdir" in stdout.getvalue()
        assert "Create a tgz" in stdout.getvalue()
        assert "http://dexy.it/docs/filters/tgzdir" in stdout.getvalue()
Beispiel #3
0
def test_commands_filters():
    with divert_stdout() as stdout:
        filters_command()
        assert "looking up filter information..." in stdout.getvalue()
        assert "ZipArchiveFilter (zip)" in stdout.getvalue()
        assert "SplitLatexFilter (splitlatex) Splits a latex doc into multiple latex docs." in stdout.getvalue()
        assert not "http://dexy.it/docs/filters/tgzdir" in stdout.getvalue()
Beispiel #4
0
def test_setup_message_with_config():
    with tempdir():
        with divert_stdout() as stdout:
            with open(Constants.DEFAULT_CONFIG, "w") as f:
                f.write(SIMPLE_PY_CONFIG)
            setup_command()
            assert "You are now ready" in stdout.getvalue()
def test_wordpress(MockXmlrpclib):
    with wrap() as wrapper:
        with open("wordpress.json", "wb") as f:
            json.dump({}, f)

        with open(".dexyapis", "wb") as f:
            json.dump({
                'wordpress' : {
                    'url' : 'http://example.com',
                    'username' : 'foo',
                    'password' : 'bar'
                    }}, f)

        # Create new (unpublished) draft
        doc = mk_wp_doc(wrapper)
        wrapper.run_docs(doc)

        with open("wordpress.json", "rb") as f:
            result = json.load(f)

        assert result['postid'] == 42
        assert result['publish'] == False

        # Update existing draft
        doc = mk_wp_doc(wrapper)
        wrapper.run_docs(doc)
        assert doc.output().json_as_dict().keys() == ['permaLink']

        result['publish'] = True
        with open("wordpress.json", "wb") as f:
            json.dump(result, f)

        # Publish existing draft
        doc = mk_wp_doc(wrapper)
        wrapper.run_docs(doc)
        assert doc.output().as_text() == "http://example.com/blog/42"

        # Now, separately, test an image upload.
        orig = os.path.join(TEST_DATA_DIR, 'color-graph.pdf')
        shutil.copyfile(orig, 'example.pdf')
        doc = Doc("example.pdf|wp",
                wrapper=wrapper)

        with open(".dexyapis", "wb") as f:
            json.dump({
                'wordpress' : {
                    'url' : 'http://example.com',
                    'username' : 'foo',
                    'password' : 'bar'
                    }}, f)

        wrapper.run_docs(doc)
        assert doc.output().as_text() == "http://example.com/example.pdf"

        # test list categories
        with divert_stdout() as stdout:
            WordPressFilter.docmd_list_categories()
            assert stdout.getvalue() == "categoryName\nfoo\nbar\n"
Beispiel #6
0
def test_add_new_subtask():
    with divert_stdout() as stdout:
        with wrap() as wrapper:
            t1 = AddNewSubtask("parent", wrapper=wrapper)

            wrapper.docs = [t1]
            wrapper.run()

            assert stdout.getvalue() == "pre 'new' run 'new' post 'new'"
Beispiel #7
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()
Beispiel #8
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'"
Beispiel #9
0
def test_run_demo_single():
    with divert_stdout() as stdout:
        with wrap() as wrapper:
            doc = SubclassTask("demo", wrapper=wrapper)

            wrapper.docs = [doc]
            wrapper.run()

            assert "pre 'demo' run 'demo' post 'demo'" == stdout.getvalue()
Beispiel #10
0
def test_commands_dexy_without_setup():
    with tempdir():
        with divert_stdout() as stdout:
            try:
                dexy_command()
                assertFalse # should not get here
            except SystemExit as e:
                assert "Please run 'dexy setup'" in stdout.getvalue()
                assert not check_setup(logsdir=Constants.DEFAULT_LDIR, artifactsdir=Constants.DEFAULT_LDIR)
                assert e.code == 1
Beispiel #11
0
def test_commands_setup_cleanup():
    with tempdir():
        with divert_stdout() as stdout:
            setup_command()
            assert "You are almost ready" in stdout.getvalue()
            assert os.path.exists(Constants.DEFAULT_ADIR)
            assert os.path.exists(Constants.DEFAULT_LDIR)
            assert check_setup(logsdir=Constants.DEFAULT_LDIR, artifactsdir=Constants.DEFAULT_ADIR)

        cleanup_command()
        assert not os.path.exists(Constants.DEFAULT_ADIR)
        assert not os.path.exists(Constants.DEFAULT_LDIR)
        assert not check_setup(logsdir=Constants.DEFAULT_LDIR, artifactsdir=Constants.DEFAULT_LDIR)
Beispiel #12
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()
Beispiel #13
0
def test_run_demo_parent_child():
    with divert_stdout() as stdout:
        with wrap() as wrapper:
            doc = SubclassTask(
                        "parent",
                        SubclassTask("child", wrapper=wrapper),
                        wrapper=wrapper
                    )

            wrapper.docs = [doc]
            wrapper.run()

        assert "pre 'parent' pre 'child' run 'child' post 'child' run 'parent' post 'parent'" == stdout.getvalue()
Beispiel #14
0
def test_dependencies_only_run_once():
    with divert_stdout() as stdout:
        with wrap() as wrapper:
            t1 = SubclassTask("1", wrapper=wrapper)
            t2 = SubclassTask("2", t1, wrapper=wrapper)
            t3 = SubclassTask("3", t1, wrapper=wrapper)

            wrapper.docs = [t1, t2, t3]
            wrapper.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()
Beispiel #15
0
def test_commands_history():
    with tempdir():
        with divert_stdout() as stdout:
            with open(".dexy", "w") as f:
                f.write(SIMPLE_PY_CONFIG)

            setup_command()
            dexy_command()
            dexy_command()

            history_command(filename="simple.py")
            text = stdout.getvalue()
            assert "Dexy found these versions of simple.py" in text
            assert "logs/batch-source-00001/simple.py" in text
            assert "logs/batch-source-00002/simple.py" in text
Beispiel #16
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()
Beispiel #17
0
def test_completed_children():
    with temprun() as runner:
        with divert_stdout() as stdout:
            grandchild_task = SubclassTask("grandchild", runner=runner)
            child_task = SubclassTask("child", grandchild_task, runner=runner)
            parent_task = SubclassTask("parent", child_task, runner=runner)

            runner.docs = [parent_task]
            runner.run()

            assert stdout.getvalue() == "pre 'parent' pre 'child' pre 'grandchild' run 'grandchild' post 'grandchild' run 'child' post 'child' run 'parent' post 'parent'"

    assert "SubclassTask:grandchild" in parent_task.completed_children.keys()
    assert "SubclassTask:child" in parent_task.completed_children.keys()

    assert "SubclassTask:grandchild" in child_task.completed_children.keys()

    assert len(grandchild_task.completed_children) == 0
Beispiel #18
0
def test_completed_children():
    with wrap() as wrapper:
        with divert_stdout() as stdout:
            grandchild_task = SubclassTask("grandchild", wrapper=wrapper)
            child_task = SubclassTask("child", grandchild_task, wrapper=wrapper)
            parent_task = SubclassTask("parent", child_task, wrapper=wrapper)

            wrapper.docs = [parent_task]
            wrapper.run()

            assert stdout.getvalue() == "pre 'parent' pre 'child' pre 'grandchild' run 'grandchild' post 'grandchild' run 'child' post 'child' run 'parent' post 'parent'"

    assert "SubclassTask:grandchild" in parent_task.completed_children.keys()
    assert "SubclassTask:child" in parent_task.completed_children.keys()

    assert "SubclassTask:grandchild" in child_task.completed_children.keys()

    assert len(grandchild_task.completed_children) == 0
Beispiel #19
0
def test_circular_dependencies():
    with tempdir():
        fn = modargs.function_for(dexy.commands, "dexy")
        args = modargs.determine_kwargs(fn)
        args['globals'] = []
        os.mkdir(args['logsdir'])
        args['danger'] = True
        c = Controller(args)
        c.config = CIRCULAR_CONFIG
        with divert_stdout() as stdout:
            try:
                c.process_config()
                assert False
            except CycleError:
                assert True
            stdout_text = stdout.getvalue()
        assert "abc depends on ghi" in stdout_text
        assert "def depends on abc" in stdout_text
        assert "ghi depends on def" in stdout_text
Beispiel #20
0
def test_help_command():
    with divert_stdout() as stdout:
        help_command()
        assert stdout.getvalue() == help_text()
Beispiel #21
0
def test_commands_reporters():
    with divert_stdout() as stdout:
        reporters_command()
        assert "Output" in stdout.getvalue()
Beispiel #22
0
def test_run_incorrectly():
    with divert_stdout() as stdout:
        with temprun() as runner:
            for demotaskinstance in (SubclassTask("demo", runner=runner),):
                demotaskinstance()
        assert "run 'demo'" == stdout.getvalue()
Beispiel #23
0
def test_commands_filters():
    with divert_stdout() as stdout:
        filters_command()
        assert "pyg : PygmentsFilter" in stdout.getvalue()
Beispiel #24
0
def test_commands_filters():
    with divert_stdout() as stdout:
        filters_command()
        assert "cp : CopyFilter" in stdout.getvalue()
Beispiel #25
0
def test_setup_message_without_config():
    with tempdir():
        with divert_stdout() as stdout:
            setup_command()
            assert "You are almost ready" in stdout.getvalue()
Beispiel #26
0
def test_help_command_with_on():
    with divert_stdout() as stdout:
        help_command("setup")
        assert stdout.getvalue() == help_text("setup")
Beispiel #27
0
def test_run_incorrectly():
    with divert_stdout() as stdout:
        with wrap() as wrapper:
            for demotaskinstance in (SubclassTask("demo", wrapper=wrapper),):
                demotaskinstance()
        assert "run 'demo'" == stdout.getvalue()