mirror of
https://github.com/quantum5/optimize-later.git
synced 2025-04-24 12:32:04 -04:00
Correctly handle names when used as decorator.
This commit is contained in:
parent
62d312338d
commit
c566533ef7
|
@ -134,6 +134,7 @@ class optimize_later(with_metaclass(NoArgDecoratorMeta)):
|
||||||
global_callback(report)
|
global_callback(report)
|
||||||
|
|
||||||
def __call__(self, function):
|
def __call__(self, function):
|
||||||
|
if self._default_name:
|
||||||
self.name = '%s:%s' % (function.__module__, function.__name__)
|
self.name = '%s:%s' % (function.__module__, function.__name__)
|
||||||
|
|
||||||
@wraps(function)
|
@wraps(function)
|
||||||
|
|
|
@ -182,3 +182,26 @@ class OptimizeLaterTest(TestCase):
|
||||||
self.assertEqual(len(reports), 10)
|
self.assertEqual(len(reports), 10)
|
||||||
for report in reports:
|
for report in reports:
|
||||||
self.assertReport(report)
|
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