-
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.
Execute output code in integration tests (#68)
* add code validation to int tests * fix integration tests so output code is executable * update test reqs * use Pyjwt * up test timeout
- Loading branch information
1 parent
db09667
commit 90ce80b
Showing
17 changed files
with
103 additions
and
56 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
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 |