How to use the pytest.approx function in pytest

To help you get started, we’ve selected a few pytest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OSGeo / gdal / autotest / utilities / test_gdaltransform.py View on Github external
def test_gdaltransform_ct_4D():
    if test_cli_utilities.get_gdaltransform_path() is None:
        pytest.skip()

    ret = gdaltest.runexternal(test_cli_utilities.get_gdaltransform_path() + ' -ct "+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=cart +step +proj=helmert +convention=position_vector +x=0.0127 +dx=-0.0029 +rx=-0.00039 +drx=-0.00011 +y=0.0065 +dy=-0.0002 +ry=0.00080 +dry=-0.00019 +z=-0.0209 +dz=-0.0006 +rz=-0.00114 +drz=0.00007 +s=0.00195 +ds=0.00001 +t_epoch=1988.0 +step +proj=cart +inv +step +proj=unitconvert +xy_in=rad +xy_out=deg" -coord 2 49 0 2000')

    values = [float(x) for x in ret.split(' ')]
    assert len(values) == 3, ret
    assert values[0] == pytest.approx(2.0000005420366, abs=1e-10), ret
    assert values[1] == pytest.approx(49.0000003766711, abs=1e-10), ret
    assert values[2] == pytest.approx(-0.0222802283242345, abs=1e-8), ret
github OSGeo / gdal / autotest / utilities / test_gdaltransform.py View on Github external
def test_gdaltransform_6():
    if test_cli_utilities.get_gdaltransform_path() is None:
        pytest.skip()

    strin = '440720 3751320\n'
    ret = gdaltest.runexternal(test_cli_utilities.get_gdaltransform_path() + ' ../gcore/data/byte.tif ../gcore/data/byte.tif', strin)

    text_split = ret.split(' ')
    x = float(text_split[0])
    y = float(text_split[1])

    assert x == pytest.approx(440720, abs=1e-4) and y == pytest.approx(3751320, abs=1e-4), ret
github fastats / fastats / tests / core / test_single_pass.py View on Github external
def test_math_tanh_function_supported():
    data = np.arange(0.1, 1.0, 0.1, dtype='float32')

    result = single_pass(data, value=math.tanh)

    assert result[0] == approx(0.099668)
    assert result[1] == approx(0.19737533)
    assert result[2] == approx(0.29131263)
    assert sum(result) == approx(3.9521739)
github SCIP-Interfaces / PySCIPOpt / tests / test_solutionIO.py View on Github external
def assert_equal_solutiondata(current, expected):
    solobj, variables = current
    exp_solobj, exp_variables = expected

    assert approx(float(solobj)) == float(exp_solobj)

    for name, (val, obj) in exp_variables.items():
        if name in variables:
            exp_val, exp_obj = variables[name]
            assert val == approx(exp_val), \
                "variable {} has wrong value: expected {} got {}".format(name, val, exp_val)
            assert obj == approx(exp_obj), \
                "variable {} has wrong objectiv: expected {} got {}".format(name, obj, exp_obj)
        else:
            assert val == approx(0), \
                "variable {} was not in solutionfile even so its value is {} and not zero".format(name, val)
github psychrometrics / psychrolib / tests / test_psychrolib_ip.py View on Github external
def test_GetStandardAtmPressure(psy):
    assert psy.GetStandardAtmPressure(-1000) == pytest.approx(15.236, abs = 1)
    assert psy.GetStandardAtmPressure(    0) == pytest.approx(14.696, abs = 1)
    assert psy.GetStandardAtmPressure( 1000) == pytest.approx(14.175, abs = 1)
    assert psy.GetStandardAtmPressure( 3000) == pytest.approx(13.173, abs = 1)
    assert psy.GetStandardAtmPressure(10000) == pytest.approx(10.108, abs = 1)
    assert psy.GetStandardAtmPressure(30000) == pytest.approx( 4.371, abs = 1)
github dit / dit / tests / multivariate / test_o_information.py View on Github external
def test_o_information_1(dist, rvs, crvs, value):
    """
    Test the o-information against known values.
    """
    assert o_information(dist=dist, rvs=rvs, crvs=crvs) == pytest.approx(value)
github Jammy2211 / PyAutoLens / test / unit / lens / test_ray_tracing.py View on Github external
def test__x2_planes__sis_lens__traced_grid_includes_deflections__on_planes_setup(
            self, sub_grid_7x7_simple, gal_x1_mp
        ):

            tracer = ray_tracing.Tracer.from_galaxies(
                galaxies=[gal_x1_mp, g.Galaxy(redshift=1.0)]
            )

            traced_grids_of_planes = tracer.traced_grids_of_planes_from_grid(
                grid=sub_grid_7x7_simple, return_in_2d=False
            )

            assert traced_grids_of_planes[0][0] == pytest.approx(
                np.array([1.0, 1.0]), 1e-3
            )
            assert traced_grids_of_planes[0][1] == pytest.approx(
                np.array([1.0, 0.0]), 1e-3
            )
            assert traced_grids_of_planes[0][2] == pytest.approx(
                np.array([1.0, 1.0]), 1e-3
            )
            assert traced_grids_of_planes[0][3] == pytest.approx(
                np.array([1.0, 0.0]), 1e-3
            )

            assert traced_grids_of_planes[1][0] == pytest.approx(
                np.array([1.0 - 0.707, 1.0 - 0.707]), 1e-3
            )
            assert traced_grids_of_planes[1][1] == pytest.approx(
                np.array([0.0, 0.0]), 1e-3
            )
            assert traced_grids_of_planes[1][2] == pytest.approx(
github bloomberg / powerfulseal / tests / k8s / test_metrics_server_client.py View on Github external
def test_parse_cpu_string():
    metrics_server = MetricsServerClient(None)
    assert metrics_server.parse_cpu_string('1') == pytest.approx(1)
    assert metrics_server.parse_cpu_string('100') == pytest.approx(100)
    assert metrics_server.parse_cpu_string('1n') == pytest.approx(0.000000001)
    assert metrics_server.parse_cpu_string('10n') == pytest.approx(0.00000001)
github girder / large_image / test / test_source_tiff.py View on Github external
def testHistogram():
    imagePath = utilities.externaldata('data/sample_image.ptif.sha512')
    source = large_image_source_tiff.TiffFileTileSource(imagePath)
    hist = source.histogram(bins=8, output={'maxWidth': 1024}, resample=False)
    assert len(hist['histogram']) == 3
    assert hist['histogram'][0]['range'] == (0, 256)
    assert list(hist['histogram'][0]['hist']) == [182, 276, 639, 1426, 2123, 2580, 145758, 547432]
    assert list(hist['histogram'][0]['bin_edges']) == [0, 32, 64, 96, 128, 160, 192, 224, 256]
    assert hist['histogram'][0]['samples'] == 700416

    hist = source.histogram(bins=256, output={'maxWidth': 1024},
                            resample=False, density=True)
    assert len(hist['histogram']) == 3
    assert hist['histogram'][0]['range'] == (0, 256)
    assert len(list(hist['histogram'][0]['hist'])) == 256
    assert hist['histogram'][0]['hist'][128] == pytest.approx(5.43e-5, 0.01)
    assert hist['histogram'][0]['samples'] == 700416

    hist = source.histogram(bins=256, output={'maxWidth': 2048},
                            density=True, resample=False)
    assert hist['histogram'][0]['samples'] == 2801664
    assert hist['histogram'][0]['hist'][128] == pytest.approx(6.39e-5, 0.01)
github lenskit / lkpy / tests / test_topn_ndcg.py View on Github external
def test_dcg_single():
    "a single element should be scored at the right place"
    assert _dcg(np.array([0.5])) == approx(0.5)
    assert _dcg(np.array([0, 0.5])) == approx(0.5)
    assert _dcg(np.array([0, 0, 0.5])) == approx(0.5 / np.log2(3))
    assert _dcg(np.array([0, 0, 0.5, 0])) == approx(0.5 / np.log2(3))