Tests run much faster like that.
Logging should be improved, but that is left to another opportunity.
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
#!/usr/bin/env python3 |
2 | 2 |
# |
3 |
-# Copyright 2015 Jose Fonseca |
|
3 |
+# Copyright 2015-2016 Jose Fonseca |
|
4 | 4 |
# |
5 | 5 |
# This program is free software: you can redistribute it and/or modify it |
6 | 6 |
# under the terms of the GNU Lesser General Public License as published |
... | ... |
@@ -20,104 +20,125 @@ |
20 | 20 |
import sys |
21 | 21 |
import os.path |
22 | 22 |
import traceback |
23 |
+import multiprocessing |
|
23 | 24 |
|
24 |
-import gi |
|
25 |
-gi.require_version('Gtk', '3.0') |
|
26 | 25 |
|
27 |
-from gi.repository import Gtk |
|
28 |
-from gi.repository import Gdk |
|
26 |
+def test(arg): |
|
27 |
+ sys.stdout.write(arg + '\n') |
|
28 |
+ sys.stdout.flush() |
|
29 | 29 |
|
30 |
-from xdot import DotWidget, DotWindow |
|
31 | 30 |
|
31 |
+ import gi |
|
32 |
+ gi.require_version('Gtk', '3.0') |
|
32 | 33 |
|
33 |
-class TestDotWidget(DotWidget): |
|
34 |
+ from gi.repository import Gtk |
|
35 |
+ from gi.repository import Gdk |
|
34 | 36 |
|
35 |
- def __init__(self, name): |
|
36 |
- DotWidget.__init__(self) |
|
37 |
- self.name = name |
|
37 |
+ from xdot import DotWidget, DotWindow |
|
38 | 38 |
|
39 |
- def on_draw(self, widget, cr): |
|
40 |
- DotWidget.on_draw(self, widget, cr) |
|
41 | 39 |
|
42 |
- if True: |
|
43 |
- # Cairo screenshot |
|
40 |
+ class TestDotWidget(DotWidget): |
|
44 | 41 |
|
45 |
- import cairo |
|
42 |
+ def __init__(self, name): |
|
43 |
+ DotWidget.__init__(self) |
|
44 |
+ self.name = name |
|
46 | 45 |
|
47 |
- # Scale to give 96 dpi instead of 72 dpi |
|
48 |
- dpi = 96.0 |
|
49 |
- scale = dpi/72.0 |
|
50 |
- w = int(self.graph.width*scale) |
|
51 |
- h = int(self.graph.height*scale) |
|
46 |
+ def on_draw(self, widget, cr): |
|
47 |
+ DotWidget.on_draw(self, widget, cr) |
|
52 | 48 |
|
53 |
- CAIRO_XMAX = 32767 |
|
54 |
- CAIRO_YMAX = 32767 |
|
55 |
- if w >= CAIRO_XMAX: |
|
56 |
- w = CAIRO_XMAX |
|
57 |
- scale = w/self.graph.width |
|
58 |
- h = int(self.graph.height*scale) |
|
59 |
- if h >= CAIRO_YMAX: |
|
60 |
- h = CAIRO_YMAX |
|
61 |
- scale = h/self.graph.height |
|
49 |
+ if True: |
|
50 |
+ # Cairo screenshot |
|
51 |
+ |
|
52 |
+ import cairo |
|
53 |
+ |
|
54 |
+ # Scale to give 96 dpi instead of 72 dpi |
|
55 |
+ dpi = 96.0 |
|
56 |
+ scale = dpi/72.0 |
|
62 | 57 |
w = int(self.graph.width*scale) |
58 |
+ h = int(self.graph.height*scale) |
|
63 | 59 |
|
64 |
- assert w <= CAIRO_XMAX |
|
65 |
- assert h <= CAIRO_YMAX |
|
60 |
+ CAIRO_XMAX = 32767 |
|
61 |
+ CAIRO_YMAX = 32767 |
|
62 |
+ if w >= CAIRO_XMAX: |
|
63 |
+ w = CAIRO_XMAX |
|
64 |
+ scale = w/self.graph.width |
|
65 |
+ h = int(self.graph.height*scale) |
|
66 |
+ if h >= CAIRO_YMAX: |
|
67 |
+ h = CAIRO_YMAX |
|
68 |
+ scale = h/self.graph.height |
|
69 |
+ w = int(self.graph.width*scale) |
|
66 | 70 |
|
67 |
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) |
|
71 |
+ assert w <= CAIRO_XMAX |
|
72 |
+ assert h <= CAIRO_YMAX |
|
68 | 73 |
|
69 |
- cr = cairo.Context(surface) |
|
74 |
+ surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) |
|
70 | 75 |
|
71 |
- cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) |
|
72 |
- cr.paint() |
|
76 |
+ cr = cairo.Context(surface) |
|
73 | 77 |
|
74 |
- cr.scale(scale, scale) |
|
78 |
+ cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) |
|
79 |
+ cr.paint() |
|
75 | 80 |
|
76 |
- self.graph.draw(cr, highlight_items=self.highlight) |
|
81 |
+ cr.scale(scale, scale) |
|
77 | 82 |
|
78 |
- surface.write_to_png(self.name + '.png') |
|
83 |
+ self.graph.draw(cr, highlight_items=self.highlight) |
|
79 | 84 |
|
80 |
- if False: |
|
81 |
- # GTK 3 screenshot |
|
85 |
+ surface.write_to_png(self.name + '.png') |
|
82 | 86 |
|
83 |
- window = self.get_window() |
|
87 |
+ if False: |
|
88 |
+ # GTK 3 screenshot |
|
84 | 89 |
|
85 |
- w = window.get_width() |
|
86 |
- h = window.get_height() |
|
90 |
+ window = self.get_window() |
|
87 | 91 |
|
88 |
- pixbuf = Gdk.pixbuf_get_from_window(window, 0, 0, w, h) |
|
92 |
+ w = window.get_width() |
|
93 |
+ h = window.get_height() |
|
89 | 94 |
|
90 |
- pixbuf.savev(self.name + '.png', 'png', (), ()) |
|
95 |
+ pixbuf = Gdk.pixbuf_get_from_window(window, 0, 0, w, h) |
|
91 | 96 |
|
92 |
- Gtk.main_quit() |
|
97 |
+ pixbuf.savev(self.name + '.png', 'png', (), ()) |
|
93 | 98 |
|
94 |
- def error_dialog(self, message): |
|
95 |
- sys.stderr.write(message) |
|
96 |
- sys.stderr.write("\n") |
|
99 |
+ Gtk.main_quit() |
|
97 | 100 |
|
101 |
+ def error_dialog(self, message): |
|
102 |
+ sys.stderr.write(message) |
|
103 |
+ sys.stderr.write("\n") |
|
98 | 104 |
|
99 |
-def main(): |
|
100 |
- status = 0 |
|
101 |
- for arg in sys.argv[1:]: |
|
102 |
- sys.stdout.write(arg + '\n') |
|
103 |
- sys.stdout.flush() |
|
104 |
- name, ext = os.path.splitext(os.path.basename(arg)) |
|
105 |
- widget = TestDotWidget(name) |
|
106 |
- window = DotWindow(widget) |
|
107 |
- window.connect('delete-event', Gtk.main_quit) |
|
105 |
+ |
|
106 |
+ result = True |
|
107 |
+ |
|
108 |
+ name, ext = os.path.splitext(os.path.basename(arg)) |
|
109 |
+ widget = TestDotWidget(name) |
|
110 |
+ window = DotWindow(widget) |
|
111 |
+ window.connect('delete-event', Gtk.main_quit) |
|
112 |
+ try: |
|
108 | 113 |
try: |
109 |
- try: |
|
110 |
- dotcode = open(arg, 'rb').read() |
|
111 |
- window.set_dotcode(dotcode) |
|
112 |
- except: |
|
113 |
- exc_info = sys.exc_info() |
|
114 |
- traceback.print_exception(*exc_info) |
|
115 |
- status = 1 |
|
116 |
- else: |
|
117 |
- window.show() |
|
118 |
- Gtk.main() |
|
119 |
- finally: |
|
120 |
- window.destroy() |
|
114 |
+ dotcode = open(arg, 'rb').read() |
|
115 |
+ window.set_dotcode(dotcode) |
|
116 |
+ except: |
|
117 |
+ exc_info = sys.exc_info() |
|
118 |
+ traceback.print_exception(*exc_info) |
|
119 |
+ result = False |
|
120 |
+ else: |
|
121 |
+ window.show() |
|
122 |
+ Gtk.main() |
|
123 |
+ finally: |
|
124 |
+ window.destroy() |
|
125 |
+ |
|
126 |
+ return result |
|
127 |
+ |
|
128 |
+ |
|
129 |
+def main(): |
|
130 |
+ args = sys.argv[1:] |
|
131 |
+ |
|
132 |
+ pool = multiprocessing.Pool(multiprocessing.cpu_count()) |
|
133 |
+ results = pool.map(test, args) |
|
134 |
+ |
|
135 |
+ # Exit with status 1 if any failed |
|
136 |
+ try: |
|
137 |
+ results.index(False) |
|
138 |
+ except ValueError: |
|
139 |
+ status = 0 |
|
140 |
+ else: |
|
141 |
+ status = 1 |
|
121 | 142 |
sys.exit(status) |
122 | 143 |
|
123 | 144 |
|
... | ... |
@@ -97,25 +97,28 @@ class TestDotWidget(DotWidget): |
97 | 97 |
|
98 | 98 |
|
99 | 99 |
def main(): |
100 |
+ status = 0 |
|
100 | 101 |
for arg in sys.argv[1:]: |
101 | 102 |
sys.stdout.write(arg + '\n') |
102 | 103 |
sys.stdout.flush() |
103 | 104 |
name, ext = os.path.splitext(os.path.basename(arg)) |
104 |
- dotcode = open(arg, 'rb').read() |
|
105 | 105 |
widget = TestDotWidget(name) |
106 | 106 |
window = DotWindow(widget) |
107 | 107 |
window.connect('delete-event', Gtk.main_quit) |
108 | 108 |
try: |
109 |
- window.set_dotcode(dotcode) |
|
110 |
- except: |
|
111 |
- exc_info = sys.exc_info() |
|
112 |
- traceback.print_exception(*exc_info) |
|
113 |
- continue |
|
114 |
- try: |
|
115 |
- window.show() |
|
116 |
- Gtk.main() |
|
109 |
+ try: |
|
110 |
+ dotcode = open(arg, 'rb').read() |
|
111 |
+ window.set_dotcode(dotcode) |
|
112 |
+ except: |
|
113 |
+ exc_info = sys.exc_info() |
|
114 |
+ traceback.print_exception(*exc_info) |
|
115 |
+ status = 1 |
|
116 |
+ else: |
|
117 |
+ window.show() |
|
118 |
+ Gtk.main() |
|
117 | 119 |
finally: |
118 | 120 |
window.destroy() |
121 |
+ sys.exit(status) |
|
119 | 122 |
|
120 | 123 |
|
121 | 124 |
if __name__ == '__main__': |
... | ... |
@@ -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__': |
This is because several fields in xdot have number of bytes, not
characters.
... | ... |
@@ -80,7 +80,7 @@ def main(): |
80 | 80 |
sys.stdout.write(arg + '\n') |
81 | 81 |
sys.stdout.flush() |
82 | 82 |
name, ext = os.path.splitext(os.path.basename(arg)) |
83 |
- dotcode = open(arg).read() |
|
83 |
+ dotcode = open(arg, 'rb').read() |
|
84 | 84 |
widget = TestDotWidget(name) |
85 | 85 |
window = DotWindow(widget) |
86 | 86 |
window.connect('delete-event', Gtk.main_quit) |
1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,98 @@ |
1 |
+#!/usr/bin/env python |
|
2 |
+# |
|
3 |
+# Copyright 2015 Jose Fonseca |
|
4 |
+# |
|
5 |
+# This program is free software: you can redistribute it and/or modify it |
|
6 |
+# under the terms of the GNU Lesser General Public License as published |
|
7 |
+# by the Free Software Foundation, either version 3 of the License, or |
|
8 |
+# (at your option) any later version. |
|
9 |
+# |
|
10 |
+# This program is distributed in the hope that it will be useful, |
|
11 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
+# GNU Lesser General Public License for more details. |
|
14 |
+# |
|
15 |
+# You should have received a copy of the GNU Lesser General Public License |
|
16 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
+# |
|
18 |
+ |
|
19 |
+ |
|
20 |
+import sys |
|
21 |
+import os.path |
|
22 |
+import traceback |
|
23 |
+ |
|
24 |
+from gi.repository import Gtk |
|
25 |
+from gi.repository import Gdk |
|
26 |
+from gi.repository import GdkPixbuf |
|
27 |
+ |
|
28 |
+from xdot import DotWidget, DotWindow |
|
29 |
+ |
|
30 |
+ |
|
31 |
+class TestDotWidget(DotWidget): |
|
32 |
+ |
|
33 |
+ def __init__(self, name): |
|
34 |
+ DotWidget.__init__(self) |
|
35 |
+ self.name = name |
|
36 |
+ |
|
37 |
+ def on_draw(self, widget, cr): |
|
38 |
+ DotWidget.on_draw(self, widget, cr) |
|
39 |
+ |
|
40 |
+ if True: |
|
41 |
+ # Cairo screenshot |
|
42 |
+ |
|
43 |
+ import cairo |
|
44 |
+ |
|
45 |
+ 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) |
|
49 |
+ |
|
50 |
+ surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) |
|
51 |
+ |
|
52 |
+ cr = cairo.Context(surface) |
|
53 |
+ |
|
54 |
+ cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) |
|
55 |
+ cr.paint() |
|
56 |
+ |
|
57 |
+ cr.scale(zoom_ratio, zoom_ratio) |
|
58 |
+ |
|
59 |
+ self.graph.draw(cr, highlight_items=self.highlight) |
|
60 |
+ |
|
61 |
+ surface.write_to_png(self.name + '.png') |
|
62 |
+ |
|
63 |
+ if False: |
|
64 |
+ # GTK 3 screenshot |
|
65 |
+ |
|
66 |
+ window = self.get_window() |
|
67 |
+ |
|
68 |
+ w = window.get_width() |
|
69 |
+ h = window.get_height() |
|
70 |
+ |
|
71 |
+ pixbuf = Gdk.pixbuf_get_from_window(window, 0, 0, w, h) |
|
72 |
+ |
|
73 |
+ pixbuf.savev(self.name + '.png', 'png', (), ()) |
|
74 |
+ |
|
75 |
+ Gtk.main_quit() |
|
76 |
+ |
|
77 |
+ |
|
78 |
+def main(): |
|
79 |
+ for arg in sys.argv[1:]: |
|
80 |
+ sys.stdout.write(arg + '\n') |
|
81 |
+ sys.stdout.flush() |
|
82 |
+ name, ext = os.path.splitext(os.path.basename(arg)) |
|
83 |
+ dotcode = open(arg).read() |
|
84 |
+ widget = TestDotWidget(name) |
|
85 |
+ window = DotWindow(widget) |
|
86 |
+ window.connect('delete-event', Gtk.main_quit) |
|
87 |
+ try: |
|
88 |
+ window.set_dotcode(dotcode) |
|
89 |
+ except: |
|
90 |
+ exc_info = sys.exc_info() |
|
91 |
+ traceback.print_exception(*exc_info) |
|
92 |
+ window.show() |
|
93 |
+ Gtk.main() |
|
94 |
+ window.destroy() |
|
95 |
+ |
|
96 |
+ |
|
97 |
+if __name__ == '__main__': |
|
98 |
+ main() |