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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
# -*- coding: utf-8 -*-
import numpy as np
import pytest
from vispy.scene.visuals import Markers
from vispy.testing import (requires_application, TestingCanvas,
run_tests_if_main)
from vispy.testing.image_tester import assert_image_approved
@requires_application()
def test_markers():
"""Test basic marker / point-sprite support"""
# this is probably too basic, but it at least ensures that point sprites
# work for people
np.random.seed(57983)
data = np.random.normal(size=(30, 2), loc=50, scale=10)
with TestingCanvas() as c:
marker = Markers(parent=c.scene)
marker.set_data(data)
assert_image_approved(c.render(), "visuals/markers.png")
# Test good correlation at high-dpi
with TestingCanvas(px_scale=2) as c:
marker = Markers(parent=c.scene)
marker.set_data(data)
assert_image_approved(c.render(), "visuals/markers.png")
def test_markers_edge_width():
data = np.random.rand(10, 3)
edge_width = np.random.rand(10)
marker = Markers()
with pytest.raises(ValueError):
marker.set_data(pos=data, edge_width_rel=1, edge_width=1)
marker.set_data(pos=data, edge_width=2)
marker.set_data(pos=data, edge_width=edge_width)
with pytest.raises(ValueError):
marker.set_data(pos=data, edge_width=-1)
marker.set_data(pos=data, edge_width_rel=edge_width, edge_width=None)
marker.set_data(pos=data, edge_width_rel=edge_width + 1, edge_width=None)
with pytest.raises(ValueError):
marker.set_data(pos=data, edge_width_rel=edge_width - 1, edge_width=None)
def test_empty_markers_symbol():
markers = Markers()
markers.symbol = 'o'
run_tests_if_main()
|