-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix integration tests so output code is executable
- Loading branch information
1 parent
62e6e0b
commit 80b86e6
Showing
16 changed files
with
87 additions
and
64 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
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ pytest==7.4.* | |
pytest-cov~=4.1.0 | ||
pytest-mock~=3.11.1 | ||
pytest-xdist==3.* | ||
security~=1.0.1 | ||
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 |
---|---|---|
@@ -1,20 +1,30 @@ | ||
import importlib.util | ||
import tempfile | ||
|
||
def validate_code(*, path=None, code=None): | ||
|
||
def execute_code(*, path=None, code=None, allowed_exceptions=None): | ||
""" | ||
Ensure that code written in `path` or in `code` str is importable. | ||
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." | ||
assert (path is None) != ( | ||
code is None | ||
), "Must pass either path to code or code as a str." | ||
|
||
if path: | ||
_try_code_import(path) | ||
_run_code(path, allowed_exceptions) | ||
return | ||
with tempfile.NamedTemporaryFile(suffix=".py", mode='w+t') as temp: | ||
with tempfile.NamedTemporaryFile(suffix=".py", mode="w+t") as temp: | ||
temp.write(code) | ||
_try_code_import(temp.name) | ||
_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 () | ||
|
||
def _try_code_import(path): | ||
spec = importlib.util.spec_from_file_location("output_code", path) | ||
module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module) | ||
try: | ||
spec.loader.exec_module(module) | ||
except allowed_exceptions: | ||
pass |