mirror of
https://github.com/quantum5/optimize-later.git
synced 2025-04-24 04:21:58 -04:00
Correctly handle names when used as decorator.
This commit is contained in:
parent
62d312338d
commit
c566533ef7
|
@ -134,7 +134,8 @@ class optimize_later(with_metaclass(NoArgDecoratorMeta)):
|
|||
global_callback(report)
|
||||
|
||||
def __call__(self, function):
|
||||
self.name = '%s:%s' % (function.__module__, function.__name__)
|
||||
if self._default_name:
|
||||
self.name = '%s:%s' % (function.__module__, function.__name__)
|
||||
|
||||
@wraps(function)
|
||||
def wrapped(*args, **kwargs):
|
||||
|
|
|
@ -182,3 +182,26 @@ class OptimizeLaterTest(TestCase):
|
|||
self.assertEqual(len(reports), 10)
|
||||
for report in reports:
|
||||
self.assertReport(report)
|
||||
|
||||
def test_decorator_with_args(self):
|
||||
reports = []
|
||||
config.register_callback(reports.append)
|
||||
|
||||
@optimize_later(float('inf'))
|
||||
def function():
|
||||
pass
|
||||
|
||||
self.assertEqual(len(reports), 0)
|
||||
|
||||
def test_decorator_custom_name(self):
|
||||
reports = []
|
||||
config.register_callback(reports.append)
|
||||
|
||||
@optimize_later('custom_name')
|
||||
def function():
|
||||
pass
|
||||
function()
|
||||
|
||||
self.assertEqual(len(reports), 1)
|
||||
self.assertReport(reports[0])
|
||||
self.assertEqual(reports[0].name, 'custom_name')
|
||||
|
|
Loading…
Reference in a new issue