<commit_before>import pytest
import tempfile

import adam
from adam.core import AssetStorage
from adam.core import Asset
from adam.core import WavReader
from adam.core import UnknownMimeTypeError

@pytest.fixture
def storage():
    return AssetStorage()

def test_contains_asset(storage):
    a = Asset()
    storage['key'] = a
    assert storage['key'] == a
    
def test_contains_key(storage):
    a = Asset()
    assert 'key' not in storage
    storage['key'] = a
    assert 'key' in storage
    
def test_asset_is_versioned(storage):
    a = Asset()
    updated_a = Asset()
    storage['key'] = a
    storage['key'] = updated_a
    versions = storage.versions_of('key')
    assert len(versions) == 2
    assert versions[0] == a
    assert versions[1] == updated_a

def test_asset_is_deleted(storage):
    a = Asset()
    storage['key'] = a
    del storage['key']
    assert 'key' not in storage

def test_search_asset(storage):
    assets_with_1s_duration = storage.get(duration=1)
    assert not assets_with_1s_duration
    
    a = Asset()
    a.duration = 1
    storage['key'] = a

    assets_with_1s_duration = storage.get(duration=1)
    assert len(assets_with_1s_duration) == 1
    assert assets_with_1s_duration[0] == a

def test_read_unkown_file():
    wav_path = 'tests/16-bit-mono.wav'
    asset = adam.read(wav_path)
    assert asset == WavReader().read(wav_path)

    mp3_path = 'tests/64kbits.mp3'
    asset = adam.read(mp3_path)
    assert asset == adam.readMp3(mp3_path)
    
def test_reading_file_with_unknown_mime_type_raises_exception():
    with tempfile.NamedTemporaryFile() as tmp:
        with pytest.raises(UnknownMimeTypeError):
            adam.read(tmp.name)


def test_supported_mime_types():
    assert len(adam.supported_mime_types) > 0

def test_deleting_unkown_key_raises_exception(storage):
    with pytest.raises(KeyError):
        del storage['key']

def test_create_asset_from_wav():
    reader = WavReader()
    asset = reader.read('tests/16-bit-mono.wav')
    assert asset.mime_type == 'audio/wav'<commit_msg>Changed wav asset creation test so it uses a package-level function instead of creating a reader object.<commit_after>import pytest
import tempfile

import adam
from adam.core import AssetStorage
from adam.core import Asset
from adam.core import UnknownMimeTypeError

@pytest.fixture
def storage():
    return AssetStorage()

def test_contains_asset(storage):
    a = Asset()
    storage['key'] = a
    assert storage['key'] == a
    
def test_contains_key(storage):
    a = Asset()
    assert 'key' not in storage
    storage['key'] = a
    assert 'key' in storage
    
def test_asset_is_versioned(storage):
    a = Asset()
    updated_a = Asset()
    storage['key'] = a
    storage['key'] = updated_a
    versions = storage.versions_of('key')
    assert len(versions) == 2
    assert versions[0] == a
    assert versions[1] == updated_a

def test_asset_is_deleted(storage):
    a = Asset()
    storage['key'] = a
    del storage['key']
    assert 'key' not in storage

def test_search_asset(storage):
    assets_with_1s_duration = storage.get(duration=1)
    assert not assets_with_1s_duration
    
    a = Asset()
    a.duration = 1
    storage['key'] = a

    assets_with_1s_duration = storage.get(duration=1)
    assert len(assets_with_1s_duration) == 1
    assert assets_with_1s_duration[0] == a

def test_read_unkown_file():
    wav_path = 'tests/16-bit-mono.wav'
    asset = adam.read(wav_path)
    assert asset == adam.readWav(wav_path)

    mp3_path = 'tests/64kbits.mp3'
    asset = adam.read(mp3_path)
    assert asset == adam.readMp3(mp3_path)
    
def test_reading_file_with_unknown_mime_type_raises_exception():
    with tempfile.NamedTemporaryFile() as tmp:
        with pytest.raises(UnknownMimeTypeError):
            adam.read(tmp.name)


def test_supported_mime_types():
    assert len(adam.supported_mime_types) > 0

def test_deleting_unkown_key_raises_exception(storage):
    with pytest.raises(KeyError):
        del storage['key']

def test_create_asset_from_wav():
    asset = adam.readWav('tests/16-bit-mono.wav')
    assert asset.mime_type == 'audio/wav'
{'fraction_non_alphanumeric': 0.10602759622367465, 'fraction_numerical': 0.012103606874848705, 'mean_word_length': 3.7222857142857144, 'pattern_counts': {'":': 0, '<': 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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1157939', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1392, 'n_words': 311}