<commit_before>#!/usr/bin/env python
#
# Tests for the dakota.vector_parameter_study module.
#
# Call with:
#   $ nosetests -sv
#
# <NAME> (<EMAIL>)

import os
from nose.tools import assert_is_instance, assert_true
from dakota.methods.vector_parameter_study import VectorParameterStudy
from . import start_dir, data_dir


# Global variables -----------------------------------------------------

config_file = os.path.join(data_dir, 'config.yaml')

# Fixtures -------------------------------------------------------------


def setup_module():
    """Called before any tests are performed."""
    print('\n*** ' + __name__)
    global v
    v = VectorParameterStudy()


def teardown_module():
    """Called after all tests have completed."""
    pass

# Tests ----------------------------------------------------------------


def test_init_no_params():
    """Test creating an instance with no parameters."""
    v1 = VectorParameterStudy()
    assert_is_instance(v1, VectorParameterStudy)


def test_init_from_file_like1():
    """Test creating an instance from a config file."""
    v1 = VectorParameterStudy.from_file_like(config_file)
    assert_is_instance(v1, VectorParameterStudy)


def test_init_from_file_like2():
    """Test creating an instance from an open config file object."""
    with open(config_file, 'r') as fp:
        v1 = VectorParameterStudy.from_file_like(fp)
    assert_is_instance(v1, VectorParameterStudy)


def test_method_block():
    """Test type of method_block method results."""
    s = v.method_block()<commit_msg>Add unit tests for VectorParameterStudy getters/setters<commit_after>#!/usr/bin/env python
#
# Tests for the dakota.vector_parameter_study module.
#
# Call with:
#   $ nosetests -sv
#
# <NAME> (<EMAIL>)

import os
from nose.tools import raises, assert_is_instance, assert_true, assert_equal
from dakota.methods.vector_parameter_study import VectorParameterStudy
from . import start_dir, data_dir


# Global variables -----------------------------------------------------

config_file = os.path.join(data_dir, 'config.yaml')

# Fixtures -------------------------------------------------------------


def setup_module():
    """Called before any tests are performed."""
    print('\n*** ' + __name__)
    global v
    v = VectorParameterStudy()


def teardown_module():
    """Called after all tests have completed."""
    pass

# Tests ----------------------------------------------------------------


def test_init_no_params():
    """Test creating an instance with no parameters."""
    v1 = VectorParameterStudy()
    assert_is_instance(v1, VectorParameterStudy)


def test_init_from_file_like1():
    """Test creating an instance from a config file."""
    v1 = VectorParameterStudy.from_file_like(config_file)
    assert_is_instance(v1, VectorParameterStudy)


def test_init_from_file_like2():
    """Test creating an instance from an open config file object."""
    with open(config_file, 'r') as fp:
        v1 = VectorParameterStudy.from_file_like(fp)
    assert_is_instance(v1, VectorParameterStudy)


def test_get_initial_point():
    """Test getting the initial_point property."""
    assert_true(type(v.initial_point) is tuple)


def test_set_initial_point():
    """Test setting the initial_point property."""
    point = (42,)
    v.initial_point = point
    assert_equal(v.initial_point, point)


@raises(TypeError)
def test_set_initial_point_fails_if_scalar():
    """Test that the initial_point property fails with scalar."""
    point = 42
    v.initial_point = point


def test_get_final_point():
    """Test getting the final_point property."""
    assert_true(type(v.final_point) is tuple)


def test_set_final_point():
    """Test setting the final_point property."""
    point = (42,)
    v.final_point = point
    assert_equal(v.final_point, point)


@raises(TypeError)
def test_set_final_point_fails_if_scalar():
    """Test that the final_point property fails with scalar."""
    point = 42
    v.final_point = point


def test_method_block():
    """Test type of method_block method results."""
    s = v.method_block()
{'fraction_non_alphanumeric': 0.183837890625, 'fraction_numerical': 0.005859375, 'mean_word_length': 2.8614514608859567, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4544190', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1153, 'n_words': 314}