def test_unroot_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.unroot = True

    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(resource("figtree.nexus")), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "10e9024301b3178cdaed0b57ba33f615"
Exemple #2
0
def test_screw_formats_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "nexus"

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "543d2fc90ca1f391312d6b8fe896c59c"
Exemple #3
0
def test_root_ui_mrca(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.root = [["firSA25a", "penSH31b"]]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "757489907bd5c82882d084ffcb22cfba"
Exemple #4
0
def test_screw_formats_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "nexus"

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "543d2fc90ca1f391312d6b8fe896c59c"
Exemple #5
0
def test_root_ui_midpoint(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.root = [[]]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) in ["8a7fdd9421e0752c9cd58a1e073186c7", "25ea14c2e89530a0fb48163c0ef2a102"]
Exemple #6
0
def test_root_ui_leaf(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.root = [["firSA25a"]]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "f32bdc34bfe127bb0453a80cf7b01302"
def test_rename_ids_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.rename_ids = ['Mle', 'Phylo']

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "6843a620b725a3a0e0940d4352f2036f"
Exemple #8
0
def test_rename_ids_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.rename_ids = ['Mle', 'Phylo']

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "6843a620b725a3a0e0940d4352f2036f"
Exemple #9
0
def test_num_tips_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.num_tips = True

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "f43920f4df66e76fbacae4af178eeebb"
Exemple #10
0
def test_unroot_ui(capsys, pb_odd_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.unroot = True

    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(pb_odd_resources["figtree"]), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "10e9024301b3178cdaed0b57ba33f615"
def test_root_ui_mrca(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.root = [["firSA25a", "penSH31b"]]

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "757489907bd5c82882d084ffcb22cfba"
def test_root_ui_leaf(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.root = [["firSA25a"]]

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "f32bdc34bfe127bb0453a80cf7b01302"
Exemple #13
0
def test_display_trees_ui(monkeypatch, pb_resources):
    if 'DISPLAY' in os.environ:
        test_in_args = deepcopy(in_args)
        test_in_args.display_trees = True
        show = mock.Mock(return_value=True)
        monkeypatch.setattr(ete3.TreeNode, "show", show)
        Pb.command_line_ui(test_in_args, pb_resources.get_one("o k"), skip_exit=True)
def test_screw_formats_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "nexus"

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "543d2fc90ca1f391312d6b8fe896c59c"
def test_screw_formats_inplace_ui(capsys):
    temp_file = MyFuncs.TempFile()
    with open(resource("compare_trees.newick"), "r") as ifile:
        temp_file.write(ifile.read())

    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "nexus"
    test_in_args.in_place = True
    test_in_args.trees[0] = temp_file.path

    tester = Pb.PhyloBuddy(temp_file.path)
    Pb.command_line_ui(test_in_args, tester, skip_exit=True)
    out, err = capsys.readouterr()
    assert "File over-written at:" in err
    check_file = os.path.isfile("%s.nex" % temp_file.path)
    assert check_file

    test_in_args.trees[0] = "%s.nex" % temp_file.path
    test_in_args.screw_formats = "newick"

    tester = Pb.PhyloBuddy("%s.nex" % temp_file.path)
    Pb.command_line_ui(test_in_args, tester, skip_exit=True)
    out, err = capsys.readouterr()
    assert "File over-written at:" in err
    check_file = os.path.isfile("%s.nwk" % temp_file.path)
    assert check_file
def test_print_trees_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.print_trees = True

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "fe340117cb8f573100c00fc897e6c8ce"
def test_root_ui_midpoint(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.root = [[]]

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "25ea14c2e89530a0fb48163c0ef2a102"
def test_num_tips_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.num_tips = True

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "f43920f4df66e76fbacae4af178eeebb"
Exemple #19
0
def test_screw_formats_inplace_ui(capsys, pb_odd_resources):
    temp_file = br.TempFile()
    with open(pb_odd_resources["compare"], "r") as ifile:
        temp_file.write(ifile.read())

    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "nexus"
    test_in_args.in_place = True
    test_in_args.trees[0] = temp_file.path

    tester = Pb.PhyloBuddy(temp_file.path)
    Pb.command_line_ui(test_in_args, tester, skip_exit=True)
    out, err = capsys.readouterr()
    assert "File overwritten at:" in err
    check_file = os.path.isfile("%s.nex" % temp_file.path)
    assert check_file

    test_in_args.trees[0] = "%s.nex" % temp_file.path
    test_in_args.screw_formats = "newick"

    tester = Pb.PhyloBuddy("%s.nex" % temp_file.path)
    Pb.command_line_ui(test_in_args, tester, skip_exit=True)
    out, err = capsys.readouterr()
    assert "File overwritten at:" in err
    check_file = os.path.isfile("%s.nwk" % temp_file.path)
    assert check_file
Exemple #20
0
def test_screw_formats_fail(capsys, pb_resources):
    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "foo"
    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m k"),
                       skip_exit=True)
    foo_out, foo_err = capsys.readouterr()
    assert foo_err == "Error: unknown format 'foo'\n"
def test_generate_tree_ui2():
    test_in_args = deepcopy(in_args)
    test_in_args.in_format, test_in_args.out_format = "nexus", "newick"
    test_in_args.trees = [resource("Mnemiopsis_cds.nex")]

    test_in_args.generate_tree = [["fasttree", "-s 12345"]]  # Command doesn't exist in fasttree
    with pytest.raises(SystemExit):
        Pb.command_line_ui(test_in_args, [])
Exemple #22
0
def test_print_trees_internal_ui(capsys, pb_resources):
    # Most of this function is covered repeatedly below, so just test the -t flag
    test_in_args = deepcopy(in_args)
    test_in_args.test = True
    test_in_args.unroot = True
    Pb.command_line_ui(test_in_args, pb_resources.get_one('m k'), skip_exit=True)
    out, err = capsys.readouterr()
    assert err == "*** Test passed ***\n"
def test_print_trees_internal_ui(capsys):
    # Most of this function is covered repeatedly below, so just test the -t flag
    test_in_args = deepcopy(in_args)
    test_in_args.test = True
    test_in_args.unroot = True
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert err == "*** Test passed ***\n"
def test_generate_tree_ui3():
    test_in_args = deepcopy(in_args)
    test_in_args.in_format, test_in_args.out_format = "nexus", "newick"
    test_in_args.trees = [resource("Mnemiopsis_cds.nex")]

    test_in_args.generate_tree = [["foo"]]
    with pytest.raises(SystemExit):
        Pb.command_line_ui(test_in_args, [])
Exemple #25
0
def test_in_place_ui(capsys, pb_resources):
    # Some of this function is covered below, so just test an edge
    test_in_args = deepcopy(in_args)
    test_in_args.in_place = True
    test_in_args.trees = [pb_resources.get_one("m k")]
    test_in_args.screw_formats = "nexus"
    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert "Warning: The -i flag was passed in, but the positional" in err
def test_in_place_ui(capsys):
    # Some of this function is covered below, so just test an edge
    test_in_args = deepcopy(in_args)
    test_in_args.in_place = True
    test_in_args.trees = [Pb.make_copy(pb_objects[0])]
    test_in_args.screw_formats = "nexus"
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert "Warning: The -i flag was passed in, but the positional" in err
def test_generate_tree_ui1(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.in_format, test_in_args.out_format = "nexus", "newick"
    test_in_args.trees = [resource("Mnemiopsis_cds.nex")]

    test_in_args.generate_tree = [["fasttree", "-seed 12345"]]
    Pb.command_line_ui(test_in_args, [], skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "d7f505182dd1a1744b45cc326096f70c"
Exemple #28
0
def test_display_trees_ui(monkeypatch, pb_resources):
    if 'DISPLAY' in os.environ:
        test_in_args = deepcopy(in_args)
        test_in_args.display_trees = True
        monkeypatch.setattr("builtins.input", lambda *_: "")
        monkeypatch.setattr(webbrowser, "open_new_tab", lambda *_: "")
        Pb.command_line_ui(test_in_args,
                           pb_resources.get_one("o k"),
                           skip_exit=True)
Exemple #29
0
def test_error(monkeypatch, capsys, pb_resources, pb_odd_resources):
    test_in_args = deepcopy(in_args)
    test_in_args.show_unique = [True]

    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("o k"),
                       skip_exit=True)
    out, err = capsys.readouterr()
    assert "PhyloBuddy object should have exactly 2 trees." in err
Exemple #30
0
def test_print_trees_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.print_trees = True

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    if os.name == "nt":
        assert hf.string2hash(out) == "05d286a56bf98457c17830bb9c1766d0"
    else:
        assert hf.string2hash(out) == "fe340117cb8f573100c00fc897e6c8ce"
Exemple #31
0
def test_error(monkeypatch, capsys, pb_resources, pb_odd_resources):
    test_in_args = deepcopy(in_args)
    test_in_args.show_unique = [True]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("o k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert "PhyloBuddy object should have exactly 2 trees." in err

    monkeypatch.setattr(Pb, "_convert_to_ete", mock_assertionerror)
    with pytest.raises(AssertionError):
        Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(pb_odd_resources["compare"]), skip_exit=True)
Exemple #32
0
def test_collapse_polytomies_ui(capsys, pb_odd_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.collapse_polytomies = [[20]]
    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(pb_odd_resources['support']), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "1b0979265205b17ca7f34abbd02f6e26"

    test_in_args.collapse_polytomies = [[0.1, 'length']]
    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(pb_odd_resources['support']), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "252572f7b9566c62df24d57065412240"
Exemple #33
0
def test_show_unique_ui(capsys, pb_resources, hf, pb_odd_resources):
    test_in_args = deepcopy(in_args)
    test_in_args.show_unique = True

    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(pb_odd_resources["compare"]), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "ea5b0d1fcd7f39cb556c0f5df96281cf"

    with pytest.raises(AssertionError) as err:
        Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), pass_through=True)
    assert "PhyloBuddy object should have exactly 2 trees." in str(err)
def test_split_polytomies_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.split_polytomies = True

    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(Pb.PhyloBuddy('(A,(B,C,D));')), skip_exit=True)
    out, err = capsys.readouterr()
    assert out in ['(A:1.0,(B:1.0,(C:1.0,D:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(B:1.0,(D:1.0,C:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(C:1.0,(B:1.0,D:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(C:1.0,(D:1.0,B:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(D:1.0,(B:1.0,C:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(D:1.0,(C:1.0,B:1.0):1e-06):1.0):1.0;\n']
Exemple #35
0
def test_split_polytomies_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.split_polytomies = True

    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(Pb.PhyloBuddy('(A,(B,C,D));')), skip_exit=True)
    out, err = capsys.readouterr()
    assert out in ['(A:1.0,(B:1.0,(C:1.0,D:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(B:1.0,(D:1.0,C:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(C:1.0,(B:1.0,D:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(C:1.0,(D:1.0,B:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(D:1.0,(B:1.0,C:1.0):1e-06):1.0):1.0;\n',
                   '(A:1.0,(D:1.0,(C:1.0,B:1.0):1e-06):1.0):1.0;\n']
def test_prune_taxa_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.prune_taxa = [["fir"]]

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "99635c6dbf708f94cf4dfdca87113c44"

    test_in_args.prune_taxa = [["fir", "ovi"]]

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[1]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "2a385fa95024323fea412fd2b3c3e91f"
Exemple #37
0
def test_prune_taxa_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.prune_taxa = [["fir"]]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "99635c6dbf708f94cf4dfdca87113c44"

    test_in_args.prune_taxa = [["fir", "ovi"]]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m n"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "2a385fa95024323fea412fd2b3c3e91f"
Exemple #38
0
def test_display_trees_ui_no_display(capsys, monkeypatch, pb_resources):
    test_in_args = deepcopy(in_args)
    test_in_args.display_trees = True
    show = mock.Mock(return_value=True)
    monkeypatch.setattr(ete3.TreeNode, "show", show)
    # noinspection PyUnresolvedReferences
    with mock.patch.dict('os.environ'):
        if 'DISPLAY' in os.environ:
            del os.environ['DISPLAY']
        Pb.command_line_ui(test_in_args, pb_resources.get_one("o k"), skip_exit=True)
        out, err = capsys.readouterr()

    assert "Error: Your system does not appear to be graphical" in err
def test_show_unique_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.show_unique = True

    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy(resource("compare_trees.newick")), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "ea5b0d1fcd7f39cb556c0f5df96281cf"

    with pytest.raises(SystemExit):
        Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"))

    out, err = capsys.readouterr()
    assert err == "AssertionError: PhyloBuddy object should have exactly 2 trees.\n"
Exemple #40
0
def test_generate_tree_ui1(capsys, pb_resources, alb_resources, monkeypatch):
    test_in_args = deepcopy(in_args)
    test_in_args.in_format, test_in_args.out_format = "nexus", "newick"
    test_in_args.trees = [alb_resources.get_one("o d n")]

    monkeypatch.setattr(Pb, "generate_tree",
                        lambda *_, **__: pb_resources.get_one("o n"))
    monkeypatch.setattr(shutil, "which", lambda *_: True)

    test_in_args.generate_tree = [None]
    Pb.command_line_ui(test_in_args, [], skip_exit=True)
    out, err = capsys.readouterr()
    assert out == str(pb_resources.get_one("o k"))

    monkeypatch.setattr(Pb, "generate_tree", mock_fileexistserror)
    with pytest.raises(FileExistsError):
        Pb.command_line_ui(test_in_args, [], pass_through=True)

    monkeypatch.setattr(Pb, "generate_tree", mock_filenotfounderror)
    with pytest.raises(FileNotFoundError):
        Pb.command_line_ui(test_in_args, [], pass_through=True)

    monkeypatch.setattr(shutil, "which", lambda _: False)
    with pytest.raises(AttributeError) as err:
        Pb.command_line_ui(test_in_args, [], pass_through=True)
    assert "Unable to identify any supported phylogenetic inference software on your system." in str(
        err)
def test_display_trees_ui(capsys, monkeypatch):
    test_in_args = deepcopy(in_args)
    test_in_args.display_trees = True
    show = mock.Mock(return_value=True)
    monkeypatch.setattr(ete3.TreeNode, "show", show)
    Pb.command_line_ui(test_in_args, pb_resources.get_one("o k"), skip_exit=True)

    # noinspection PyUnresolvedReferences
    with mock.patch.dict('os.environ'):
        del os.environ['DISPLAY']
        Pb.command_line_ui(test_in_args, pb_resources.get_one("o k"), skip_exit=True)
        out, err = capsys.readouterr()

    assert "Error: Your system is non-graphical, so display_trees can not work." in err
Exemple #42
0
def test_display_trees_ui_no_display(capsys, monkeypatch, pb_resources):
    test_in_args = deepcopy(in_args)
    test_in_args.display_trees = True
    monkeypatch.setattr("builtins.input", lambda *_: "")
    monkeypatch.setattr(webbrowser, "open_new_tab", lambda *_: "")
    monkeypatch.setattr(os, "name", "posix")
    # noinspection PyUnresolvedReferences
    with mock.patch.dict('os.environ'):
        if 'DISPLAY' in os.environ:
            del os.environ['DISPLAY']
        Pb.command_line_ui(test_in_args,
                           pb_resources.get_one("o k"),
                           skip_exit=True)
        out, err = capsys.readouterr()

    assert "Error: Your system does not appear to be graphical" in err
Exemple #43
0
def test_exit(monkeypatch, capsys, pb_resources):
    class MockUsage(object):
        @staticmethod
        def increment(*args):
            print(args)
            return True

        @staticmethod
        def save():
            return True

    monkeypatch.setattr(br, "Usage", MockUsage)
    test_in_args = deepcopy(in_args)
    test_in_args.list_ids = [True]

    with pytest.raises(SystemExit):
        Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"))
    out, err = capsys.readouterr()
    assert "('PhyloBuddy', '%s', 'list_ids', 2412)" % Pb.VERSION.short() in out
Exemple #44
0
def test_hash_ids_ui(capsys, monkeypatch, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.hash_ids = [[1, "nodes"]]

    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("o n"),
                       skip_exit=True)
    out, err = capsys.readouterr()

    assert hf.string2hash(out) != hf.buddy2hash(pb_resources.get_one("o n"))
    assert "Warning: The hash_length parameter was passed in with the value 1" in err

    test_in_args.hash_ids = [[-1, "nodes"]]

    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m n"),
                       skip_exit=True)
    out, err = capsys.readouterr()

    assert hf.string2hash(out) != hf.buddy2hash(pb_resources.get_one("m n"))
    assert "Warning: The hash_length parameter was passed in with the value -1" in err

    def hash_ids(*args, **kwargs):
        if args or kwargs:
            pass
        raise ValueError("Foo bar")

    test_in_args.hash_ids = [[1, "nodes"]]
    monkeypatch.setattr(Pb, "hash_ids", hash_ids)
    with pytest.raises(ValueError):
        Pb.command_line_ui(test_in_args,
                           pb_resources.get_one("o n"),
                           pass_through=True)
def test_hash_ids_ui(capsys, monkeypatch):
    test_in_args = deepcopy(in_args)
    test_in_args.hash_ids = [[1, "nodes"]]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("o n"), skip_exit=True)
    out, err = capsys.readouterr()

    assert string2hash(out) != phylo_to_hash(pb_resources.get_one("o n"))
    assert "Warning: The hash_length parameter was passed in with the value 1" in err

    test_in_args.hash_ids = [[-1, "nodes"]]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m n"), skip_exit=True)
    out, err = capsys.readouterr()

    assert string2hash(out) != phylo_to_hash(pb_resources.get_one("m n"))
    assert "Warning: The hash_length parameter was passed in with the value -1" in err

    def hash_ids(*args):
        if args:
            pass
        raise ValueError("Foo bar")

    test_in_args.hash_ids = [[1, "nodes"]]
    monkeypatch.setattr(Pb, "hash_ids", hash_ids)
    with pytest.raises(ValueError):
        Pb.command_line_ui(test_in_args, pb_resources.get_one("o n"))
    out, err = capsys.readouterr()
    assert not err
def test_consensus_tree_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.consensus_tree = [False]
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "f20cbd5aae5971cce8efbda15e4e0b7e"

    test_in_args.consensus_tree = [0.9]
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "447862ed1ed6e98f2fb535ecce70218b"

    test_in_args.consensus_tree = [1.5]
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "f20cbd5aae5971cce8efbda15e4e0b7e"
def test_distance_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.distance = [False]
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "7a9f9902ef30ca3d7ac97b63cfdd0b2e"

    test_in_args.distance = ["uwrf"]
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "6e520f6911aabdf91dfd075d1545bc1e"

    test_in_args.distance = ["ed"]
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "f0acdd9c751bce77fe14355cc77b69cc"
Exemple #48
0
def test_consensus_tree_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.consensus_tree = [False]
    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "acd3fb34cce867c37684244701f9f5bf"

    test_in_args.consensus_tree = [0.9]
    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "baf9b2def2c0fa2ff97d3a16d24b4738"

    test_in_args.consensus_tree = [1.5]
    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "acd3fb34cce867c37684244701f9f5bf"
    assert err == "Warning: The frequency value should be between 0 and 1. Defaulting to 0.5.\n\n"
Exemple #49
0
def test_list_ids_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.list_ids = [True]

    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "4f0857e0211ff0cd058d0cf7cbaf64d5"

    test_in_args.list_ids = [4]
    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "bf2fbfe1bd52e9b27ae21f5c06e7763a"

    test_in_args.list_ids = [4]
    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy("(, );"), skip_exit=True)
    out, err = capsys.readouterr()
    assert out == "#### tree_1 ####\nNone\n\n"
def test_list_ids_ui(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.list_ids = [True]

    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "4f0857e0211ff0cd058d0cf7cbaf64d5"

    test_in_args.list_ids = [4]
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    out, err = capsys.readouterr()
    assert string2hash(out) == "bf2fbfe1bd52e9b27ae21f5c06e7763a"

    test_in_args.list_ids = [4]
    Pb.command_line_ui(test_in_args, Pb.PhyloBuddy("(, );"), skip_exit=True)
    out, err = capsys.readouterr()
    assert out == "#### tree_1 ####\nNone\n\n"
Exemple #51
0
def test_ladderize_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.ladderize = [None]

    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m k"),
                       skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "63ee71da75031d09f953932a1f0195b5"

    test_in_args.ladderize = ['reverse']
    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m k"),
                       skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "0dfa9fbb23428d2992b982776777428c"

    test_in_args.ladderize = ['rev']
    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m k"),
                       skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "0dfa9fbb23428d2992b982776777428c"
def test_screw_formats_fail(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "foo"
    Pb.command_line_ui(test_in_args, pb_resources.get_one("m k"), skip_exit=True)
    foo_out, foo_err = capsys.readouterr()
    assert foo_err == "Error: unknown format 'foo'\n"
Exemple #53
0
def test_distance_ui(capsys, pb_resources, hf):
    test_in_args = deepcopy(in_args)
    test_in_args.distance = [False]  # Should default to wrf
    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m k"),
                       skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "66df36fa117e4c4660f04e2649c3fa6b"
    assert err == "Tree 1	Tree 2	Value\n"

    test_in_args.distance = ["wrf"]
    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m k"),
                       skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "66df36fa117e4c4660f04e2649c3fa6b"
    assert err == "Tree 1	Tree 2	Value\n"

    test_in_args.distance = ["uwrf"]
    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m k"),
                       skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "9dd162b4cc4fa28f402e6f31ef2fb349"
    assert err == "Tree 1	Tree 2	Value\n"

    test_in_args.distance = ["ed"]
    Pb.command_line_ui(test_in_args,
                       pb_resources.get_one("m k"),
                       skip_exit=True)
    out, err = capsys.readouterr()
    assert hf.string2hash(out) == "a49e54a6c14ab4dbbf73d3f7d1d6aa82"
    assert err == "Tree 1	Tree 2	Value\n"

    test_in_args.distance = ["foo"]
    with pytest.raises(AttributeError) as err:
        Pb.command_line_ui(test_in_args,
                           pb_resources.get_one("m k"),
                           pass_through=True)
    assert "foo is an invalid comparison method." in str(err)

    with pytest.raises(ValueError) as err:
        Pb.command_line_ui(test_in_args,
                           pb_resources.get_one("o k"),
                           pass_through=True)
    assert "Distance requires at least two trees." in str(err)
Exemple #54
0
def test_screw_formats_fail(capsys):
    test_in_args = deepcopy(in_args)
    test_in_args.screw_formats = "foo"
    Pb.command_line_ui(test_in_args, Pb.make_copy(pb_objects[0]), skip_exit=True)
    foo_out, foo_err = capsys.readouterr()
    assert foo_err == "Error: unknown format 'foo'\n"