# -*- coding: utf-8 -*-
# Copyright (c) 2022 Satpy developers
# This file is part of satpy.
# satpy is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# satpy is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Test backports and compatibility fixes."""
from satpy._compat import CachedPropertyBackport
[docs]class ClassWithCachedProperty: # noqa
def __init__(self, x): # noqa
self.x = x
def property(self): # noqa
return 2 * self.x
"""Test cached property backport."""
c = ClassWithCachedProperty(1)
assert c.property == 2
"""Test that cached property backport releases memory."""
c1 = ClassWithCachedProperty(2)
instances = [
obj for obj in gc.get_objects()
if isinstance(obj, ClassWithCachedProperty)
assert len(instances) == 0