Code Duplication    Length = 14-15 lines in 2 locations

tests/transforms/test_custom_image_subclass_fix.py 1 location

@@ 8-22 (lines=15) @@
5
import torchio as tio
6
7
8
class HistoryScalarImage(tio.ScalarImage):
9
    """Custom ScalarImage subclass that stores history metadata."""
10
11
    def __init__(self, tensor, affine, history, **kwargs):
12
        super().__init__(tensor=tensor, affine=affine, **kwargs)
13
        self.history = history
14
15
    def new_like(self, tensor, affine=None):
16
        """Override new_like to preserve history attribute."""
17
        return type(self)(
18
            tensor=tensor,
19
            affine=affine if affine is not None else self.affine,
20
            history=self.history,  # Preserve custom attribute
21
            check_nans=self.check_nans,
22
            reader=self.reader,
23
        )
24
25

tests/transforms/test_custom_image_subclass.py 1 location

@@ 8-21 (lines=14) @@
5
import torchio as tio
6
7
8
class HistoryImage(tio.ScalarImage):
9
    """Test custom Image with required parameter."""
10
11
    def __init__(self, tensor, affine, history, **kwargs):
12
        super().__init__(tensor=tensor, affine=affine, **kwargs)
13
        self.history = history
14
15
    def new_like(self, tensor, affine=None):
16
        return type(self)(
17
            tensor=tensor,
18
            affine=affine if affine is not None else self.affine,
19
            history=self.history,
20
            check_nans=self.check_nans,
21
            reader=self.reader,
22
        )
23
24