|
| 1 | +import unittest |
| 2 | + |
| 3 | +from pylabrobot.centrifuge import ( |
| 4 | + BucketHasPlateError, |
| 5 | + BucketNoPlateError, |
| 6 | + Centrifuge, |
| 7 | + CentrifugeDoorError, |
| 8 | + Loader, |
| 9 | + LoaderNoPlateError, |
| 10 | + NotAtBucketError, |
| 11 | +) |
| 12 | +from pylabrobot.centrifuge.backend import CentrifugeBackend, LoaderBackend |
| 13 | +from pylabrobot.resources import Coordinate, Cor_96_wellplate_360ul_Fb |
| 14 | + |
| 15 | + |
| 16 | +class CentrifugeLoaderResourceModelTests(unittest.IsolatedAsyncioTestCase): |
| 17 | + async def asyncSetUp(self): |
| 18 | + self.mock_centrifuge_backend = unittest.mock.MagicMock(spec=CentrifugeBackend) |
| 19 | + self.mock_loader_backend = unittest.mock.MagicMock(spec=LoaderBackend) |
| 20 | + self.centrifuge = Centrifuge(backend=self.mock_centrifuge_backend) |
| 21 | + self.loader = Loader( |
| 22 | + backend=self.mock_loader_backend, |
| 23 | + centrifuge=self.centrifuge, |
| 24 | + name="loader", |
| 25 | + size_x=1, |
| 26 | + size_y=1, |
| 27 | + size_z=1, |
| 28 | + child_location=Coordinate.zero(), |
| 29 | + ) |
| 30 | + self.plate = Cor_96_wellplate_360ul_Fb(name="plate") |
| 31 | + return await super().asyncSetUp() |
| 32 | + |
| 33 | + async def test_go_to_bucket(self): |
| 34 | + self.assertIsNone(self.centrifuge.at_bucket) |
| 35 | + await self.centrifuge.go_to_bucket1() |
| 36 | + self.assertEqual(self.centrifuge.at_bucket, self.centrifuge.bucket1) |
| 37 | + await self.centrifuge.go_to_bucket2() |
| 38 | + self.assertEqual(self.centrifuge.at_bucket, self.centrifuge.bucket2) |
| 39 | + |
| 40 | + async def test_load(self): |
| 41 | + await self.centrifuge.go_to_bucket1() |
| 42 | + await self.centrifuge.open_door() |
| 43 | + assert self.centrifuge._door_open |
| 44 | + assert self.centrifuge.door_open |
| 45 | + self.loader.assign_child_resource(self.plate) |
| 46 | + await self.loader.load() |
| 47 | + self.mock_loader_backend.load.assert_awaited_once() |
| 48 | + assert self.centrifuge.at_bucket is not None |
| 49 | + self.assertEqual(self.centrifuge.at_bucket.children[0], self.plate) |
| 50 | + self.assertEqual(self.loader.children, []) |
| 51 | + |
| 52 | + async def test_load_locked_door(self): |
| 53 | + self.loader.assign_child_resource(self.plate) |
| 54 | + with self.assertRaises(CentrifugeDoorError): |
| 55 | + await self.loader.load() |
| 56 | + self.mock_loader_backend.load.assert_not_awaited() |
| 57 | + |
| 58 | + async def test_load_no_plate(self): |
| 59 | + await self.centrifuge.go_to_bucket1() |
| 60 | + await self.centrifuge.open_door() |
| 61 | + with self.assertRaises(LoaderNoPlateError): |
| 62 | + await self.loader.load() |
| 63 | + self.mock_loader_backend.load.assert_not_awaited() |
| 64 | + |
| 65 | + async def test_load_bucket_has_plate(self): |
| 66 | + await self.centrifuge.go_to_bucket1() |
| 67 | + await self.centrifuge.open_door() |
| 68 | + assert self.centrifuge.at_bucket is not None |
| 69 | + self.centrifuge.at_bucket.assign_child_resource(self.plate) |
| 70 | + another_plate = Cor_96_wellplate_360ul_Fb(name="another_plate") |
| 71 | + self.loader.assign_child_resource(another_plate) |
| 72 | + with self.assertRaises(BucketHasPlateError): |
| 73 | + await self.loader.load() |
| 74 | + self.mock_loader_backend.load.assert_not_awaited() |
| 75 | + |
| 76 | + async def test_load_not_at_bucket(self): |
| 77 | + self.loader.assign_child_resource(self.plate) |
| 78 | + await self.centrifuge.open_door() |
| 79 | + with self.assertRaises(NotAtBucketError): |
| 80 | + await self.loader.load() |
| 81 | + self.mock_loader_backend.load.assert_not_awaited() |
| 82 | + |
| 83 | + async def test_unload(self): |
| 84 | + await self.centrifuge.go_to_bucket1() |
| 85 | + await self.centrifuge.open_door() |
| 86 | + assert self.centrifuge.at_bucket is not None |
| 87 | + self.centrifuge.at_bucket.assign_child_resource(self.plate) |
| 88 | + await self.loader.unload() |
| 89 | + self.mock_loader_backend.unload.assert_awaited_once() |
| 90 | + self.assertEqual(self.centrifuge.at_bucket.children, []) |
| 91 | + self.assertEqual(self.loader.children, [self.plate]) |
| 92 | + |
| 93 | + async def test_unload_locked_door(self): |
| 94 | + self.loader.assign_child_resource(self.plate) |
| 95 | + with self.assertRaises(CentrifugeDoorError): |
| 96 | + await self.loader.unload() |
| 97 | + self.mock_loader_backend.unload.assert_not_awaited() |
| 98 | + |
| 99 | + async def test_unload_bucket_has_no_plate(self): |
| 100 | + await self.centrifuge.go_to_bucket1() |
| 101 | + await self.centrifuge.open_door() |
| 102 | + with self.assertRaises(BucketNoPlateError): |
| 103 | + await self.loader.unload() |
| 104 | + self.mock_loader_backend.unload.assert_not_awaited() |
| 105 | + |
| 106 | + async def test_unload_loader_has_plate(self): |
| 107 | + await self.centrifuge.go_to_bucket1() |
| 108 | + await self.centrifuge.open_door() |
| 109 | + self.loader.assign_child_resource(self.plate) |
| 110 | + with self.assertRaises(BucketNoPlateError): |
| 111 | + await self.loader.unload() |
| 112 | + self.mock_loader_backend.unload.assert_not_awaited() |
| 113 | + |
| 114 | + async def test_unload_not_at_bucket(self): |
| 115 | + self.loader.assign_child_resource(self.plate) |
| 116 | + await self.centrifuge.open_door() |
| 117 | + with self.assertRaises(NotAtBucketError): |
| 118 | + await self.loader.unload() |
| 119 | + self.mock_loader_backend.unload.assert_not_awaited() |
0 commit comments