forked from yt-project/unyt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_unyt_testing.py
51 lines (37 loc) · 1.48 KB
/
test_unyt_testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Test unyt.testing module that contains utilities for writing tests.
"""
# ----------------------------------------------------------------------------
# Copyright (c) 2013, yt Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------
import pytest
from unyt.array import unyt_array, unyt_quantity
from unyt.testing import assert_allclose_units
def test_equality():
a1 = unyt_array([1.0, 2.0, 3.0], "cm")
a2 = unyt_array([1.0, 2.0, 3.0], "cm")
assert_allclose_units(a1, a2)
def test_unequal_error():
a1 = unyt_array([1.0, 2.0, 3.0], "cm")
a2 = unyt_array([4.0, 5.0, 6.0], "cm")
with pytest.raises(AssertionError):
assert_allclose_units(a1, a2)
def test_conversion_error():
a1 = unyt_array([1.0, 2.0, 3.0], "cm")
a2 = unyt_array([1.0, 2.0, 3.0], "kg")
with pytest.raises(AssertionError):
assert_allclose_units(a1, a2)
def test_runtime_error():
a1 = unyt_array([1.0, 2.0, 3.0], "cm")
a2 = unyt_array([1.0, 2.0, 3.0], "cm")
with pytest.raises(RuntimeError):
assert_allclose_units(a1, a2, rtol=unyt_quantity(1e-7, "cm"))
def test_atol_conversion_error():
a1 = unyt_array([1.0, 2.0, 3.0], "cm")
a2 = unyt_array([1.0, 2.0, 3.0], "cm")
with pytest.raises(AssertionError):
assert_allclose_units(a1, a2, atol=unyt_quantity(0.0, "kg"))