Passed
Push — master ( 3a869f...6c7a18 )
by Fernando
01:18
created

tests.transforms.preprocessing.test_copy_affine   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 22
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestCopyAffine.test_missing_reference() 0 4 2
A TestCopyAffine.test_wrong_target_type() 0 3 2
A TestCopyAffine.test_same_affine() 0 10 1
1
import torch
2
3
import torchio as tio
4
from ...utils import TorchioTestCase
5
6
7
class TestCopyAffine(TorchioTestCase):
8
    """Tests for `CopyAffine`."""
9
10
    def test_missing_reference(self):
11
        transform = tio.CopyAffine(target='missing')
12
        with self.assertRaises(RuntimeError):
13
            transform(self.sample_subject)
14
15
    def test_wrong_target_type(self):
16
        with self.assertRaises(ValueError):
17
            tio.CopyAffine(target=[1])
18
19
    def test_same_affine(self):
20
        image = tio.ScalarImage(tensor=torch.rand(2, 2, 2, 2))
21
        mask = tio.LabelMap(tensor=torch.rand(2, 2, 2, 2))
22
        mask.affine *= 1.1
23
        subject = tio.Subject(t1=image, mask=mask)
24
        transform = tio.CopyAffine('t1')
25
        transformed = transform(subject)
26
        self.assertTensorEqual(
27
            transformed['t1'].affine,
28
            transformed['mask'].affine,
29
        )
30