<commit_before>from __future__ import print_function

import warnings
from distutils.version import StrictVersion

import numpy as np
import pytest

from .conftest import BMI_VERSION_STRING, INPUT_FILE, Bmi

BMI_VERSION = StrictVersion(BMI_VERSION_STRING)

BAD_VALUE = {"f": np.nan, "i": -999, "u": 0}


def empty_var_buffer(bmi, var_name):
    gid = bmi.get_var_grid(var_name)
    if BMI_VERSION > "1.0":
        loc = bmi.get_var_location(var_name)
    else:
        warnings.warn(
            "get_var_location not implemented (assuming nodes)", FutureWarning
        )
        loc = "node"

    if loc == "node":
        size = bmi.get_grid_size(gid)
    elif loc == "edge":
        size = bmi.get_grid_number_of_edges(gid)
    else:
        size = 0

    dtype = np.dtype(bmi.get_var_type(var_name))
    values = np.empty(size, dtype=dtype)

    return values


def test_get_var_location(initialized_bmi, var_name):
    """Test for get_var_location"""
    if BMI_VERSION < "1.1":
        pytest.skip(
            "testing BMIv{ver}: get_var_location was introduced in BMIv1.1".format(
                ver=BMI_VERSION
            )
        )

    assert hasattr(initialized_bmi, "get_var_location")

    loc = initialized_bmi.get_var_location(var_name)

    assert isinstance(loc, str)
    assert loc in ("node", "edge", "face")


def test_get_input_values(staged_tmpdir, in_var_name):<commit_msg>fix: test for values defined on faces<commit_after>from __future__ import print_function

import warnings
from distutils.version import StrictVersion

import numpy as np
import pytest

from .conftest import BMI_VERSION_STRING, INPUT_FILE, Bmi

BMI_VERSION = StrictVersion(BMI_VERSION_STRING)

BAD_VALUE = {"f": np.nan, "i": -999, "u": 0}


def empty_var_buffer(bmi, var_name):
    gid = bmi.get_var_grid(var_name)
    if BMI_VERSION > "1.0":
        loc = bmi.get_var_location(var_name)
    else:
        warnings.warn(
            "get_var_location not implemented (assuming nodes)", FutureWarning
        )
        loc = "node"

    if loc == "node":
        size = bmi.get_grid_size(gid)
    elif loc == "edge":
        size = bmi.get_grid_edge_count(gid)
    elif loc == "face":
        size = bmi.get_grid_face_count(gid)
    else:
        size = 0

    dtype = np.dtype(bmi.get_var_type(var_name))
    values = np.empty(size, dtype=dtype)

    return values


def test_get_var_location(initialized_bmi, var_name):
    """Test for get_var_location"""
    if BMI_VERSION < "1.1":
        pytest.skip(
            "testing BMIv{ver}: get_var_location was introduced in BMIv1.1".format(
                ver=BMI_VERSION
            )
        )

    assert hasattr(initialized_bmi, "get_var_location")

    loc = initialized_bmi.get_var_location(var_name)

    assert isinstance(loc, str)
    assert loc in ("node", "edge", "face")


def test_get_input_values(staged_tmpdir, in_var_name):
{'fraction_non_alphanumeric': 0.10176531671858775, 'fraction_numerical': 0.00761509172724126, 'mean_word_length': 3.0646976090014064, 'pattern_counts': {'":': 15, '<': 5, '<?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': '914499', 'n_tokens_mistral': 1020, 'n_tokens_neox': 982, 'n_words': 222}