<commit_before>"""Tests that are common to graphs"""
from atlasseq import ProbabilisticMultiColourDeBruijnGraph
import random
from atlasseq.utils import make_hash
from atlasseq.utils import reverse_comp
from hypothesis import given
from hypothesis import example
import hypothesis.strategies as st
from atlasseq.bytearray import ByteArray


POSSIBLE_STORAGES = [{'dict': None},
                     {"redis": {"conn": [('localhost', 6379, 2)]}},
                     {'berkeleydb': {'filename': './db'}}]
st_storage = st.sampled_from(POSSIBLE_STORAGES)
st_sample_colour = st.integers(min_value=0, max_value=10)
st_sample_name = st.text(min_size=1)

BINARY_KMERS_OR_NOT = [True, False]
st_binary_kmers = st.sampled_from(BINARY_KMERS_OR_NOT)
KMER = st.text(min_size=31, max_size=31, alphabet=['A', 'T', 'C', 'G'])
ST_GRAPH = st.sampled_from([ProbabilisticMultiColourDeBruijnGraph])


@given(Graph=ST_GRAPH, binary_kmers=st_binary_kmers)
def test_init(Graph, binary_kmers):
    mc = Graph(binary_kmers=binary_kmers)
    assert mc.binary_kmers == binary_kmers
    assert mc.num_hashes > 0


@given(Graph=ST_GRAPH, store=st_storage, sample=st_sample_name)
def test_add_sample_metadata(Graph, store, sample):
    print("new test", Graph, store, sample)
    mc = Graph(storage=store)
    mc.delete_all()
    colour = mc.add_sample(sample)
    assert mc.get_sample_colour(sample) == colour
    assert mc.colours_to_sample_dict().get(colour) == sample


@given(Graph=ST_GRAPH, store=st_storage, sample=st_sample_name,
       kmers=st.lists(KMER, min_size=1, max_size=100), binary_kmers=st_binary_kmers)
def test_insert_lookup_kmers(Graph, store, sample, kmers, binary_kmers):
    mc = Graph(binary_kmers=binary_kmers, storage=store)
    mc.delete_all()
    mc.insert(kmers, sample)
    for kmer in kmers:
        assert sample in mc.lookup(kmer)
    assert sample in mc.lookup(kmers)


# @given(Graph=ST_GRAPH, store=st_storage, kmer=KMER, binary_kmers=st_binary_kmers)
# def test_insert_get_kmer(Graph, store, kmer, binary_kmers):<commit_msg>Return bytes from storage when appropriate<commit_after>"""Tests that are common to graphs"""
from atlasseq import ProbabilisticMultiColourDeBruijnGraph
import random
from atlasseq.utils import make_hash
from atlasseq.utils import reverse_comp
from hypothesis import given
from hypothesis import example
import hypothesis.strategies as st
from atlasseq.bytearray import ByteArray


POSSIBLE_STORAGES = [{'dict': None},
                     {"redis": {"conn": [('localhost', 6379, 2)]}},
                     {'berkeleydb': {'filename': './db'}}]
st_storage = st.sampled_from(POSSIBLE_STORAGES)
st_sample_colour = st.integers(min_value=0, max_value=10)
st_sample_name = st.text(min_size=1)

BINARY_KMERS_OR_NOT = [True, False]
st_binary_kmers = st.sampled_from(BINARY_KMERS_OR_NOT)
KMER = st.text(min_size=31, max_size=31, alphabet=['A', 'T', 'C', 'G'])
ST_GRAPH = st.sampled_from([ProbabilisticMultiColourDeBruijnGraph])


@given(Graph=ST_GRAPH, binary_kmers=st_binary_kmers)
def test_init(Graph, binary_kmers):
    mc = Graph(binary_kmers=binary_kmers)
    assert mc.binary_kmers == binary_kmers
    assert mc.num_hashes > 0


@given(Graph=ST_GRAPH, store=st_storage, sample=st_sample_name)
def test_add_sample_metadata(Graph, store, sample):
    print("new test", Graph, store, sample)
    mc = Graph(storage=store)
    mc.delete_all()
    colour = mc.add_sample(sample)
    assert mc.get_sample_colour(sample) == colour
    assert mc.colours_to_sample_dict().get(colour) == sample


@given(Graph=ST_GRAPH, store=st_storage, sample=st_sample_name,
       kmers=st.lists(KMER, min_size=1, max_size=100), binary_kmers=st_binary_kmers)
def test_insert_lookup_kmers(Graph, store, sample, kmers, binary_kmers):
    mc = Graph(binary_kmers=binary_kmers, storage=store)
    mc.delete_all()
    mc.insert(kmers, sample)
    for kmer in kmers:
        assert sample in mc.lookup(kmer)
    print(mc.lookup(kmers))
    assert sample in mc.lookup(kmers)


# @given(Graph=ST_GRAPH, store=st_storage, kmer=KMER, binary_kmers=st_binary_kmers)
# def test_insert_get_kmer(Graph, store, kmer, binary_kmers):
{'fraction_non_alphanumeric': 0.11466666666666667, 'fraction_numerical': 0.008727272727272728, 'mean_word_length': 5.549206349206349, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2473168', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1462, 'n_words': 293}