Example #1
0
def test_hash_ids_edges(monkeypatch, pb_resources, hf, pb_odd_resources):
    class MockRandom(object):
        def __init__(self):
            self.values = [
                "YCva8wcKxN", "r5iHz5XItJ", "b0dfUBWelI", "Tv0XxZziIQ",
                "hkwU50UQfq", "Jbn4JWgxXy", "OeGgev9Mdu", "pQRpDbjomQ",
                "z9JvFAa1vZ", "vHwNvExi6A", "i6tluyP88x", "mXvIO8GYAg",
                "clDGuGrku8", "atmvoy1uN6", "0R59tE6LgP", "eOUHJPbVaf",
                "2U0FarU2Lv", "4tITUmacIV", "UND58iKTiH", "aqQWMJnjeu",
                "rOFRXh4ftJ", "HeAcnkJ8LV", "bdWtyB4OP4", "L0aFqF3oMc",
                "4HN9dP8uqL", "TtdeGIxxY6", "s4S1RfO9sO", "mIScdjmMzq",
                "ohGB7fpJGq", "CtLTzCg6RB", "QufRP2p8jN", "NA98oE9g9u",
                "6IbtWWrdDr", "ZqnxsFXwpT", "hZd46Bc15s", "iL936ARfV9",
                "iOcjJIWv7Y", "yVkDeDhFpK", "d2amahGHzt", "H9VzjZZdbW",
                "kxFL0xMfFx", "glhRhmReup", "kxFL0xMfFx"
            ]
            self.current_value = self.values.pop()

        def choice(self, *args):
            if not self.current_value:
                self.current_value = self.values.pop()
            next_char = self.current_value[0]
            self.current_value = self.current_value[1:]
            return next_char

    with pytest.raises(TypeError) as e:
        Pb.hash_ids(Pb.PhyloBuddy, hash_length="foo")
    assert "Hash length argument must be an integer, not <class 'str'>" in str(
        e)

    with pytest.raises(ValueError) as e:
        Pb.hash_ids(Pb.PhyloBuddy, hash_length=0)
    assert "Hash length must be greater than 0" in str(e)

    with pytest.raises(ValueError) as e:
        Pb.hash_ids(pb_resources.get_one("m n"), hash_length=1)
    assert "Insufficient number of hashes available to cover all sequences." in str(
        e)

    tester = Pb.PhyloBuddy(pb_odd_resources['node_lables'])
    test_hash = hf.buddy2hash(tester)
    tester = Pb.hash_ids(tester, hash_length=5, nodes=True)
    assert hf.buddy2hash(tester) != test_hash

    monkeypatch.setattr(Pb.random, "Random", MockRandom)
    tester = Pb.hash_ids(pb_resources.get_one("o n"))
    assert hf.buddy2hash(tester) == "48b1b2b0e1f7012ea1a964269300ac6b"
Example #2
0
def test_hash_ids_edges():
    with pytest.raises(TypeError) as e:
        Pb.hash_ids(Pb.PhyloBuddy, hash_length="foo")
    assert "Hash length argument must be an integer, not <class 'str'>" in str(e)

    with pytest.raises(ValueError) as e:
        Pb.hash_ids(Pb.PhyloBuddy, hash_length=0)
    assert "Hash length must be greater than 0" in str(e)

    with pytest.raises(ValueError) as e:
        Pb.hash_ids(pb_resources.get_one("m n"), hash_length=1)
    assert "Insufficient number of hashes available to cover all sequences." in str(e)

    tester = Pb.PhyloBuddy(resource("tree_with_node_lables.nwk"))
    test_hash = phylo_to_hash(tester)
    tester = Pb.hash_ids(tester, hash_length=5, nodes=True)
    assert phylo_to_hash(tester) != test_hash
Example #3
0
def test_hash_ids(phylobuddy):
    orig_hash = phylo_to_hash(phylobuddy)
    Pb.hash_ids(phylobuddy)
    assert phylo_to_hash(phylobuddy) != orig_hash
Example #4
0
def test_hash_ids(pb_resources, hf):
    for phylobuddy in pb_resources.get_list("m o k n l"):
        orig_hash = hf.buddy2hash(phylobuddy)
        Pb.hash_ids(phylobuddy)
        assert hf.buddy2hash(phylobuddy) != orig_hash