diff options
Diffstat (limited to 'tests/test_topology.py')
-rw-r--r-- | tests/test_topology.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/test_topology.py b/tests/test_topology.py new file mode 100644 index 0000000..0579d63 --- /dev/null +++ b/tests/test_topology.py @@ -0,0 +1,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]) |