Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import unittest
00035
00036 from qt_dotgraph.dot_to_qt import DotToQtGenerator, get_unquoted
00037 from python_qt_binding.QtWidgets import QApplication
00038 import sys
00039 import subprocess
00040
00041
00042 def check_x_server():
00043 p = subprocess.Popen(sys.executable, stdin=subprocess.PIPE)
00044 p.stdin.write('from python_qt_binding.QtWidgets import QApplication\n')
00045 p.stdin.write('app = QApplication([])\n')
00046 p.stdin.close()
00047 p.communicate()
00048
00049 print(p.returncode)
00050
00051 return p.returncode == 0
00052
00053
00054
00055 class DotToQtGeneratorTest(unittest.TestCase):
00056
00057 DOT_CODE = '''
00058 digraph graph_name {
00059 graph [bb="0,0,154,108",
00060 rank=same
00061 ];
00062 node [label="\N"];
00063 subgraph cluster_foo {
00064 graph [bb="1,1,100,101",
00065 label=cluster_foo
00066 ];
00067 }
00068 foo [height=0.5,
00069 label=foo,
00070 pos="77,90",
00071 shape=box,
00072 width=0.75];
00073 bar [height=0.5,
00074 label=barbarbarbarbarbarbarbar,
00075 pos="77,18",
00076 shape=box,
00077 width=2.25];
00078 foo -> bar [pos="e,77,36.104 77,71.697 77,63.983 77,54.712 77,46.112"];
00079 }
00080 '''
00081
00082 _Q_APP = None
00083
00084 def __init__(self, *args):
00085 super(DotToQtGeneratorTest, self).__init__(*args)
00086
00087 if DotToQtGeneratorTest._Q_APP is None:
00088 if check_x_server():
00089 DotToQtGeneratorTest._Q_APP = QApplication([])
00090
00091 def test_simple_integration(self):
00092 if DotToQtGeneratorTest._Q_APP is None:
00093 raise unittest.case.SkipTest
00094
00095 (nodes, edges) = DotToQtGenerator().dotcode_to_qt_items(
00096 DotToQtGeneratorTest.DOT_CODE, 1)
00097 self.assertEqual(3, len(nodes))
00098 self.assertEqual(1, len(edges))
00099
00100 def test_label_sizes(self):
00101 if DotToQtGeneratorTest._Q_APP is None:
00102 raise unittest.case.SkipTest
00103
00104 (nodes, edges) = DotToQtGenerator().dotcode_to_qt_items(DotToQtGeneratorTest.DOT_CODE, 1)
00105
00106 self.longMessage = True
00107 for name, node in nodes.items():
00108 shape_rect = node._graphics_item.sceneBoundingRect()
00109 label_rect = node._label.sceneBoundingRect()
00110 self.assertLess(
00111 label_rect.width(),
00112 shape_rect.width(),
00113 "Label text for '%s' is wider than surrounding shape." % name)
00114 self.assertLess(
00115 label_rect.height(),
00116 shape_rect.height(),
00117 "Label text for '%s' is higher than surrounding shape." % name)
00118
00119 def test_unquoted(self):
00120 self.assertEqual("foo", get_unquoted({'bar': 'foo'}, 'bar'))