File: test_cached_property.py

package info (click to toggle)
graphql-core 3.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,384 kB
  • sloc: python: 45,812; makefile: 26; sh: 13
file content (27 lines) | stat: -rw-r--r-- 697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from graphql.pyutils import cached_property


def describe_cached_property():
    def works_like_a_normal_property():
        class TestClass:
            @cached_property
            def value(self):
                return 42

        assert TestClass().value == 42

    def caches_the_value():
        class TestClass:
            evaluations = 0

            @cached_property
            def value(self):
                self.__class__.evaluations += 1
                return 42

        obj = TestClass()
        assert TestClass.evaluations == 0
        assert obj.value == 42
        assert TestClass.evaluations == 1
        assert obj.value == 42
        assert TestClass.evaluations == 1