File: test_init.py

package info (click to toggle)
lutris 0.5.22-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 9,128 kB
  • sloc: python: 43,973; xml: 231; makefile: 82; sh: 30
file content (32 lines) | stat: -rw-r--r-- 755 bytes parent folder | download
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
28
29
30
31
32
import unittest

from lutris.util import cache_single


class TestCacheSingle(unittest.TestCase):
    def test_no_args(self):
        call_count = 0

        @cache_single
        def no_args():
            nonlocal call_count
            call_count += 1
            return call_count

        self.assertEqual(no_args(), 1)
        self.assertEqual(no_args(), 1)

        no_args.cache_clear()
        self.assertEqual(no_args(), 2)
        self.assertEqual(no_args(), 2)

    def test_with_args(self):
        @cache_single
        def with_args(return_value):
            return return_value

        self.assertEqual(with_args(1), 1)
        self.assertEqual(with_args(2), 2)

        with_args.cache_clear()
        self.assertEqual(with_args(3), 3)