Ejemplo n.º 1
0
def test_generate_points_random_num_points():
    """Test generate_points with random returns correct number of points"""
    param_dict = sf.read_param_ranges(
        os.path.join(test_files_dir, 'folder', 'test_file_1'))
    command = 'batch-submit 16 -m random -s'
    with mock.patch('sys.argv', command.split(' ')):
        args = get_args()

    _, num_points = sf.generate_points(args, param_dict)
    assert num_points == 16
Ejemplo n.º 2
0
def test_generate_points_random_ranges():
    """Test generate_points with random  gens points within ranges"""
    param_dict = sf.read_param_ranges(
        os.path.join(test_files_dir, 'folder', 'test_file_1'))
    command = 'batch-submit 16 -m random -s'
    with mock.patch('sys.argv', command.split(' ')):
        args = get_args()

    param_dict, num_points_ = sf.generate_points(args, param_dict)
    for param, info in param_dict.iteritems():
        for value in info['values']:
            assert info['range'][0] <= value <= info['range'][1]
Ejemplo n.º 3
0
def test_generate_points_uniform_num_points_input():
    """Test generate_points with uniform returns correct number of points"""
    param_dict = sf.read_param_ranges(
        os.path.join(test_files_dir, 'folder', 'test_file_1'))
    command = 'batch-submit 10 -m uniform -s'
    with mock.patch('sys.argv', command.split(' ')):
        args = get_args()

    # Create mock object to replace raw_input and return 'yes' when called
    with mock.patch.object(__builtin__, 'raw_input', lambda x: 'yes'):
        _, num_points = param_dict, _ = sf.generate_points(args, param_dict)

    assert num_points == 16
Ejemplo n.º 4
0
def test_read_param_ranges_valid():
    """Test read_param_ranges successful on valid param file"""
    param_file_1 = os.path.join(test_files_dir, 'folder', 'test_file_1')
    params = sf.read_param_ranges(param_file_1)
    expected_params = {
        'param1': {
            'range': (0, 1),
            'values': []
        },
        'param2': {
            'range': (10, 100),
            'values': []
        },
        'param3': {
            'range': (4, 10),
            'values': []
        },
        'param4': {
            'range': (0, 1),
            'values': []
        }
    }
    assert params == expected_params
Ejemplo n.º 5
0
def test_read_param_ranges_min_greater_than_max():
    """Test read_param_ranges fails when min value greater or equal to max"""
    param_file_3 = os.path.join(test_files_dir, 'folder', 'folder_depth_2',
                                'test_file_3')
    with pytest.raises(ValueError):
        sf.read_param_ranges(param_file_3)
Ejemplo n.º 6
0
def test_read_param_ranges_invalid():
    """Test read_param_ranges fails on an invalid param file"""
    param_file_2 = os.path.join(test_files_dir, 'folder', 'test_file_2')
    with pytest.raises(ValueError):
        sf.read_param_ranges(param_file_2)