pyqtgraph/tests/test_Vector.py
Ogi Moore a6971c768d Move and Update test-data repo into pyqtgraph repo
To reduce complexity, and make it easier to add more images and tests,
the images in the `test-data` repository should be merged with the main
repository.  Furthermore, we can remove a lot of the subprocess work in
the image_testing.py file, as we no longer need to have it interact with
git.

The images are not the same.  Images were regenerated with Qt6, and now
have proper big and little endian handling thanks to @pijyoi

Second commit is a slightly modified variant of
2e135ab282d6007b34a3854921be54d0e9efb241 authored by @pijyoi
it is to convert qimages to RGBA8888 for testing.  Image
files were regenerated images for the big/little handling

Fixed issue with bogus test from test_NonUniformImage and generated a
new image
2021-05-31 21:05:00 -07:00

78 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
import pytest
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
def test_Vector_init():
"""Test construction of Vector objects from a variety of source types."""
# separate values without z
v = pg.Vector(0, 1)
assert v.z() == 0
v = pg.Vector(0.0, 1.0)
assert v.z() == 0
# separate values with 3 args
v = pg.Vector(0, 1, 2)
assert v.x() == 0
assert v.y() == 1
assert v.z() == 2
v = pg.Vector(0.0, 1.0, 2.0)
assert v.x() == 0
assert v.y() == 1
assert v.z() == 2
# all in a list
v = pg.Vector([0, 1])
assert v.z() == 0
v = pg.Vector([0, 1, 2])
# QSizeF
v = pg.Vector(QtCore.QSizeF(1, 2))
assert v.x() == 1
assert v.z() == 0
# QPoint
v = pg.Vector(QtCore.QPoint(0, 1))
assert v.z() == 0
v = pg.Vector(QtCore.QPointF(0, 1))
assert v.z() == 0
# QVector3D
qv = QtGui.QVector3D(1, 2, 3)
v = pg.Vector(qv)
assert v == qv
with pytest.raises(Exception):
v = pg.Vector(1, 2, 3, 4)
def test_Vector_interface():
"""Test various aspects of the Vector API."""
v = pg.Vector(-1, 2)
# len
assert len(v) == 3
# indexing
assert v[0] == -1
assert v[2] == 0
with pytest.raises(IndexError):
x = v[4]
assert v[1] == 2
v[1] = 5
assert v[1] == 5
# iteration
v2 = pg.Vector(*v)
assert v2 == v
assert abs(v).x() == 1
# angle
v1 = pg.Vector(1, 0)
v2 = pg.Vector(1, 1)
assert abs(v1.angle(v2) - 45) < 0.001