forked from beeware/voc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented simple closures, which also enables simple non-argument d…
…ecorators.
- Loading branch information
1 parent
3541618
commit 2b40540
Showing
8 changed files
with
202 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from unittest import expectedFailure | ||
|
||
from ..utils import TranspileTestCase | ||
|
||
|
||
class DecoratorTests(TranspileTestCase): | ||
def test_simple_decorator(self): | ||
self.assertCodeExecution(""" | ||
def thing(fn): | ||
def _dec(value): | ||
print("Start decoration.") | ||
result = fn(value) | ||
print("End decoration.") | ||
return result * 42 | ||
return _dec | ||
@thing | ||
def calculate(value): | ||
print("Do a calculation") | ||
return 37 * value | ||
print("Decorated result is", calculate(5)) | ||
print("Done.") | ||
""") | ||
|
||
@expectedFailure | ||
def test_decorator_with_argument(self): | ||
self.assertCodeExecution(""" | ||
def thing(multiplier): | ||
def _dec(fn): | ||
def _fn(value): | ||
print("Start decoration.") | ||
result = fn(value) | ||
print("End decoration.") | ||
return result * multiplier | ||
return _fn | ||
return _dec | ||
@thing(42) | ||
def calculate(value): | ||
print("Do a calculation") | ||
return 37 * value | ||
print("Decorated result is", calculate(5)) | ||
print("Done.") | ||
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.