summaryrefslogtreecommitdiff
path: root/tests/test_topology.py
blob: 0579d63e15804f0255c539701f66ab43c6e49e1c (plain)
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
55
"""Module for testing topology behaviour."""

import pytest

from blc2.topology import Fixture
from blc2.workspace import Workspace

def test_fixture_create(ws):
    """Test basic fixture creation."""
    f = Fixture(ws, id_=0, name="Test 1")
    assert f.id in ws.fixtures
    assert f.id == 0
    assert f.name == "Test 1"
    assert not f.channels

    with pytest.raises(ValueError):
        Fixture(ws, id_=0, name="Test 2")

    assert ws.fixtures[0] == f
    assert len(ws.fixtures) == 1

    f2 = Fixture(ws, name="Test 3")
    assert f2.id is not None
    assert ws.fixtures[f2.id] == f2
    assert len(ws.fixtures) == 2

    f3 = Fixture(ws, channel_count = 3)
    assert len(f3.channels) == 3

def test_fixture_channels(ws):
    """Test fixture channel manipulations."""
    f = Fixture(ws, channel_count=3)
    for i in range(3):
        f.channels[i].address = (0, i)
    channels = tuple(f.channels)

    with pytest.raises(ValueError):
        f.channel_count = -1
    assert len(f.channels) == 3

    ## Verify that the channels haven't been changed
    for a, b in zip(f.channels, channels):
        assert id(a) == id(b)
    
    f.channel_count = 2
    assert len(f.channels) == 2
    for a, b in zip(f.channels, channels[:2]):
        assert id(a) == id(b)
    
    f.channel_count = 3
    assert len(f.channels) == 3
    for a, b in zip(f.channels, channels[:2]):
        assert id(a) == id(b)

    assert id(f.channels[2]) != id(channels[2])