@@ 1927-1944 (lines=18) @@ | ||
1924 | assert not called |
|
1925 | ||
1926 | ||
1927 | def test_subclassing_dynamic_with_local_attr(lazy_object_proxy): |
|
1928 | if lazy_object_proxy.kind == 'cext': |
|
1929 | pytest.skip("Not possible.") |
|
1930 | ||
1931 | class Foo: |
|
1932 | pass |
|
1933 | ||
1934 | called = [] |
|
1935 | ||
1936 | class LazyProxy(lazy_object_proxy.Proxy): |
|
1937 | def __init__(self, func, **lazy_attr): |
|
1938 | super(LazyProxy, self).__init__(func) |
|
1939 | for attr, val in lazy_attr.items(): |
|
1940 | object.__setattr__(self, attr, val) |
|
1941 | ||
1942 | proxy = LazyProxy(lambda: called.append(1) or Foo(), name='bar') |
|
1943 | assert proxy.name == 'bar' |
|
1944 | assert not called |
|
1945 | ||
1946 | ||
@@ 1909-1924 (lines=16) @@ | ||
1906 | assert benchmark(partial(str, proxied)) == obj |
|
1907 | ||
1908 | ||
1909 | def test_subclassing_with_local_attr(lazy_object_proxy): |
|
1910 | class Foo: |
|
1911 | pass |
|
1912 | called = [] |
|
1913 | ||
1914 | class LazyProxy(lazy_object_proxy.Proxy): |
|
1915 | name = None |
|
1916 | ||
1917 | def __init__(self, func, **lazy_attr): |
|
1918 | super(LazyProxy, self).__init__(func) |
|
1919 | for attr, val in lazy_attr.items(): |
|
1920 | setattr(self, attr, val) |
|
1921 | ||
1922 | proxy = LazyProxy(lambda: called.append(1) or Foo(), name='bar') |
|
1923 | assert proxy.name == 'bar' |
|
1924 | assert not called |
|
1925 | ||
1926 | ||
1927 | def test_subclassing_dynamic_with_local_attr(lazy_object_proxy): |