<commit_before>"""Test ModelData
"""
from unittest.mock import MagicMock, Mock

import numpy as np
from pytest import fixture
from smif.data_layer import DataHandle
from smif.metadata import Metadata, MetadataSet
from smif.model.dependency import Dependency
from smif.parameters import ParameterList


@fixture(scope='function')
def mock_store():
    store = Mock()
    store.read_results = MagicMock(return_value=np.array([[1.0]]))
    return store


@fixture(scope='function')
def mock_model():
    model = Mock()
    model.name = 'test_model'
    model.parameters = ParameterList()
    model.parameters.add_parameters_from_list([
        {
            'name': 'smart_meter_savings',
            'description': 'The savings from smart meters',
            'absolute_range': (0, 100),
            'suggested_range': (3, 10),
            'default_value': 3,
            'units': '%',
            'parent': None
        }
    ])
    model.inputs = MetadataSet([
        Metadata('test', 'test_regions', 'test_intervals', 'test_unit')
    ])
    model.outputs = MetadataSet([
        Metadata('test', 'test_regions', 'test_intervals', 'test_unit')
    ])
    source_model = Mock()
    source_model.name = 'test_source'
    model.deps = {
        'test': Dependency(
            source_model,
            Metadata('test_output', 'test_regions', 'test_intervals', 'test_unit'),
            Metadata('test', 'test_regions', 'test_intervals', 'test_unit')
        )
    }
    return model


def test_create():
    """should be created with a DataInterface
    """
    DataHandle(Mock(), 1, 2015, [2015, 2020], Mock())


def test_get_data(mock_store, mock_model):<commit_msg>Fix mocking test call for DataHandle<commit_after>"""Test ModelData
"""
from unittest.mock import MagicMock, Mock

import numpy as np
from pytest import fixture
from smif.data_layer import DataHandle
from smif.metadata import Metadata, MetadataSet
from smif.model.dependency import Dependency
from smif.parameters import ParameterList


@fixture(scope='function')
def mock_store():
    store = Mock()
    store.read_results = MagicMock(return_value=np.array([[1.0]]))
    return store


@fixture(scope='function')
def mock_model():
    model = Mock()
    model.name = 'test_model'
    model.parameters = ParameterList()
    model.parameters.add_parameters_from_list([
        {
            'name': 'smart_meter_savings',
            'description': 'The savings from smart meters',
            'absolute_range': (0, 100),
            'suggested_range': (3, 10),
            'default_value': 3,
            'units': '%',
            'parent': None
        }
    ])
    regions = Mock()
    regions.name = 'test_regions'
    intervals = Mock()
    intervals.name = 'test_intervals'
    model.inputs = MetadataSet([
        Metadata('test', regions, intervals, 'test_unit')
    ])
    model.outputs = MetadataSet([
        Metadata('test', regions, intervals, 'test_unit')
    ])
    source_model = Mock()
    source_model.name = 'test_source'
    model.deps = {
        'test': Dependency(
            source_model,
            Metadata('test_output', regions, intervals, 'test_unit'),
            Metadata('test', regions, intervals, 'test_unit')
        )
    }
    return model


def test_create():
    """should be created with a DataInterface
    """
    DataHandle(Mock(), 1, 2015, [2015, 2020], Mock())


def test_get_data(mock_store, mock_model):
{'fraction_non_alphanumeric': 0.12693770108218777, 'fraction_numerical': 0.013454226381983035, 'mean_word_length': 2.986013986013986, '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': '7642949', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1007, 'n_words': 246}