<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import glob
import os

import pytest
import yaml

import knowit
from knowit.utils import CustomLoader

__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))


def _parameters():
    parameters = []
    input_dir = os.path.join(__location__, 'mediainfo')
    yml_files = [f for f in glob.glob(os.path.join(input_dir, '*.yml'))]

    for input_file in yml_files:
        with open(input_file, 'r') as stream:
            data = yaml.load(stream, Loader=CustomLoader)

        raw = data['input']
        expected = data['expected']
        parameters.append([raw, expected])

    return parameters


@pytest.mark.parametrize('raw,expected', _parameters())
def test_mediainfo_provider(raw, expected):
    # Given
    options = dict(provider='mediainfo', raw=False)

    # When
    actual = knowit.knowit(raw, options)

    # Then
    assert expected == actual<commit_msg>Monkeypatch mediainfo provider<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import glob
import os

import pytest
import yaml

import knowit
from knowit.utils import CustomLoader

__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))


def _parameters():
    parameters = []
    input_dir = os.path.join(__location__, 'mediainfo')
    yml_files = [f for f in glob.glob(os.path.join(input_dir, '*.yml'))]

    for input_file in yml_files:
        with open(input_file, 'r') as stream:
            data = yaml.load(stream, Loader=CustomLoader)

        raw = data['input']
        expected = data['expected']
        parameters.append([raw, expected])

    return parameters


@pytest.mark.parametrize('raw,expected', _parameters())
def test_mediainfo_provider(monkeypatch, raw, expected):
    # Given
    options = dict(provider='mediainfo', raw=False)
    monkeypatch.setattr('knowit.providers.mediainfo.INITIALIZED', True)
    monkeypatch.setattr('knowit.providers.mediainfo.MEDIA_INFO_AVAILABLE', True)

    # When
    actual = knowit.knowit(raw, options)

    # Then
    assert expected == actual
{'fraction_non_alphanumeric': 0.12179188054129725, 'fraction_numerical': 0.0009332711152589828, 'mean_word_length': 3.743362831858407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5289964', 'n_tokens_mistral': 703, 'n_tokens_neox': 678, 'n_words': 154}