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


Python testing.assert_equal函数代码示例

本文整理汇总了Python中vispy.testing.assert_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_equal函数的具体用法?Python assert_equal怎么用?Python assert_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_import_vispy_scene

def test_import_vispy_scene():
    """ Importing vispy.gloo.gl.desktop should not import PyOpenGL. """
    modnames = loaded_vispy_modules('vispy.scene', 2)
    more_modules = ['vispy.app', 'vispy.gloo', 'vispy.glsl', 'vispy.scene', 
                    'vispy.color', 
                    'vispy.io', 'vispy.geometry', 'vispy.visuals']
    assert_equal(modnames, set(_min_modules + more_modules))
开发者ID:Calvarez20,项目名称:vispy,代码行数:7,代码来源:test_import.py

示例2: test_FunctionCall

def test_FunctionCall():
    fun = Function(transformScale)
    fun['scale'] = '1.0'
    fun2 = Function(transformZOffset)
    
    # No args
    assert_raises(TypeError, fun)  # need 1 arg
    assert_raises(TypeError, fun, 1, 2)  # need 1 arg
    call = fun('x')
    # Test repr
    exp = call.expression({fun: 'y'})
    assert_equal(exp, 'y(x)')
    # Test sig
    assert len(call._args) == 1
    # Test dependencies
    assert_in(fun, call.dependencies())
    assert_in(call._args[0], call.dependencies())
    
    # More args
    call = fun(fun2('foo'))
    # Test repr
    exp = call.expression({fun: 'y', fun2: 'z'})
    assert_in('y(z(', exp)
    # Test sig
    assert len(call._args) == 1
    call2 = call._args[0]
    assert len(call2._args) == 1
    # Test dependencies
    assert_in(fun, call.dependencies())
    assert_in(call._args[0], call.dependencies())
    assert_in(fun2, call.dependencies())
    assert_in(call2._args[0], call.dependencies())
开发者ID:rougier,项目名称:vispy,代码行数:32,代码来源:test_function.py

示例3: test_use

def test_use():
    
    # Set default app to None, so we can test the use function
    vispy.app.use_app()
    default_app = vispy.app._default_app.default_app
    vispy.app._default_app.default_app = None
    
    app_name = default_app.backend_name.split(' ')[0]
    
    try:
        # With no arguments, should do nothing
        assert_raises(TypeError, vispy.use)
        assert_equal(vispy.app._default_app.default_app, None)
        
        # With only gl args, should do nothing to app
        vispy.use(gl='gl2')
        assert_equal(vispy.app._default_app.default_app, None)
        
        # Specify app (one we know works)
        vispy.use(app_name)
        assert_not_equal(vispy.app._default_app.default_app, None)
        
        # Again, but now wrong app
        wrong_name = 'glfw' if app_name.lower() != 'glfw' else 'pyqt4'
        assert_raises(RuntimeError, vispy.use, wrong_name)
        
        # And both
        vispy.use(app_name, 'gl2')
    
    finally:
        # Restore
        vispy.app._default_app.default_app = default_app
开发者ID:Calvarez20,项目名称:vispy,代码行数:32,代码来源:test_vispy.py

示例4: test_use_framebuffer

def test_use_framebuffer():
    """Test drawing to a framebuffer"""
    shape = (100, 300)  # for some reason Windows wants a tall window...
    data = np.random.rand(*shape).astype(np.float32)
    use_shape = shape + (3,)
    with Canvas(size=shape[::-1]) as c:
        orig_tex = Texture2D(data)
        fbo_tex = Texture2D(use_shape, format='rgb')
        rbo = RenderBuffer(shape, 'color')
        fbo = FrameBuffer(color=fbo_tex)
        c.context.glir.set_verbose(True)
        assert_equal(c.size, shape[::-1])
        set_viewport((0, 0) + c.size)
        with fbo:
            draw_texture(orig_tex)
        draw_texture(fbo_tex)
        out_tex = _screenshot()[::-1, :, 0].astype(np.float32)
        assert_equal(out_tex.shape, c.size[::-1])
        assert_raises(TypeError, FrameBuffer.color_buffer.fset, fbo, 1.)
        assert_raises(TypeError, FrameBuffer.depth_buffer.fset, fbo, 1.)
        assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, fbo, 1.)
        fbo.color_buffer = rbo
        fbo.depth_buffer = RenderBuffer(shape)
        fbo.stencil_buffer = None
        print((fbo.color_buffer, fbo.depth_buffer, fbo.stencil_buffer))
        clear(color='black')
        with fbo:
            clear(color='black')
            draw_texture(orig_tex)
            out_rbo = _screenshot()[:, :, 0].astype(np.float32)
    assert_allclose(data * 255., out_tex, atol=1)
    assert_allclose(data * 255., out_rbo, atol=1)
开发者ID:Calvarez20,项目名称:vispy,代码行数:32,代码来源:test_use_gloo.py

示例5: test_FunctionChain

def test_FunctionChain():
    
    f1 = Function("void f1(){}")
    f2 = Function("void f2(){}")
    f3 = Function("float f3(vec3 x){}")
    f4 = Function("vec3 f4(vec3 y){}")
    f5 = Function("vec3 f5(vec4 z){}")
    
    ch = FunctionChain('chain', [f1, f2])
    assert ch.name == 'chain'
    assert ch.args == []
    assert ch.rtype == 'void'
    
    assert_in('f1', ch.compile())
    assert_in('f2', ch.compile())
    
    ch.remove(f2)
    assert_not_in('f2', ch.compile())

    ch.append(f2)
    assert_in('f2', ch.compile())

    ch = FunctionChain(funcs=[f5, f4, f3])
    assert_equal('float', ch.rtype)
    assert_equal([('vec4', 'z')], ch.args)
    assert_in('f3', ch.compile())
    assert_in('f4', ch.compile())
    assert_in('f5', ch.compile())
    assert_in(f3, ch.dependencies())
    assert_in(f4, ch.dependencies())
    assert_in(f5, ch.dependencies())
开发者ID:rougier,项目名称:vispy,代码行数:31,代码来源:test_function.py

示例6: test_context_properties

def test_context_properties():
    """Test setting context properties"""
    a = use_app()
    if a.backend_name.lower() == 'pyglet':
        return  # cannot set more than once on Pyglet
    # stereo, double buffer won't work on every sys
    configs = [dict(samples=4), dict(stencil_size=8),
               dict(samples=4, stencil_size=8)]
    if a.backend_name.lower() != 'glfw':  # glfw *always* double-buffers
        configs.append(dict(double_buffer=False, samples=4))
        configs.append(dict(double_buffer=False))
    else:
        assert_raises(RuntimeError, Canvas, app=a,
                      config=dict(double_buffer=False))
    if a.backend_name.lower() == 'sdl2' and os.getenv('TRAVIS') == 'true':
        raise SkipTest('Travis SDL cannot set context')
    for config in configs:
        n_items = len(config)
        with Canvas(config=config):
            if 'true' in (os.getenv('TRAVIS', ''),
                          os.getenv('APPVEYOR', '').lower()):
                # Travis and Appveyor cannot handle obtaining these values
                props = config
            else:
                props = get_gl_configuration()
            assert_equal(len(config), n_items)
            for key, val in config.items():
                # XXX knownfail for windows samples, and wx (all platforms)
                if key == 'samples':
                    iswx = a.backend_name.lower() == 'wx'
                    if not (sys.platform.startswith('win') or iswx):
                        assert_equal(val, props[key], key)
    assert_raises(TypeError, Canvas, config='foo')
    assert_raises(KeyError, Canvas, config=dict(foo=True))
    assert_raises(TypeError, Canvas, config=dict(double_buffer='foo'))
开发者ID:Lx37,项目名称:vispy,代码行数:35,代码来源:test_context.py

示例7: test_event_order

def test_event_order():
    """Test event order"""
    x = list()

    class MyCanvas(Canvas):
        def on_initialize(self, event):
            x.append('init')

        def on_draw(self, event):
            sz = True if self.size is not None else False
            x.append('draw size=%s show=%s' % (sz, show))

        def on_close(self, event):
            x.append('close')

    for show in (False, True):
        # clear our storage variable
        while x:
            x.pop()
        with MyCanvas(show=show) as c:
            c.update()
            c.app.process_events()

        print(x)
        assert_true(len(x) >= 3)
        assert_equal(x[0], 'init')
        assert_in('draw size=True', x[1])
        assert_in('draw size=True', x[-2])
        assert_equal(x[-1], 'close')
开发者ID:Eric89GXL,项目名称:vispy,代码行数:29,代码来源:test_app.py

示例8: test_config

def test_config():
    """Test vispy config methods and file downloading"""
    assert_raises(TypeError, config.update, data_path=dict())
    assert_raises(KeyError, config.update, foo="bar")  # bad key
    data_dir = op.join(temp_dir, "data")
    assert_raises(IOError, set_data_dir, data_dir)  # didn't say to create
    orig_val = os.environ.get("_VISPY_CONFIG_TESTING", None)
    os.environ["_VISPY_CONFIG_TESTING"] = "true"
    try:
        assert_raises(IOError, set_data_dir, data_dir)  # doesn't exist yet
        set_data_dir(data_dir, create=True, save=True)
        assert_equal(config["data_path"], data_dir)
        config["data_path"] = data_dir
        print(config)  # __repr__
        load_data_file("CONTRIBUTING.txt")
        fid = open(op.join(data_dir, "test-faked.txt"), "w")
        fid.close()
        load_data_file("test-faked.txt")  # this one shouldn't download
        assert_raises(RuntimeError, load_data_file, "foo-nonexist.txt")
        save_config()
    finally:
        if orig_val is not None:
            os.environ["_VISPY_CONFIG_TESTING"] = orig_val
        else:
            del os.environ["_VISPY_CONFIG_TESTING"]
开发者ID:bdvd,项目名称:vispy,代码行数:25,代码来源:test_config.py

示例9: test_serialize_command

def test_serialize_command():
    command = ('CREATE', 4, 'VertexBuffer')
    command_serialized = _serialize_command(command)
    assert_equal(command_serialized, list(command))

    command = ('UNIFORM', 4, 'u_scale', 'vec3', (1, 2, 3))
    commands_serialized_expected = ['UNIFORM', 4, 'u_scale', 'vec3', [1, 2, 3]]
    command_serialized = _serialize_command(command)
    assert_equal(command_serialized, commands_serialized_expected)
开发者ID:Eric89GXL,项目名称:vispy,代码行数:9,代码来源:test_ipynb_util.py

示例10: test_use_uniforms

def test_use_uniforms():
    """Test using uniform arrays"""
    VERT_SHADER = """
    attribute vec2 a_pos;
    varying vec2 v_pos;

    void main (void)
    {
        v_pos = a_pos;
        gl_Position = vec4(a_pos, 0., 1.);
    }
    """

    FRAG_SHADER = """
    varying vec2 v_pos;
    uniform vec3 u_color[2];

    void main()
    {
        gl_FragColor = vec4((u_color[0] + u_color[1]) / 2., 1.);
    }
    """
    shape = (500, 500)
    with Canvas(size=shape) as c:
        c.set_current()
        c.context.glir.set_verbose(True)
        assert_equal(c.size, shape[::-1])
        shape = (3, 3)
        set_viewport((0, 0) + shape)
        program = Program(VERT_SHADER, FRAG_SHADER)
        program['a_pos'] = [[-1., -1.], [1., -1.], [-1., 1.], [1., 1.]]
        program['u_color'] = np.ones((2, 3))
        c.context.clear('k')
        c.set_current()
        program.draw('triangle_strip')
        out = _screenshot()
        assert_allclose(out[:, :, 0] / 255., np.ones(shape), atol=1. / 255.)

        # now set one element
        program['u_color[1]'] = np.zeros(3, np.float32)
        c.context.clear('k')
        program.draw('triangle_strip')
        out = _screenshot()
        assert_allclose(out[:, :, 0] / 255., 127.5 / 255. * np.ones(shape),
                        atol=1. / 255.)

        # and the other
        assert_raises(ValueError, program.__setitem__, 'u_color',
                      np.zeros(3, np.float32))
        program['u_color'] = np.zeros((2, 3), np.float32)
        program['u_color[0]'] = np.ones(3, np.float32)
        c.context.clear((0.33,) * 3)
        program.draw('triangle_strip')
        out = _screenshot()
        assert_allclose(out[:, :, 0] / 255., 127.5 / 255. * np.ones(shape),
                        atol=1. / 255.)
开发者ID:rougier,项目名称:vispy,代码行数:56,代码来源:test_use_gloo.py

示例11: test_key

def test_key():
    """Test basic key functionality"""
    def bad():
        return (ENTER == dict())
    assert_raises(ValueError, bad)
    assert_true(not (ENTER == None))  # noqa
    assert_equal('Return', ENTER)
    print(ENTER.name)
    print(ENTER)  # __repr__
    assert_equal(Key('1'), 49)  # ASCII code
开发者ID:Calvarez20,项目名称:vispy,代码行数:10,代码来源:test_key.py

示例12: test_close_keys

def test_close_keys():
    """Test close keys"""
    c = Canvas(keys='interactive')
    x = list()

    @c.events.close.connect
    def closer(event):
        x.append('done')
    c.events.key_press(key=keys.ESCAPE, text='', modifiers=[])
    assert_equal(len(x), 1)  # ensure the close event was sent
    c.app.process_events()
开发者ID:Eric89GXL,项目名称:vispy,代码行数:11,代码来源:test_app.py

示例13: test_create_glir_message_binary

def test_create_glir_message_binary():
    arr = np.zeros((3, 2)).astype(np.float32)
    arr2 = np.ones((4, 5)).astype(np.int16)

    commands = [('CREATE', 1, 'VertexBuffer'),
                ('UNIFORM', 2, 'u_scale', 'vec3', (1, 2, 3)),
                ('DATA', 3, 0, arr),
                ('UNIFORM', 4, 'u_pan', 'vec2', np.array([1, 2, 3])),
                ('DATA', 5, 20, arr2)]
    msg = create_glir_message(commands)
    assert_equal(msg['msg_type'], 'glir_commands')

    commands_serialized = msg['commands']
    assert_equal(commands_serialized,
                 [['CREATE', 1, 'VertexBuffer'],
                  ['UNIFORM', 2, 'u_scale', 'vec3', [1, 2, 3]],
                  ['DATA', 3, 0, {'buffer_index': 0,
                                  'buffer_shape': [3, 2],
                                  'buffer_dtype': 'float32'}],
                  ['UNIFORM', 4, 'u_pan', 'vec2', [1, 2, 3]],
                  ['DATA', 5, 20, {'buffer_index': 1,
                                   'buffer_shape': [4, 5],
                                   'buffer_dtype': 'int16'}]])

    buffers_serialized = msg['buffers']
    buf0 = buffers_serialized[0]
    assert_equal(buf0, b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')  # noqa

    buf1 = buffers_serialized[1]
    assert_equal(buf1, b'\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00')  # noqa
开发者ID:Eric89GXL,项目名称:vispy,代码行数:30,代码来源:test_ipynb_util.py

示例14: test_import_vispy_scene

def test_import_vispy_scene():
    """ Importing vispy.gloo.gl.desktop should not import PyOpenGL. """
    modnames = loaded_vispy_modules("vispy.scene", 2)
    more_modules = [
        "vispy.app",
        "vispy.gloo",
        "vispy.glsl",
        "vispy.scene",
        "vispy.color",
        "vispy.io",
        "vispy.geometry",
        "vispy.visuals",
    ]
    assert_equal(modnames, set(_min_modules + more_modules))
开发者ID:ringw,项目名称:vispy,代码行数:14,代码来源:test_import.py

示例15: test_logging

def test_logging():
    """Test logging context manager"""
    ll = logger.level
    with use_log_level('warning', print_msg=False):
        assert_equal(logger.level, logging.WARN)
    assert_equal(logger.level, ll)
    with use_log_level('debug', print_msg=False):
        assert_equal(logger.level, logging.DEBUG)
    assert_equal(logger.level, ll)
开发者ID:Lx37,项目名称:vispy,代码行数:9,代码来源:test_logging.py


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