tests
unit_tests
test__compat.py
Go to the documentation of this file.
1
from
typing
import
List, Tuple
2
3
from
genmypy._compat
import
lru_cache
4
from
genmypy.stub_element
import
ImportsElement
5
6
7
def
test_lru_cache
():
8
# type: () -> None
9
called = []
# type: List[Tuple[str, str, ImportsElement]]
10
11
@
lru_cache
()
12
def
func(module, name, imports):
13
# type: (str, str, ImportsElement) -> str
14
called.append((module, name, imports))
15
return
"from {} import {}"
.format(module, name)
16
17
session1 =
ImportsElement
()
18
assert
func(
"typing"
,
"List"
, session1) ==
"from typing import List"
19
assert
called == [(
"typing"
,
"List"
, session1)]
20
21
assert
func(
"typing"
,
"List"
, session1) ==
"from typing import List"
22
assert
called == [(
"typing"
,
"List"
, session1)]
23
24
assert
func(
"typing"
,
"Optional"
, session1) ==
"from typing import Optional"
25
assert
called == [(
"typing"
,
"List"
, session1), (
"typing"
,
"Optional"
, session1)]
26
27
# Ensure that lru_cache doesn't care the contents of a reference object
28
session1.add_system_module(
"typing"
,
None
)
29
assert
func(
"typing"
,
"Optional"
, session1) ==
"from typing import Optional"
30
assert
called == [(
"typing"
,
"List"
, session1), (
"typing"
,
"Optional"
, session1)]
31
32
session2 =
ImportsElement
()
33
assert
func(
"typing"
,
"Optional"
, session2) ==
"from typing import Optional"
34
assert
called == [
35
(
"typing"
,
"List"
, session1),
36
(
"typing"
,
"Optional"
, session1),
37
(
"typing"
,
"Optional"
, session2),
38
]
genmypy.stub_element.ImportsElement
Definition:
stub_element.py:62
genmypy.stub_element
Definition:
stub_element.py:1
genmypy._compat.lru_cache
def lru_cache()
Definition:
_compat.py:14
genmypy._compat
Definition:
_compat.py:1
test__compat.test_lru_cache
def test_lru_cache()
Definition:
test__compat.py:7
genmypy
Author(s): Yuki Igarashi, Tamaki Nishino
autogenerated on Mon Apr 10 2023 02:40:49