-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
6 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,31 @@ | ||
#!/bin/bash | ||
# $1: repo name | ||
# $2: test directory in repository root | ||
|
||
[ -d venvs ] || mkdir venvs | ||
[ -d under_test ] || mkdir under_test | ||
|
||
python -m pip install --user virtualenv | ||
|
||
# Create virtual environtment | ||
venv=$1_tmp_env | ||
virtualenv --python 3.9.0 venvs/$venv | ||
source venvs/$venv/bin/activate | ||
|
||
# Install requirements for package under test | ||
cp -r ./test/PythonRepos/$1 ./under_test/$1_tmp | ||
cp filter_tests.py ./under_test/$1_tmp | ||
cd ./under_test/$1_tmp | ||
|
||
pip install pytest | ||
|
||
[ -f requirements.txt ] && pip install -r requirements.txt | ||
|
||
# Install package | ||
[ -f myInstall.sh ] && bash ./myInstall.sh || pip install . | ||
# Run tests | ||
python filter_tests.py $(pwd) $2 | ||
|
||
cd ../.. | ||
source deactivate | ||
rm -rf venvs/$venv |
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,41 @@ | ||
import linecache | ||
import sys | ||
import pytest | ||
|
||
bad_tests = set() | ||
results = [] | ||
print(' '.join(sys.argv)) | ||
test_dir = sys.argv[2] | ||
|
||
def find_testfile(frame, package_test_dir): | ||
while frame is not None: | ||
if package_test_dir in frame.f_code.co_filename: | ||
ln = frame.f_lineno | ||
current_line = linecache.getline(frame.f_code.co_filename, ln) | ||
current_indent = len(current_line) - len(current_line.lstrip()) | ||
while ln > 0: | ||
ln -= 1 | ||
this_line = linecache.getline(frame.f_code.co_filename, ln) | ||
if len(this_line) - len(this_line.lstrip()) < current_indent and this_line.lstrip().startswith('def '): | ||
bad_tests.add((frame.f_code.co_filename + '::' + linecache.getline(frame.f_code.co_filename, ln).strip()[4:].split('(')[0]).split('/')[-1]) | ||
break | ||
frame = frame.f_back | ||
|
||
def uses_stack(frame, event, arg=None): | ||
code = frame.f_code | ||
access_path_names = code.co_names | ||
file_name = code.co_filename | ||
|
||
if '.'.join(access_path_names) in ['sys._getframe', 'sys.exc_info', 'inspect.stack']: | ||
find_testfile(frame, test_dir) | ||
elif file_name.endswith('inspect.py') and any(map(lambda x: x in linecache.getline(file_name, frame.f_lineno), ['trace', 'stack', 'currentframe', 'getinnerframes', 'getouterframes', 'getlineno', 'getframeinfo'])): | ||
find_testfile(frame, test_dir) | ||
return uses_stack | ||
|
||
sys.settrace(uses_stack) | ||
|
||
pytest.main([sys.argv[1] + '/' + test_dir]) | ||
|
||
print('\n'.join(bad_tests)) | ||
with open('filtered.txt', 'w') as f: | ||
f.write('\n'.join(bad_tests)) |
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