You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
5 years ago
|
import pytest
|
||
|
|
||
|
from clusterview.points import Attribute, PointSet
|
||
|
|
||
|
|
||
|
def test_add_to_point_set():
|
||
|
l = PointSet()
|
||
|
|
||
|
l.add_point(1, 2)
|
||
|
|
||
|
points = list(l.points)
|
||
|
|
||
|
assert len(points) == 1
|
||
|
assert points[0] == (1, 2)
|
||
|
assert len(l.attributes(1, 2)) == 0
|
||
|
|
||
|
def test_add_to_point_set_with_attributes():
|
||
|
attribute = Attribute("thing", 1)
|
||
|
|
||
|
l = PointSet()
|
||
|
l.add_point(1, 2, attrs=[attribute])
|
||
|
|
||
|
points = list(l.points)
|
||
|
attrs = l.attributes(1, 2)
|
||
|
|
||
|
assert len(points) == 1
|
||
|
assert points[0] == (1, 2)
|
||
|
assert len(l.attributes(1, 2)) == 1
|
||
|
|
||
|
def test_remove_point():
|
||
|
attribute = Attribute("thing", 1)
|
||
|
|
||
|
l = PointSet()
|
||
|
l.add_point(1, 2, attrs=[attribute])
|
||
|
|
||
|
l.remove_point(1, 2)
|
||
|
|
||
|
points = list(l.points)
|
||
|
|
||
|
assert len(points) == 0
|
||
|
|
||
|
with pytest.raises(KeyError):
|
||
|
# We expect a call to attributes on a removed
|
||
|
# point to raise a KeyError because it no
|
||
|
# longer exists in the point -> attribute_list
|
||
|
# dictionary.
|
||
|
l.attributes(1, 2)
|
||
|
|
||
|
def test_attributes_must_be_array_of_attributes():
|
||
|
with pytest.raises(ValueError):
|
||
|
l = PointSet()
|
||
|
l.add_point(1, 2, attrs=[1,2,3,4,5])
|