File: test_lazy_initializer.py

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (27 lines) | stat: -rw-r--r-- 528 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
import pytest

from freeorion_tools.lazy_initializer import InitializerLock


@pytest.fixture
def lock():
    lock = InitializerLock("test")
    return lock


def test_function_return_value_when_unlocked(lock):
    @lock
    def foo():
        return 1

    lock.unlock()
    assert foo() == 1


def test_function_call_raise_error_when_locked(lock):
    @lock
    def foo():
        return 1

    with pytest.raises(ValueError, match=r"Call of 'foo' is forbidden before InitializerLock\('test'\) is initialized"):
        foo()