mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Made env generation polymorphic
This commit is contained in:
parent
5ca8f4ffa8
commit
47bad120e4
2 changed files with 53 additions and 20 deletions
29
tests/util_test.py
Normal file
29
tests/util_test.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
import pytest
|
||||
import time
|
||||
|
||||
from pre_commit.util import cached_property
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def class_with_cached_property():
|
||||
class Foo(object):
|
||||
@cached_property
|
||||
def foo(self):
|
||||
return "Foo" + str(time.time())
|
||||
|
||||
return Foo
|
||||
|
||||
|
||||
def test_cached_property(class_with_cached_property):
|
||||
instance = class_with_cached_property()
|
||||
val = instance.foo
|
||||
val2 = instance.foo
|
||||
assert val is val2
|
||||
|
||||
|
||||
def test_unbound_cached_property(class_with_cached_property):
|
||||
# Make sure we don't blow up when accessing the property unbound
|
||||
prop = class_with_cached_property.foo
|
||||
assert isinstance(prop, cached_property)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue