File: comparison.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (10 lines) | stat: -rw-r--r-- 387 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
import pytest
import numpy as np

def compare_with_pytest_approx(quantity, expected_values, rel_tol):
    """
    Cast inputted objects to numpy arrays and assert equivalence via
    pytest.approx with the requested relative tolerance
    """
    quantity, expected_values = map(np.asarray, [quantity, expected_values])
    assert quantity == pytest.approx(expected_values, rel=rel_tol)