-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Execute output code in integration tests #68
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
coverage==7.3.* | ||
GitPython<4 | ||
Jinja2~=3.1.2 | ||
lxml~=4.9.3 | ||
mock==5.1.* | ||
pre-commit<4 | ||
Pyjwt~=2.8.0 | ||
pytest==7.4.* | ||
pytest-cov~=4.1.0 | ||
pytest-mock~=3.11.1 | ||
pytest-xdist==3.* | ||
security~=1.2.0 | ||
types-mock==5.1.* |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import requests | ||
|
||
requests.get("www.google.com") | ||
requests.get("https://www.google.com") | ||
var = "hello" |
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 |
---|---|---|
@@ -1,22 +1,23 @@ | ||
#!/bin/env python | ||
from a import a2 | ||
from abc import ABCMeta | ||
|
||
# comment b1 | ||
# comment b2 | ||
import b | ||
# comment builtins1 | ||
# comment builtins2 | ||
import builtins | ||
|
||
# comment a | ||
from a import a1 | ||
from abc import ABC | ||
|
||
# comment b3 | ||
import b, d | ||
# comment builtins3 | ||
import builtins, datetime | ||
|
||
# comment b4 | ||
# comment b5 | ||
import b | ||
# comment builtins4 | ||
# comment builtins5 | ||
import builtins | ||
import collections | ||
|
||
a1 | ||
a2 | ||
b | ||
c | ||
d | ||
ABC | ||
ABCMeta | ||
builtins | ||
collections | ||
datetime |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import a | ||
from b import c, d | ||
import abc | ||
from builtins import complex, dict | ||
|
||
a | ||
c | ||
abc | ||
complex |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import requests | ||
|
||
requests.get("www.google.com", verify=False) | ||
requests.post("https/some-api/", json={"id": 1234, "price": 18}, verify=False) | ||
requests.get("https://www.google.com", verify=False) | ||
requests.post("https://some-api/", json={"id": 1234, "price": 18}, verify=False) | ||
var = "hello" |
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
x = foo() | ||
x = sum([1, 2]) | ||
if x is not None: | ||
print(x) | ||
|
||
y = bar() | ||
y = max([1, 2]) | ||
if y: | ||
print(y) | ||
|
||
z = baz() | ||
z = min([1, 2]) | ||
print(z) | ||
|
||
|
||
def whatever(): | ||
b = biz() | ||
b = int("2") | ||
if b == 10: | ||
print(b) |
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,30 @@ | ||
import importlib.util | ||
import tempfile | ||
|
||
|
||
def execute_code(*, path=None, code=None, allowed_exceptions=None): | ||
""" | ||
Ensure that code written in `path` or in `code` str is executable. | ||
""" | ||
assert (path is None) != ( | ||
code is None | ||
), "Must pass either path to code or code as a str." | ||
|
||
if path: | ||
_run_code(path, allowed_exceptions) | ||
return | ||
with tempfile.NamedTemporaryFile(suffix=".py", mode="w+t") as temp: | ||
temp.write(code) | ||
_run_code(temp.name, allowed_exceptions) | ||
|
||
|
||
def _run_code(path, allowed_exceptions=None): | ||
"""Execute the code in `path` in its own namespace.""" | ||
allowed_exceptions = allowed_exceptions or () | ||
|
||
spec = importlib.util.spec_from_file_location("output_code", path) | ||
module = importlib.util.module_from_spec(spec) | ||
try: | ||
spec.loader.exec_module(module) | ||
except allowed_exceptions: | ||
pass |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super cool.