Browse code

Make test script more robust.

Jose Fonseca authored on 18/10/2015 20:37:04
Showing 1 changed files

  • test.py index 480b0b5..e453184 100755
... ...
@@ -42,10 +42,25 @@ class TestDotWidget(DotWidget):
42 42
 
43 43
             import cairo
44 44
 
45
+            # Scale to give 96 dpi instead of 72 dpi
45 46
             dpi = 96.0
46
-            zoom_ratio = dpi/72.0
47
-            w = int(self.graph.width*zoom_ratio)
48
-            h = int(self.graph.height*zoom_ratio)
47
+            scale = dpi/72.0
48
+            w = int(self.graph.width*scale)
49
+            h = int(self.graph.height*scale)
50
+
51
+            CAIRO_XMAX = 32767
52
+            CAIRO_YMAX = 32767
53
+            if w >= CAIRO_XMAX:
54
+                w = CAIRO_XMAX
55
+                scale = w/self.graph.width
56
+                h = int(self.graph.height*scale)
57
+            if h >= CAIRO_YMAX:
58
+                h = CAIRO_YMAX
59
+                scale = h/self.graph.height
60
+                w = int(self.graph.width*scale)
61
+
62
+            assert w <= CAIRO_XMAX
63
+            assert h <= CAIRO_YMAX
49 64
 
50 65
             surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
51 66
 
... ...
@@ -54,7 +69,7 @@ class TestDotWidget(DotWidget):
54 69
             cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
55 70
             cr.paint()
56 71
 
57
-            cr.scale(zoom_ratio, zoom_ratio)
72
+            cr.scale(scale, scale)
58 73
 
59 74
             self.graph.draw(cr, highlight_items=self.highlight)
60 75
 
... ...
@@ -89,9 +104,12 @@ def main():
89 104
         except:
90 105
             exc_info = sys.exc_info()
91 106
             traceback.print_exception(*exc_info)
92
-        window.show()
93
-        Gtk.main()
94
-        window.destroy()
107
+            continue
108
+        try:
109
+            window.show()
110
+            Gtk.main()
111
+        finally:
112
+            window.destroy()
95 113
 
96 114
 
97 115
 if __name__ == '__main__':