Merge pull request #904 from j9ac9k/take-screenshots

Take screenshots + Show Resolution
This commit is contained in:
Luke Campagnola 2019-05-29 13:12:12 -07:00 committed by GitHub
commit 52fef555ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 9 deletions

View File

@ -135,6 +135,8 @@ if __name__ == '__main__':
lib = 'PyQt4'
elif '--pyqt5' in args:
lib = 'PyQt5'
elif '--pyside2' in args:
lib = 'PySide2'
else:
lib = ''

View File

@ -31,7 +31,6 @@ def init_viewbox():
g = pg.GridItem()
vb.addItem(g)
app.processEvents()
def test_ViewBox():

View File

@ -191,6 +191,7 @@ def assertImageApproved(image, standardFile, message=None, **kwargs):
if os.getenv('PYQTGRAPH_AUDIT_ALL') == '1':
raise Exception("Image test passed, but auditing due to PYQTGRAPH_AUDIT_ALL evnironment variable.")
except Exception:
if stdFileName in gitStatus(dataPath):
print("\n\nWARNING: unit test failed against modified standard "
"image %s.\nTo revert this file, run `cd %s; git checkout "
@ -210,6 +211,9 @@ def assertImageApproved(image, standardFile, message=None, **kwargs):
"PYQTGRAPH_AUDIT=1 to add this image." % stdFileName)
else:
if os.getenv('TRAVIS') is not None:
saveFailedTest(image, stdImage, standardFile, upload=True)
elif os.getenv('AZURE') is not None:
standardFile = r"artifacts/" + standardFile
saveFailedTest(image, stdImage, standardFile)
print(graphstate)
raise
@ -281,14 +285,13 @@ def assertImageMatch(im1, im2, minCorr=None, pxThreshold=50.,
assert corr >= minCorr
def saveFailedTest(data, expect, filename):
def saveFailedTest(data, expect, filename, upload=False):
"""Upload failed test images to web server to allow CI test debugging.
"""
commit = runSubprocess(['git', 'rev-parse', 'HEAD'])
name = filename.split('/')
name = filename.split(os.path.sep)
name.insert(-1, commit.strip())
filename = '/'.join(name)
host = 'data.pyqtgraph.org'
filename = os.path.sep.join(name)
# concatenate data, expect, and diff into a single image
ds = data.shape
@ -306,15 +309,25 @@ def saveFailedTest(data, expect, filename):
img[2:2+diff.shape[0], -diff.shape[1]-2:-2] = diff
png = makePng(img)
directory = os.path.dirname(filename)
if not os.path.isdir(directory):
os.makedirs(directory)
with open(filename + ".png", "wb") as png_file:
png_file.write(png)
print("\nImage comparison failed. Test result: %s %s Expected result: "
"%s %s" % (data.shape, data.dtype, expect.shape, expect.dtype))
if upload:
uploadFailedTest(filename, png)
def uploadFailedTest(filename, png):
host = 'data.pyqtgraph.org'
conn = httplib.HTTPConnection(host)
req = urllib.urlencode({'name': filename,
'data': base64.b64encode(png)})
conn.request('POST', '/upload.py', req)
response = conn.getresponse().read()
conn.close()
print("\nImage comparison failed. Test result: %s %s Expected result: "
"%s %s" % (data.shape, data.dtype, expect.shape, expect.dtype))
print("Uploaded to: \nhttp://%s/data/%s" % (host, filename))
if not response.startswith(b'OK'):
print("WARNING: Error uploading data to %s" % host)
@ -495,7 +508,7 @@ def getTestDataRepo():
if not os.path.isdir(parentPath):
os.makedirs(parentPath)
if os.getenv('TRAVIS') is not None:
if os.getenv('TRAVIS') is not None or os.getenv('AZURE') is not None:
# Create a shallow clone of the test-data repository (to avoid
# downloading more data than is necessary)
os.makedirs(dataPath)

View File

@ -15,10 +15,15 @@ elif '--pyqt4' in args:
elif '--pyqt5' in args:
args.remove('--pyqt5')
import PyQt5
elif '--pyside2' in args:
args.remove('--pyside2')
import PySide2
import pyqtgraph as pg
pg.systemInfo()
qApp = pg.mkQApp()
desktop = qApp.desktop().screenGeometry()
print("\n\nDesktop Resolution: {} x {}\n\n".format(desktop.width(), desktop.height()))
pytest.main(args)