Skip to content

Commit 09c3ec8

Browse files
mgornyionelmc
authored andcommitted
Move test_proto benchmark to test_perf as well
Fixes #90 Signed-off-by: Michał Górny <mgorny@gentoo.org>
1 parent 3857696 commit 09c3ec8

File tree

2 files changed

+72
-73
lines changed

2 files changed

+72
-73
lines changed

tests/test_lazy_object_proxy.py

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from datetime import date
99
from datetime import datetime
1010
from decimal import Decimal
11-
from functools import partial
1211

1312
import pytest
1413

@@ -1810,78 +1809,6 @@ def test_garbage_collection_count(lop):
18101809
assert count == sys.getrefcount(obj)
18111810

18121811

1813-
empty = object()
1814-
1815-
1816-
@pytest.fixture(scope='module', params=['SimpleProxy', 'LocalsSimpleProxy', 'CachedPropertyProxy', 'LocalsCachedPropertyProxy'])
1817-
def prototype(request):
1818-
from lazy_object_proxy.simple import cached_property
1819-
1820-
name = request.param
1821-
1822-
if name == 'SimpleProxy':
1823-
1824-
class SimpleProxy:
1825-
def __init__(self, factory):
1826-
self.factory = factory
1827-
self.object = empty
1828-
1829-
def __str__(self):
1830-
if self.object is empty:
1831-
self.object = self.factory()
1832-
return str(self.object)
1833-
1834-
return SimpleProxy
1835-
elif name == 'CachedPropertyProxy':
1836-
1837-
class CachedPropertyProxy:
1838-
def __init__(self, factory):
1839-
self.factory = factory
1840-
1841-
@cached_property
1842-
def object(self):
1843-
return self.factory()
1844-
1845-
def __str__(self):
1846-
return str(self.object)
1847-
1848-
return CachedPropertyProxy
1849-
elif name == 'LocalsSimpleProxy':
1850-
1851-
class LocalsSimpleProxy:
1852-
def __init__(self, factory):
1853-
self.factory = factory
1854-
self.object = empty
1855-
1856-
def __str__(self, func=str):
1857-
if self.object is empty:
1858-
self.object = self.factory()
1859-
return func(self.object)
1860-
1861-
return LocalsSimpleProxy
1862-
elif name == 'LocalsCachedPropertyProxy':
1863-
1864-
class LocalsCachedPropertyProxy:
1865-
def __init__(self, factory):
1866-
self.factory = factory
1867-
1868-
@cached_property
1869-
def object(self):
1870-
return self.factory()
1871-
1872-
def __str__(self, func=str):
1873-
return func(self.object)
1874-
1875-
return LocalsCachedPropertyProxy
1876-
1877-
1878-
@pytest.mark.benchmark(group='prototypes')
1879-
def test_proto(benchmark, prototype):
1880-
obj = 'foobar'
1881-
proxied = prototype(lambda: obj)
1882-
assert benchmark(partial(str, proxied)) == obj
1883-
1884-
18851812
def test_subclassing_with_local_attr(lop):
18861813
class Foo:
18871814
pass

tests/test_perf.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,75 @@ def test_perf(benchmark, name, lop_loader):
99
obj = 'foobar'
1010
proxied = implementation.Proxy(lambda: obj)
1111
assert benchmark(partial(str, proxied)) == obj
12+
13+
14+
empty = object()
15+
16+
17+
@pytest.fixture(scope='module', params=['SimpleProxy', 'LocalsSimpleProxy', 'CachedPropertyProxy', 'LocalsCachedPropertyProxy'])
18+
def prototype(request):
19+
from lazy_object_proxy.simple import cached_property
20+
21+
name = request.param
22+
23+
if name == 'SimpleProxy':
24+
25+
class SimpleProxy:
26+
def __init__(self, factory):
27+
self.factory = factory
28+
self.object = empty
29+
30+
def __str__(self):
31+
if self.object is empty:
32+
self.object = self.factory()
33+
return str(self.object)
34+
35+
return SimpleProxy
36+
elif name == 'CachedPropertyProxy':
37+
38+
class CachedPropertyProxy:
39+
def __init__(self, factory):
40+
self.factory = factory
41+
42+
@cached_property
43+
def object(self):
44+
return self.factory()
45+
46+
def __str__(self):
47+
return str(self.object)
48+
49+
return CachedPropertyProxy
50+
elif name == 'LocalsSimpleProxy':
51+
52+
class LocalsSimpleProxy:
53+
def __init__(self, factory):
54+
self.factory = factory
55+
self.object = empty
56+
57+
def __str__(self, func=str):
58+
if self.object is empty:
59+
self.object = self.factory()
60+
return func(self.object)
61+
62+
return LocalsSimpleProxy
63+
elif name == 'LocalsCachedPropertyProxy':
64+
65+
class LocalsCachedPropertyProxy:
66+
def __init__(self, factory):
67+
self.factory = factory
68+
69+
@cached_property
70+
def object(self):
71+
return self.factory()
72+
73+
def __str__(self, func=str):
74+
return func(self.object)
75+
76+
return LocalsCachedPropertyProxy
77+
78+
79+
@pytest.mark.benchmark(group='prototypes')
80+
def test_proto(benchmark, prototype):
81+
obj = 'foobar'
82+
proxied = prototype(lambda: obj)
83+
assert benchmark(partial(str, proxied)) == obj

0 commit comments

Comments
 (0)