diff options
author | Ben Connors <benconnors@outlook.com> | 2019-09-26 19:08:01 -0400 |
---|---|---|
committer | Ben Connors <benconnors@outlook.com> | 2019-09-26 19:08:01 -0400 |
commit | cefc580a2f38f14c0245c9d6a5acbaa67feaf8d4 (patch) | |
tree | a055ef1931c4f8da009aa9f61f4640a37b25e4fe /tests/test_topology.py | |
parent | 9bd3390071be3db8c366d44e161e828c8263179b (diff) |
Various fixes; start implementing tests
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]) |