-
Notifications
You must be signed in to change notification settings - Fork 37
/
basepmpgraphics.py
executable file
·92 lines (80 loc) · 2.98 KB
/
basepmpgraphics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
from __future__ import print_function
import unittest
import os
import sys
import pcmdi_metrics
import checkimage
class TestGraphics(unittest.TestCase):
def __init__(self, *args, **kwargs):
self.update = eval(os.environ.get("UPDATE_TESTS","False"))
self.geometry = {"width": 1200, "height": 600}
if 'geometry' in kwargs:
self.geometry = kwargs['geometry']
del kwargs['geometry']
self.bg = int(os.environ.get("VCS_BACKGROUND",1))
if 'bg' in kwargs:
self.bg = kwargs['bg']
del kwargs['bg']
super(TestGraphics, self).__init__(*args, **kwargs)
def setUp(self):
try:
import vcs
except:
raise RuntimeError(
"Sorry your python is not build with VCS support, cannot generate plots")
# This is for circleci that crashes for any mac bg=True
self.x=vcs.init(geometry=self.geometry,bg=self.bg)
self.x.setantialiasing(0)
if self.geometry is not None:
self.x.setbgoutputdimensions(self.geometry['width'],
self.geometry['height'],
units="pixels")
#if not self.bg:
# self.x.open()
self.orig_cwd = os.getcwd()
self.pngsdir = "tests_png"
os.makedirs(self.pngsdir, exist_ok=True)
self.basedir = os.path.join(os.path.dirname(__file__), "graphics")
def tearDown(self):
os.chdir(self.orig_cwd)
self.x.clear()
del(self.x)
# if png dir is empty (no failures) remove it
#if glob.glob(os.path.join(self.pngsdir,"*")) == []:
# shutil.rmtree(self.pngsdir)
def checkImage(self,fnm,src=None,threshold=checkimage.defaultThreshold,pngReady=False,pngPathSet=False):
if src is None:
src = os.path.join(self.basedir,os.path.basename(fnm))
if not pngPathSet:
fnm = os.path.join(self.pngsdir,fnm)
print("Test file :",fnm)
print("Source file:",src)
if not pngReady:
self.x.png(fnm,width=self.x.width, height=self.x.height, units="pixels")
ret = checkimage.check_result_image(fnm,src,threshold, update_baseline=self.update)
self.assertEqual(ret,0)
return ret
def loadJSON(self):
"""
# LOAD METRICS DICTIONARIES FROM JSON FILES FOR EACH VAR AND STORE AS A
# SINGLE DICTIONARY
"""
import glob
import json
json_files = glob.glob(
os.path.join(
os.path.dirname(__file__),
"graphics",
"json",
"v2.0",
"*.json"))
json_files += glob.glob(
os.path.join(
os.path.dirname(__file__),
"graphics",
"json",
"v1.0",
"*.json"))
print("JFILES:",json_files)
return pcmdi_metrics.pcmdi.io.JSONs(json_files)