当前位置: 首页>>代码示例>>Python>>正文


Python pytest.approx方法代码示例

本文整理汇总了Python中pytest.approx方法的典型用法代码示例。如果您正苦于以下问题:Python pytest.approx方法的具体用法?Python pytest.approx怎么用?Python pytest.approx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytest的用法示例。


在下文中一共展示了pytest.approx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_text_classification_unified_information

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_text_classification_unified_information(notebooks, tmp):
    notebook_path = notebooks["tc_unified_information"]
    pm.execute_notebook(
        notebook_path,
        OUTPUT_NOTEBOOK,
        kernel_name=KERNEL_NAME,
        parameters=dict(
            DATA_FOLDER=tmp,
            BERT_CACHE_DIR=tmp,
            BATCH_SIZE=32,
            BATCH_SIZE_PRED=512,
            NUM_EPOCHS=1,
            TEST=True,
            QUICK_RUN=True,
        ),
    )
    result = sb.read_notebook(OUTPUT_NOTEBOOK).scraps.data_dict
    assert pytest.approx(result["accuracy"], 0.93, abs=ABS_TOL)
    assert pytest.approx(result["precision"], 0.93, abs=ABS_TOL)
    assert pytest.approx(result["recall"], 0.93, abs=ABS_TOL)
    assert pytest.approx(result["f1"], 0.93, abs=ABS_TOL) 
开发者ID:interpretml,项目名称:interpret-text,代码行数:23,代码来源:test_notebook_unified_information_explainer.py

示例2: test_has_fields

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_has_fields(self):
        '''
        Initially, doing a limited test of fields as figure out how mamu of the
        CourseEnrollment model fields and relationships we need to capture.
        '''
        data = self.serializer.data

        assert data['course_id'] == str(self.model_obj.course_id)
        # assert data['course']['id'] == str(self.model_obj.course.id)
        # assert data['course']['display_name'] == self.model_obj.course.display_name
        # assert data['course']['org'] == self.model_obj.course.org

        assert dateutil_parse(data['created']) == self.model_obj.created
        assert data['user']['fullname'] == self.model_obj.user.profile.name

        for field_name in (self.expected_results_keys - self.special_fields):
            db_field = getattr(self.model_obj, field_name)
            if type(db_field) in (float, Decimal, ):
                assert float(data[field_name]) == pytest.approx(db_field)
            else:
                assert data[field_name] == db_field 
开发者ID:appsembler,项目名称:figures,代码行数:23,代码来源:test_serializers.py

示例3: test_text_classification_introspective_rationale

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_text_classification_introspective_rationale(notebooks, tmp):
    notebook_path = notebooks["tc_introspective_rationale"]
    pm.execute_notebook(
        notebook_path,
        OUTPUT_NOTEBOOK,
        kernel_name=KERNEL_NAME,
        parameters=dict(
            DATA_FOLDER=tmp,
            CUDA=torch.cuda.is_available(),
            QUICK_RUN=False,
            MODEL_SAVE_DIR=tmp
        ),
    )
    result = sb.read_notebook(OUTPUT_NOTEBOOK).scraps.data_dict
    print(result)
    assert pytest.approx(result["accuracy"], 0.72, abs=ABS_TOL)
    assert pytest.approx(result["anti_accuracy"], 0.69, abs=ABS_TOL)
    assert pytest.approx(result["sparsity"], 0.17, abs=ABS_TOL) 
开发者ID:interpretml,项目名称:interpret-text,代码行数:20,代码来源:test_notebook_introspective_rationale_explainer.py

示例4: test_ciftify_seedcorr_cifti_output_with_mask

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_ciftify_seedcorr_cifti_output_with_mask(output_dir, left_hemisphere_dir):
    seedcorr_output = os.path.join(output_dir,
                                  'seedcorr.dscalar.nii')
    run(['ciftify_seed_corr', '--debug',
         '--outputname', seedcorr_output,
         '--weighted',
         '--mask', os.path.join(left_hemisphere_dir, 'mask_L.dscalar.nii'),
         test_dtseries,
         weighted_dscalar])
    meants5, labels5 = get_the_5_rois_meants_outputs(seedcorr_output, output_dir, custom_dlabel)
    assert os.path.isfile(seedcorr_output)
    print(meants5)
    print(labels5)
    assert pytest.approx(meants5.loc[0,0], 0.001) == 0.0875
    assert pytest.approx(meants5.loc[1,0], 0.001) == 0
    assert pytest.approx(meants5.loc[3,0], 0.001) == 0 
开发者ID:edickie,项目名称:ciftify,代码行数:18,代码来源:test_ciftify_seed_corr.py

示例5: test_ciftify_seedcorr_cifti_output_nifti_seed

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_ciftify_seedcorr_cifti_output_nifti_seed(output_dir, subcort_images_dir):
    seedcorr_output = os.path.join(output_dir,
                                  'seedcorr.dscalar.nii')
    run(['ciftify_seed_corr',
         '--debug',
         '--roi-label 4',
         '--outputname', seedcorr_output,
         test_dtseries,
         os.path.join(subcort_images_dir, 'rois.nii.gz')])
    meants5, labels5 = get_the_5_rois_meants_outputs(
        seedcorr_output, output_dir, custom_dlabel)
    print(meants5)
    print(labels5)
    assert os.path.isfile(seedcorr_output)
    assert pytest.approx(meants5.loc[0,0], 0.001) == 0.1256
    assert pytest.approx(meants5.loc[1,0], 0.001) == 0.3094
    assert pytest.approx(meants5.loc[3,0], 0.001) == 0.3237
    assert pytest.approx(meants5.loc[4,0], 0.001) == 0.1458 
开发者ID:edickie,项目名称:ciftify,代码行数:20,代码来源:test_ciftify_seed_corr.py

示例6: test_ciftify_seedcorr_cifti_output_with_TRfile

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_ciftify_seedcorr_cifti_output_with_TRfile(output_dir):
    seedcorr_output = os.path.join(output_dir,
                                  'seedcorr.dscalar.nii')
    TR_file = os.path.join(output_dir, 'TR_file.txt')
    with open(TR_file, "w") as text_file:
        text_file.write('''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''')
    run(['ciftify_seed_corr',
         '--outputname', seedcorr_output,
         '--use-TRs', TR_file,
         '--weighted',
         test_dtseries,
         weighted_dscalar])
    assert os.path.isfile(seedcorr_output)
    meants5, labels5 = get_the_5_rois_meants_outputs(
        seedcorr_output, output_dir, custom_dlabel)
    assert pytest.approx(meants5.loc[0,0], 0.001) == 0.0929
    assert pytest.approx(meants5.loc[1,0], 0.001) == 0.482
    assert pytest.approx(meants5.loc[3,0], 0.001) == 0.220 
开发者ID:edickie,项目名称:ciftify,代码行数:20,代码来源:test_ciftify_seed_corr.py

示例7: test_attributes

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_attributes(context):
    # Timer1: periodic interval 0.8 sec
    timer1 = timer.Timer(
        interval=0.8,
        expire_function=context.timer1_expired)
    # Timer2: one-shot interval 0.7 sec
    timer2 = timer.Timer(
        interval=0.7,
        expire_function=context.timer2_expired,
        periodic=False)
    assert timer1.running() is True
    assert timer1.interval() == pytest.approx(0.8)
    assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer1.remaining_time_str())
    assert timer2.running() is True
    assert timer2.interval() == pytest.approx(0.7)
    assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer2.remaining_time_str())
    time.sleep(1.0)
    timer.TIMER_SCHEDULER.trigger_all_expired_timers()
    assert timer1.running() is True
    assert timer1.interval() == pytest.approx(0.8)
    assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer1.remaining_time_str())
    assert timer2.running() is False
    assert timer2.interval() == pytest.approx(0.7)
    assert timer2.remaining_time_str() == "Stopped" 
开发者ID:brunorijsman,项目名称:rift-python,代码行数:26,代码来源:test_timer.py

示例8: test_correct_average

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_correct_average():
    # Tests what is being depicted in figure 3 of 'Evaluating MOT Performance'
    acc = mm.MOTAccumulator(auto_id=True)

    # No track
    acc.update([1, 2, 3, 4], [], [])
    acc.update([1, 2, 3, 4], [], [])
    acc.update([1, 2, 3, 4], [], [])
    acc.update([1, 2, 3, 4], [], [])

    # Track single
    acc.update([4], [4], [0])
    acc.update([4], [4], [0])
    acc.update([4], [4], [0])
    acc.update([4], [4], [0])

    mh = mm.metrics.create()
    metr = mh.compute(acc, metrics='mota', return_dataframe=False)
    assert metr['mota'] == approx(0.2) 
开发者ID:facebookresearch,项目名称:PoseWarper,代码行数:21,代码来源:test_mot.py

示例9: test_report_current

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_report_current(mocker, config_dir):
    mocker.patch('arrow.utcnow', return_value=arrow.get(5000))

    watson = Watson(
        current={'project': 'foo', 'start': 4000},
        config_dir=config_dir
    )

    for _ in range(2):
        report = watson.report(
            arrow.utcnow(), arrow.utcnow(), current=True, projects=['foo']
        )
    assert len(report['projects']) == 1
    assert report['projects'][0]['name'] == 'foo'
    assert report['projects'][0]['time'] == pytest.approx(1000)

    report = watson.report(
        arrow.utcnow(), arrow.utcnow(), current=False, projects=['foo']
    )
    assert len(report['projects']) == 0

    report = watson.report(
        arrow.utcnow(), arrow.utcnow(), projects=['foo']
    )
    assert len(report['projects']) == 0 
开发者ID:TailorDev,项目名称:Watson,代码行数:27,代码来源:test_watson.py

示例10: test_h3_to_geo_boundary

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_h3_to_geo_boundary():
    out = h3.h3_to_geo_boundary('85283473fffffff')

    expected = [
        [37.271355866731895, -121.91508032705622],
        [37.353926450852256, -121.86222328902491],
        [37.42834118609435, -121.9235499963016],
        [37.42012867767778, -122.0377349642703],
        [37.33755608435298, -122.09042892904395],
        [37.26319797461824, -122.02910130919],
    ]

    assert len(out) == len(expected)

    for o, e in zip(out, expected):
        assert o == approx(e) 
开发者ID:uber,项目名称:h3-py,代码行数:18,代码来源:test_h3.py

示例11: test_h3_to_geo_boundary_geo_json

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_h3_to_geo_boundary_geo_json():
    out = h3.h3_to_geo_boundary('85283473fffffff', True)

    expected = [
        [-121.91508032705622, 37.271355866731895],
        [-121.86222328902491, 37.353926450852256],
        [-121.9235499963016, 37.42834118609435],
        [-122.0377349642703, 37.42012867767778],
        [-122.09042892904395, 37.33755608435298],
        [-122.02910130919, 37.26319797461824],
        [-121.91508032705622, 37.271355866731895],
    ]

    assert len(out) == len(expected)

    for o, e in zip(out, expected):
        assert o == approx(e) 
开发者ID:uber,项目名称:h3-py,代码行数:19,代码来源:test_h3.py

示例12: test_steps_mid

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_steps_mid(ax):
    ax.plot([0, 1], [0, 1], drawstyle="steps-mid")
    ax.set(xlim=(-1, 2), ylim=(-1, 2))
    cursor = mplcursors.cursor()
    _process_event("__mouse_click__", ax, (0, 1), 1)
    assert len(cursor.selections) == 0
    _process_event("__mouse_click__", ax, (1, 0), 1)
    assert len(cursor.selections) == 0
    _process_event("__mouse_click__", ax, (.25, 0), 1)
    index = cursor.selections[0].target.index
    assert (index.int, index.x, index.y) == approx((0, .25, 0))
    _process_event("__mouse_click__", ax, (.5, .5), 1)
    index = cursor.selections[0].target.index
    assert (index.int, index.x, index.y) == approx((0, .5, .5))
    _process_event("__mouse_click__", ax, (.75, 1), 1)
    index = cursor.selections[0].target.index
    assert (index.int, index.x, index.y) == approx((0, .75, 1)) 
开发者ID:anntzer,项目名称:mplcursors,代码行数:19,代码来源:test_mplcursors.py

示例13: test_errorbar

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_errorbar(ax):
    ax.errorbar(range(2), range(2), [(1, 1), (1, 2)])
    cursor = mplcursors.cursor()
    assert len(cursor.artists) == 1
    _process_event("__mouse_click__", ax, (0, 2), 1)
    assert len(cursor.selections) == 0
    _process_event("__mouse_click__", ax, (.5, .5), 1)
    assert cursor.selections[0].target == approx((.5, .5))
    assert _parse_annotation(
        cursor.selections[0], "x=(.*)\ny=(.*)") == approx((.5, .5))
    _process_event("__mouse_click__", ax, (0, 1), 1)
    assert cursor.selections[0].target == approx((0, 0))
    assert _parse_annotation(
        cursor.selections[0], r"x=(.*)\ny=\$(.*)\\pm(.*)\$") == (0, 0, 1)
    _process_event("__mouse_click__", ax, (1, 2), 1)
    sel, = cursor.selections
    assert sel.target == approx((1, 1))
    assert _parse_annotation(
        sel, r"x=(.*)\ny=\$(.*)_\{(.*)\}\^\{(.*)\}\$") == (1, 1, -1, 2) 
开发者ID:anntzer,项目名称:mplcursors,代码行数:21,代码来源:test_mplcursors.py

示例14: test_move

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_move(ax, plotter):
    plotter(ax, [0, 1, 2], [0, 1, np.nan])
    cursor = mplcursors.cursor()
    # Nothing happens with no cursor.
    _process_event("key_press_event", ax, (.123, .456), "shift+left")
    assert len(cursor.selections) == 0
    # Now we move the cursor left or right.
    if plotter in [Axes.plot, Axes.errorbar]:
        _process_event("__mouse_click__", ax, (.5, .5), 1)
        assert tuple(cursor.selections[0].target) == approx((.5, .5))
        _process_event("key_press_event", ax, (.123, .456), "shift+up")
        _process_event("key_press_event", ax, (.123, .456), "shift+left")
    elif plotter is Axes.scatter:
        _process_event("__mouse_click__", ax, (0, 0), 1)
        _process_event("key_press_event", ax, (.123, .456), "shift+up")
    assert tuple(cursor.selections[0].target) == (0, 0)
    assert cursor.selections[0].target.index == 0
    _process_event("key_press_event", ax, (.123, .456), "shift+right")
    assert tuple(cursor.selections[0].target) == (1, 1)
    assert cursor.selections[0].target.index == 1
    # Skip through nan.
    _process_event("key_press_event", ax, (.123, .456), "shift+right")
    assert tuple(cursor.selections[0].target) == (0, 0)
    assert cursor.selections[0].target.index == 0 
开发者ID:anntzer,项目名称:mplcursors,代码行数:26,代码来源:test_mplcursors.py

示例15: test_session_expiration_set_to_configured_lifetime

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import approx [as 别名]
def test_session_expiration_set_to_configured_lifetime(self, time_mock, utc_time_sans_frac_mock):
        timestamp = time.mktime(datetime(2017, 1, 1).timetuple())
        time_mock.return_value = timestamp
        utc_time_sans_frac_mock.return_value = int(timestamp)

        exp_time = 10
        state = 'test_state'
        nonce = 'test_nonce'
        id_token = IdToken(iss=self.PROVIDER_BASEURL,
                           aud=self.CLIENT_ID,
                           sub='sub1',
                           exp=int(timestamp) + exp_time,
                           iat=int(timestamp),
                           nonce=nonce)
        token_response = {'access_token': 'test', 'token_type': 'Bearer', 'id_token': id_token.to_jwt()}
        token_endpoint = self.PROVIDER_BASEURL + '/token'
        responses.add(responses.POST, token_endpoint, json=token_response)

        session_lifetime = 1234
        self.app.config['PERMANENT_SESSION_LIFETIME'] = session_lifetime
        self.init_app(provider_metadata_extras={'token_endpoint': token_endpoint})

        with self.app.test_client() as client:
            with client.session_transaction() as session:
                UserSession(session, self.PROVIDER_NAME)
                session['destination'] = '/'
                session['state'] = state
                session['nonce'] = nonce
            resp = client.get('/redirect_uri?state={}&code=test'.format(state))

        cookies = SimpleCookie()
        cookies.load(resp.headers['Set-Cookie'])
        session_cookie_expiration = cookies[self.app.config['SESSION_COOKIE_NAME']]['expires']
        parsed_expiration = datetime.strptime(session_cookie_expiration, '%a, %d-%b-%Y %H:%M:%S GMT')
        cookie_lifetime = (parsed_expiration - datetime.utcnow()).total_seconds()
        assert cookie_lifetime == pytest.approx(session_lifetime, abs=1) 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:38,代码来源:test_flask_pyoidc.py


注:本文中的pytest.approx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。