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


Python decorators.image_comparison方法代码示例

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


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

示例1: make_set

# 需要导入模块: from matplotlib.testing import decorators [as 别名]
# 或者: from matplotlib.testing.decorators import image_comparison [as 别名]
def make_set(basename, fontset, tests, extensions=None):
    def make_test(filename, test):
        @image_comparison(baseline_images=[filename], extensions=extensions,
                          tol=32)
        def single_test():
            matplotlib.rcParams['mathtext.fontset'] = fontset
            fig = plt.figure(figsize=(5.25, 0.75))
            fig.text(0.5, 0.5, test, horizontalalignment='center', verticalalignment='center')
        func = single_test
        func.__name__ = str("test_" + filename)
        return func

    # We inject test functions into the global namespace, rather than
    # using a generator, so that individual tests can be run more
    # easily from the commandline and so each test will have its own
    # result.
    for i, test in enumerate(tests):
        filename = '%s_%s_%02d' % (basename, fontset, i)
        globals()['test_%s' % filename] = make_test(filename, test) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:21,代码来源:test_mathtext.py

示例2: test_rasterize_dpi

# 需要导入模块: from matplotlib.testing import decorators [as 别名]
# 或者: from matplotlib.testing.decorators import image_comparison [as 别名]
def test_rasterize_dpi():
    # This test should check rasterized rendering with high output resolution.
    # It plots a rasterized line and a normal image with implot. So it will catch
    # when images end up in the wrong place in case of non-standard dpi setting.
    # Instead of high-res rasterization i use low-res.  Therefore the fact that the
    # resolution is non-standard is is easily checked by image_comparison.
    import numpy as np
    import matplotlib.pyplot as plt

    img = np.asarray([[1, 2], [3, 4]])

    fig, axes = plt.subplots(1, 3, figsize = (3, 1))

    axes[0].imshow(img)

    axes[1].plot([0,1],[0,1], linewidth=20., rasterized=True)
    axes[1].set(xlim = (0,1), ylim = (-1, 2))

    axes[2].plot([0,1],[0,1], linewidth=20.)
    axes[2].set(xlim = (0,1), ylim = (-1, 2))

    # Low-dpi PDF rasterization errors prevent proper image comparison tests.
    # Hide detailed structures like the axes spines.
    for ax in axes:
        ax.set_xticks([])
        ax.set_yticks([])
        for spine in ax.spines.values():
            spine.set_visible(False)

    rcParams['savefig.dpi'] = 10 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:32,代码来源:test_image.py

示例3: make_all_2d_testfuncs

# 需要导入模块: from matplotlib.testing import decorators [as 别名]
# 或者: from matplotlib.testing.decorators import image_comparison [as 别名]
def make_all_2d_testfuncs(allfuncs=allfuncs):
    def make_test(func):
        filenames = [
            '%s-%s' % (func.__name__, x) for x in
            ['ref-img', 'nn-img', 'lin-img', 'ref-con', 'nn-con', 'lin-con']]

        # We only generate PNGs to save disk space -- we just assume
        # that any backend differences are caught by other tests.
        @image_comparison(filenames, extensions=['png'],
                          freetype_version=('2.4.5', '2.4.9'),
                          remove_text=True)
        def reference_test():
            nnt.plot(func, interp=False, plotter='imshow')
            nnt.plot(func, interp=True, plotter='imshow')
            lpt.plot(func, interp=True, plotter='imshow')
            nnt.plot(func, interp=False, plotter='contour')
            nnt.plot(func, interp=True, plotter='contour')
            lpt.plot(func, interp=True, plotter='contour')

        tester = reference_test
        tester.__name__ = str('test_%s' % func.__name__)
        return tester

    nnt = NNTester(npoints=1000)
    lpt = LinearTester(npoints=1000)
    for func in allfuncs:
        globals()['test_%s' % func.__name__] = make_test(func) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:29,代码来源:test_delaunay.py

示例4: test_rasterize_dpi

# 需要导入模块: from matplotlib.testing import decorators [as 别名]
# 或者: from matplotlib.testing.decorators import image_comparison [as 别名]
def test_rasterize_dpi():
    # This test should check rasterized rendering with high output resolution.
    # It plots a rasterized line and a normal image with implot.  So it will
    # catch when images end up in the wrong place in case of non-standard dpi
    # setting.  Instead of high-res rasterization I use low-res.  Therefore
    # the fact that the resolution is non-standard is easily checked by
    # image_comparison.
    img = np.asarray([[1, 2], [3, 4]])

    fig, axes = plt.subplots(1, 3, figsize=(3, 1))

    axes[0].imshow(img)

    axes[1].plot([0,1], [0,1], linewidth=20., rasterized=True)
    axes[1].set(xlim=(0, 1), ylim=(-1, 2))

    axes[2].plot([0,1], [0,1], linewidth=20.)
    axes[2].set(xlim=(0, 1), ylim=(-1, 2))

    # Low-dpi PDF rasterization errors prevent proper image comparison tests.
    # Hide detailed structures like the axes spines.
    for ax in axes:
        ax.set_xticks([])
        ax.set_yticks([])
        for spine in ax.spines.values():
            spine.set_visible(False)

    rcParams['savefig.dpi'] = 10 
开发者ID:holzschu,项目名称:python3_ios,代码行数:30,代码来源:test_image.py

示例5: test_rasterize_dpi

# 需要导入模块: from matplotlib.testing import decorators [as 别名]
# 或者: from matplotlib.testing.decorators import image_comparison [as 别名]
def test_rasterize_dpi():
    # This test should check rasterized rendering with high output resolution.
    # It plots a rasterized line and a normal image with implot. So it will catch
    # when images end up in the wrong place in case of non-standard dpi setting.
    # Instead of high-res rasterization i use low-res.  Therefore the fact that the
    # resolution is non-standard is easily checked by image_comparison.
    img = np.asarray([[1, 2], [3, 4]])

    fig, axes = plt.subplots(1, 3, figsize = (3, 1))

    axes[0].imshow(img)

    axes[1].plot([0,1],[0,1], linewidth=20., rasterized=True)
    axes[1].set(xlim = (0,1), ylim = (-1, 2))

    axes[2].plot([0,1],[0,1], linewidth=20.)
    axes[2].set(xlim = (0,1), ylim = (-1, 2))

    # Low-dpi PDF rasterization errors prevent proper image comparison tests.
    # Hide detailed structures like the axes spines.
    for ax in axes:
        ax.set_xticks([])
        ax.set_yticks([])
        for spine in ax.spines.values():
            spine.set_visible(False)

    rcParams['savefig.dpi'] = 10 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:29,代码来源:test_image.py

示例6: test_image_comparison_expect_rms

# 需要导入模块: from matplotlib.testing import decorators [as 别名]
# 或者: from matplotlib.testing.decorators import image_comparison [as 别名]
def test_image_comparison_expect_rms(im1, im2, tol, expect_rms):
    """Compare two images, expecting a particular RMS error.

    im1 and im2 are filenames relative to the baseline_dir directory.

    tol is the tolerance to pass to compare_images.

    expect_rms is the expected RMS value, or None. If None, the test will
    succeed if compare_images succeeds. Otherwise, the test will succeed if
    compare_images fails and returns an RMS error almost equal to this value.
    """
    im1 = os.path.join(baseline_dir, im1)
    im2_src = os.path.join(baseline_dir, im2)
    im2 = os.path.join(result_dir, im2)
    # Move im2 from baseline_dir to result_dir. This will ensure that
    # compare_images writes the diff file to result_dir, instead of trying to
    # write to the (possibly read-only) baseline_dir.
    shutil.copyfile(im2_src, im2)
    results = compare_images(im1, im2, tol=tol, in_decorator=True)

    if expect_rms is None:
        assert results is None
    else:
        assert results is not None
        assert results['rms'] == approx(expect_rms, abs=1e-4)


# The following tests are used by test_nose_image_comparison to ensure that the
# image_comparison decorator continues to work with nose. They should not be
# prefixed by test_ so they don't run with pytest. 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:32,代码来源:test_compare_images.py

示例7: test_nose_image_comparison

# 需要导入模块: from matplotlib.testing import decorators [as 别名]
# 或者: from matplotlib.testing.decorators import image_comparison [as 别名]
def test_nose_image_comparison(func, kwargs, errors, failures, dots,
                               monkeypatch):
    nose = pytest.importorskip('nose')
    monkeypatch.setattr('matplotlib._called_from_pytest', False)

    class TestResultVerifier(nose.result.TextTestResult):
        def __init__(self, *args, **kwargs):
            super(TestResultVerifier, self).__init__(*args, **kwargs)
            self.error_count = 0
            self.failure_count = 0

        def addError(self, test, err):
            super(TestResultVerifier, self).addError(test, err)

            if self.error_count < len(errors):
                assert err[0] is errors[self.error_count][0]
                assert errors[self.error_count][1] in str(err[1])
            else:
                raise err[1]
            self.error_count += 1

        def addFailure(self, test, err):
            super(TestResultVerifier, self).addFailure(test, err)

            assert self.failure_count < len(failures), err[1]
            assert err[0] is failures[self.failure_count][0]
            assert failures[self.failure_count][1] in str(err[1])
            self.failure_count += 1

    # Make sure that multiple extensions work, but don't require LaTeX or
    # Inkscape to do so.
    kwargs.setdefault('extensions', ['png', 'png', 'png'])

    func = image_comparison(**kwargs)(func)
    loader = nose.loader.TestLoader()
    suite = loader.loadTestsFromGenerator(
        func,
        'matplotlib.tests.test_compare_images')
    if six.PY2:
        output = io.BytesIO()
    else:
        output = io.StringIO()
    result = TestResultVerifier(stream=output, descriptions=True, verbosity=1)
    with warnings.catch_warnings():
        # Nose uses deprecated stuff; we don't care about it.
        warnings.simplefilter('ignore', DeprecationWarning)
        suite.run(result=result)

    assert output.getvalue() == dots
    assert result.error_count == len(errors)
    assert result.failure_count == len(failures) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:53,代码来源:test_compare_images.py


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