Пример #1
0
def test_type_checking_int_to_float_coersion():
    """It's possible to make 'float' Point from 'int' values"""

    src = [[0.0, 1, 2], array([0, 1, 2])]  # list with 'int' values  # array of 'int' type

    for s in src:
        p = Point(coordarray=s, coordtype=float)
        assert_almost_equal(p.toarray(), array([0.0, 1.0, 2.0], dtype=float64))
Пример #2
0
def test_type_checking_int_to_float_coersion():
    """It's possible to make 'float' Point from 'int' values"""

    src = [
        [0.0, 1, 2],  # list with 'int' values
        array([0, 1, 2])  # array of 'int' type
    ]

    for s in src:
        p = Point(coordarray=s, coordtype=float)
        assert_almost_equal(p.toarray(), array([0.0, 1.0, 2.0], dtype=float64))
Пример #3
0
def test_nonchar_coordnames():
    """Non-char coordnames are converted to strings"""
    p = Point({"coorddict": {11: 1.0, 100: -1.0}})
    assert_almost_equal(p.toarray(), array([-1.0, 1.0], dtype=float64))
    assert p.coordnames == ["100", "11"]
Пример #4
0
def test_named_dict():
    """Create Point from dict with 'coorddict' key"""
    p = Point({"coorddict": {"x": -1.0, "y": 1.0}})
    assert_almost_equal(p.toarray(), array([-1.0, 1.0], dtype=float64))
    assert p.coordnames == ["x", "y"]
Пример #5
0
def test_type_checking_scalar():
    """Using 'float' value for 'int' Point is forbidden"""
    with pytest.raises(AssertionError):
        Point({'coorddict': {'x': 0.0}, 'coordtype': int})
Пример #6
0
def test_coordarray_empty_list():
    """Empty lists are forbidden"""
    with pytest.raises(ValueError):
        Point({'coordarray': []})
Пример #7
0
def test_dict_empty_array():
    """Empty arrays are forbidden"""
    with pytest.raises(ValueError):
        Point({'x': array([]), 'y': 0.0})
Пример #8
0
def test_dict_with_array_values():
    """Arrays are truncated to first element"""
    p = Point({'x': array([1.0]), 'y': array([-1.0, 2.0])})
    assert_almost_equal(p.toarray(), array([1.0, -1.0], dtype=float64))
Пример #9
0
def test_list_explicit_float():
    """Convert 'float' to 'float64'"""
    _check_point(Point(coordarray=[0.0, 1.0, 2.0], coordtype=float), float64)
Пример #10
0
def test_list_default():
    """Use 'float64' by default when 'coordtype' is omitted"""
    _check_point(Point(coordarray=[0.0, 1.0, 2.0]), float64)
Пример #11
0
def test_dict_explicit_int():
    """Convert 'int' to 'int32'"""
    _check_point(Point(coorddict={'x': 1, 'y': -1}, coordtype=int), int32)
Пример #12
0
def test_dict_explicit_float():
    """Convert 'float' to 'float64'"""
    _check_point(Point(coorddict={
        'x': 1.0,
        'y': -1.0
    }, coordtype=float), float64)
Пример #13
0
def test_dict_default():
    """Use 'float64' by default for Point from dict"""
    _check_point(Point({'x': 1.0, 'y': -1.0}), float64)
Пример #14
0
def test_type_checking_exotic_values():
    """Exotic values are caught by numpy"""
    with pytest.raises(TypeError):
        Point({'x': 'x', 'y': 'y'})
Пример #15
0
def test_type_checking_array_for_coordarray():
    """Build 'int' Point from 'float' array is forbidden"""
    with pytest.raises(AssertionError):
        Point({'coordarray': array([0.0, 1.0, 2.0], float), 'coordtype': int})
Пример #16
0
def test_list_explicit_int():
    """Convert 'int' to 'int32'"""
    _check_point(Point(coordarray=[0, 1, 2], coordtype=int), int32)
Пример #17
0
def test_named_dict():
    """Create Point from dict with 'coorddict' key"""
    p = Point({'coorddict': {'x': -1.0, 'y': 1.0}})
    assert_almost_equal(p.toarray(), array([-1.0, 1.0], dtype=float64))
    assert p.coordnames == ['x', 'y']
Пример #18
0
def test_array_float():
    """All float arrays are coerced to float64"""

    for ftype in _all_numpy_float:
        _check_point(Point(coordarray=array([0.0, 1.0, 2.0], dtype=ftype)),
                     float64)
Пример #19
0
def test_dict_empty_list():
    """Empty lists are forbidden"""
    with pytest.raises(ValueError):
        Point({'x': [], 'y': 0.0})
Пример #20
0
def test_array_int():
    """All int arrays are coerced to int32"""

    for itype in _all_numpy_int:
        _check_point(Point(coordarray=array([0, 1, 2]), dtype=itype), int32)
Пример #21
0
def test_nonchar_coordnames():
    """Non-char coordnames are converted to strings"""
    p = Point({'coorddict': {11: 1.0, 100: -1.0}})
    assert_almost_equal(p.toarray(), array([-1.0, 1.0], dtype=float64))
    assert p.coordnames == ['100', '11']
Пример #22
0
def test_duplicated_coordnames():
    """Duplicated coord names are forbidden"""
    with pytest.raises(AssertionError):
        Point({'coordarray': [0.0, 1.0], 'coordnames': 'xx'})
Пример #23
0
def test_coordarray_empty_array():
    """Empty arrays are forbidden"""
    with pytest.raises(ValueError):
        Point({'coordarray': array([])})
Пример #24
0
def test_non_matching_lengths():
    """Length of values sequence must be equal to the length of names sequence"""
    with pytest.raises(ValueError):
        Point({'coordarray': [0.0, 1.0], 'coordnames': 'xyz'})
Пример #25
0
def test_type_checking_list_for_coord():
    """Using list of 'float' values for 'int' Point is forbidden"""
    with pytest.raises(AssertionError):
        Point({'coorddict': {'x': [0.0]}, 'coordtype': int})
Пример #26
0
def test_wrong_rank():
    """Values must be scalar or one-dimension array"""
    with pytest.raises(ValueError):
        Point({'coordarray': [[0.0, 1.0], [2.0, 3.0]], 'coordnames': 'xyz'})
Пример #27
0
def test_named_argument():
    """Create Point from name/value dict as a named argument"""
    p = Point(coorddict={"x": 1.0, "y": -1.0})
    assert_almost_equal(p.toarray(), array([1.0, -1.0], dtype=float64))
    assert p.coordnames == ["x", "y"]
Пример #28
0
def test_missing_coord_data():
    """Coord values are required argument"""
    with pytest.raises(ValueError):
        Point({'coordnames': 'xyz'})
Пример #29
0
def test_dict_with_array_values():
    """Arrays are truncated to first element"""
    p = Point({"x": array([1.0]), "y": array([-1.0, 2.0])})
    assert_almost_equal(p.toarray(), array([1.0, -1.0], dtype=float64))
Пример #30
0
def test_named_argument():
    """Create Point from name/value dict as a named argument"""
    p = Point(coorddict={'x': 1.0, 'y': -1.0})
    assert_almost_equal(p.toarray(), array([1.0, -1.0], dtype=float64))
    assert p.coordnames == ['x', 'y']
Пример #31
0
def test_filteredDict_works_as_expected_for_Point():
    p = Point({'x': 1, 'y': 2, 'z': 3})
    assert {} == filteredDict(p, ['w'])
    assert {'x': 1, 'y': 2} == filteredDict(p, ['x', 'y'])
    assert {'z': 3} == filteredDict(p, ['x', 'y'], neg=True)
Пример #32
0
def test_type_checking_list_for_coordarray():
    """Build 'int' Point from list of 'float' values is forbidden"""
    with pytest.raises(AssertionError):
        Point({'coordarray': [0.0, 1.0, 2.0], 'coordtype': int})