Passed
Pull Request — master (#353)
by Fernando
01:16
created

tests.transforms.test_invertibility   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B TestInvertibility.test_all_random_transforms() 0 25 6
1
import warnings
2
3
from ..utils import TorchioTestCase
4
5
6
class TestInvertibility(TorchioTestCase):
7
8
    def test_all_random_transforms(self):
9
        transform = self.get_large_composed_transform()
10
        # Remove RandomLabelsToImage as it will add a new image to the subject
11
        for t in transform.transforms:
12
            if t.name == 'RandomLabelsToImage':
13
                transform.transforms.remove(t)
14
                break
15
        # Ignore elastic deformation and gamma warnings during execution
16
        with warnings.catch_warnings():
17
            warnings.simplefilter('ignore', (RuntimeWarning, UserWarning))
18
            transformed = transform(self.sample_subject)
19
        # Ignore some transforms not invertible
20
        with warnings.catch_warnings():
21
            warnings.simplefilter('ignore', UserWarning)
22
            inverting_transform = transformed.get_inverse_transform()
23
        with warnings.catch_warnings():
24
            warnings.simplefilter('ignore', (RuntimeWarning, UserWarning))
25
            transformed_back = inverting_transform(transformed)
26
        self.assertEqual(
27
            transformed.t1.shape,
28
            transformed_back.t1.shape,
29
        )
30
        self.assertTensorEqual(
31
            transformed.label.affine,
32
            transformed_back.label.affine,
33
        )
34