Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F29732369
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
Ladsgroup
Jul 10 2019, 5:02 PM
2019-07-10 17:02:42 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
import os
import sys
import re
import subprocess
from subprocess import PIPE
def find_test_files(path):
files = []
for r, d, f in os.walk(path):
for file_name in f:
if file_name.endswith('Test.php'):
files.append(os.path.join(r, file_name))
return files
def move_things(path, sep):
if len(sys.argv) > 2:
d = sys.argv[2]
else:
d = sys.argv[1]
new_path = '{0}{1}/{2}/{3}'.format(path.split(d)[0], d, sep, path.split(d)[1])
new_path = new_path.replace('//','/')
res = subprocess.run(["mkdir", "-p", '/'.join(new_path.split('/')[:-1])], stdout=PIPE, stderr=PIPE)
if res.returncode != 0:
print(res.stdout.decode('utf-8'))
sys.exit()
res = subprocess.run(["mv", path, new_path], stdout=PIPE, stderr=PIPE)
if res.returncode != 0:
print(res.stdout.decode('utf-8'))
sys.exit()
def check_file(path):
with open(path, 'r') as f:
content = f.read()
old_content = content
search_result = re.findall(r'(\nclass (\S+) extends \\?MediaWikiTestCase)', content)
if not search_result and 'PHPUnit\Framework\TestCase' not in content:
return
with open(path, 'w') as f:
new_content = content.replace('MediaWikiTestCase', 'MediaWikiUnitTestCase')
new_content = new_content.replace('PHPUnit\Framework\TestCase', 'MediaWikiUnitTestCase')
new_content = re.sub(r'\n\t*?use \\?(PHPUnit4And6Compat|MediaWikiCoversValidator)\;', '', new_content)
new_content = re.sub(r' extends (\\?)TestCase', r' extends \1MediaWikiUnitTestCase', new_content)
f.write(new_content)
res = subprocess.run(["composer", "phpunit:unit", path], stdout=PIPE, stderr=PIPE)
if res.returncode != 0 or 'markTestSkipped' in content:
try:
errors = re.findall(r'Tests\: (\d+)(?:.+), Assertions\: (?:\d+)(?:.+?), (.+\: \d+)', res.stdout.decode('utf-8'))
except:
errors = []
if errors:
errs = sum([int(i) for i in re.findall(r' (\d+)', errors[0][1])])
print(errors[0][0] + ',' + str(errs) +','+ path)
#print(res.stdout.decode('utf-8'))
print('It did not work :((')
with open(path, 'w') as f:
f.write(old_content)
move_things(path, 'integration')
else:
print('It worked, moving')
move_things(path, 'unit')
for f in find_test_files(sys.argv[1]):
#print('Checking ' + f)
check_file(f)
#break
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7718188
Default Alt Text
raw.txt (2 KB)
Attached To
Mode
P8702 Python script to fix unit tests
Attached
Detach File
Event Timeline
Log In to Comment