(batch_size, output_size, input_tensor, expected_batches, expected_value)
| 17 | ], |
| 18 | ) |
| 19 | def test_preprocessor(batch_size, output_size, input_tensor, expected_batches, expected_value): |
| 20 | processor = PreProcessor(output_size, batch_size) |
| 21 | |
| 22 | # Invalid input type |
| 23 | with pytest.raises(TypeError): |
| 24 | processor(42) |
| 25 | # 4D check |
| 26 | with pytest.raises(AssertionError): |
| 27 | processor(np.full((256, 128, 3), 255, dtype=np.uint8)) |
| 28 | with pytest.raises(TypeError): |
| 29 | processor(np.full((1, 256, 128, 3), 255, dtype=np.int32)) |
| 30 | # 3D check |
| 31 | with pytest.raises(AssertionError): |
| 32 | processor([np.full((3, 256, 128, 3), 255, dtype=np.uint8)]) |
| 33 | with pytest.raises(TypeError): |
| 34 | processor([np.full((256, 128, 3), 255, dtype=np.int32)]) |
| 35 | |
| 36 | with torch.no_grad(): |
| 37 | out = processor(input_tensor) |
| 38 | assert isinstance(out, list) and len(out) == expected_batches |
| 39 | assert all(isinstance(b, torch.Tensor) for b in out) |
| 40 | assert all(b.dtype == torch.float32 for b in out) |
| 41 | assert all(b.shape[-2:] == output_size for b in out) |
| 42 | assert all(torch.all(b == expected_value) for b in out) |
| 43 | assert len(repr(processor).split("\n")) == 4 |
nothing calls this directly
no test coverage detected