Skip to main content

tests/test_functions.py

1"""
2Tests for `funkycache.functions`.
3"""
5from pathlib import Path
6import subprocess
7import textwrap
10def test_canonical_name_varies_by_path(tmp_path: Path) -> None:
11 """
12 The canonical name of functions in the top-level of a script
13 varies by path.
15 For these functions, func.__module__ is __main__, so we need a way
16 to distinguish them to avoid cache collisions.
17 """
18 (tmp_path / "s1.py").write_text(
19 textwrap.dedent("""
20 from funkycache.functions import canonical_func_name
22 def greet(name: str) -> str:
23 return f"Hello {name}!"
25 print(canonical_func_name(greet))
26 """)
27 )
29 (tmp_path / "s2.py").write_text(
30 textwrap.dedent("""
31 from funkycache.functions import canonical_func_name
33 def greet(name: str) -> str:
34 return f"Hello {name}!"
36 print(canonical_func_name(greet))
37 """)
38 )
40 name1 = subprocess.check_output(["python3", (tmp_path / "s1.py")])
41 name2 = subprocess.check_output(["python3", (tmp_path / "s2.py")])
43 assert name1 != name2