-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #458 from nucleic/py310-fixes
core: prune return None from inserted Python blocks
- Loading branch information
Showing
6 changed files
with
108 additions
and
17 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#------------------------------------------------------------------------------ | ||
# Copyright (c) 2021, Nucleic Development Team. | ||
# | ||
# Distributed under the terms of the Modified BSD License. | ||
# | ||
# The full license is in the file COPYING.txt, distributed with this software. | ||
#------------------------------------------------------------------------------ | ||
"""Test for the code generator.""" | ||
import ast | ||
import pytest | ||
|
||
from enaml.core.code_generator import CodeGenerator | ||
|
||
|
||
# Since we cannot have a return outside a function I am not sure we can ever | ||
# encounter a non-implicit return opcode. | ||
@pytest.mark.parametrize("source, return_on_lines", [ | ||
("pass", []), | ||
("for i in range(10):\n i", []), | ||
("with open(f) as f:\n print(f.readlines())", []), | ||
]) | ||
def test_python_block_insertion(source, return_on_lines): | ||
cg = CodeGenerator() | ||
cg.insert_python_block(ast.parse(source)) | ||
for i in cg.code_ops: | ||
if getattr(i, "name", "") == "RETURN_VALUE": | ||
assert i.lineno in return_on_lines |