Skip to content
This repository was archived by the owner on Nov 19, 2018. It is now read-only.

Commit 0aa9189

Browse files
committed
Adjust tests to reverted changes
1 parent c985db9 commit 0aa9189

File tree

2 files changed

+66
-121
lines changed

2 files changed

+66
-121
lines changed

test/test_pydot.py

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -123,96 +123,12 @@ def test_unicode_ids(self):
123123
self.assertEqual(g2.get_edges()[0].get_source(), node1)
124124
self.assertEqual(g2.get_edges()[0].get_destination(), node2)
125125

126-
@unittest.skip("failing checksum")
127-
def test_graph_with_shapefiles(self):
128-
shapefile_dir = os.path.join(TEST_DIR, 'from-past-to-future')
129-
dot_file = os.path.join(shapefile_dir, 'from-past-to-future.dot')
130-
131-
pngs = [
132-
os.path.join(shapefile_dir, fname)
133-
for fname in os.listdir(shapefile_dir)
134-
if fname.endswith('.png')]
135-
136-
f = open(dot_file, 'rt')
137-
graph_data = f.read()
138-
f.close()
139-
140-
g = pydot.graph_from_dot_data(graph_data)
141-
g.set_shape_files(pngs)
142-
jpe_data = g.create(format='jpe')
143-
hexdigest = sha256(jpe_data).hexdigest()
144-
hexdigest_original = self._render_with_graphviz(dot_file)
145-
self.assertEqual(hexdigest, hexdigest_original)
146-
147126
def test_multiple_graphs(self):
148127
graph_data = 'graph A { a->b };\ngraph B {c->d}'
149128
graphs = pydot.graph_from_dot_data(graph_data)
150129
self.assertEqual(len(graphs), 2)
151130
self.assertEqual([g.get_name() for g in graphs], ['A', 'B'])
152131

153-
def _render_with_graphviz(self, filename):
154-
p = subprocess.Popen(
155-
(DOT_BINARY_PATH, '-Tjpe'),
156-
cwd=os.path.dirname(filename),
157-
stdin=open(filename, 'rt'),
158-
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
159-
160-
stdout = p.stdout
161-
162-
stdout_output = list()
163-
while True:
164-
data = stdout.read()
165-
if not data:
166-
break
167-
stdout_output.append(data)
168-
stdout.close()
169-
170-
if stdout_output:
171-
stdout_output = NULL_SEP.join(stdout_output)
172-
173-
# this returns a status code we should check
174-
p.wait()
175-
176-
return sha256(stdout_output).hexdigest()
177-
178-
def _render_with_pydot(self, filename):
179-
g = pydot.graph_from_dot_file(filename)
180-
if not isinstance(g, list):
181-
g = [g]
182-
jpe_data = NULL_SEP.join([_g.create(format='jpe') for _g in g])
183-
return sha256(jpe_data).hexdigest()
184-
185-
def test_my_regression_tests(self):
186-
self._render_and_compare_dot_files(MY_REGRESSION_TESTS_DIR)
187-
188-
@unittest.skip('failing checksum')
189-
def test_graphviz_regression_tests(self):
190-
self._render_and_compare_dot_files(REGRESSION_TESTS_DIR)
191-
192-
def _render_and_compare_dot_files(self, directory):
193-
194-
dot_files = [
195-
fname for fname in os.listdir(directory)
196-
if fname.endswith('.dot')]
197-
198-
for dot in dot_files:
199-
os.sys.stdout.write('#')
200-
os.sys.stdout.flush()
201-
202-
fname = os.path.join(directory, dot)
203-
204-
try:
205-
parsed_data_hexdigest = self._render_with_pydot(fname)
206-
original_data_hexdigest = self._render_with_graphviz(fname)
207-
except Exception:
208-
print('Failed rendering BAD(%s)' % dot)
209-
raise
210-
211-
if parsed_data_hexdigest != original_data_hexdigest:
212-
print('BAD(%s)' % dot)
213-
214-
self.assertEqual(parsed_data_hexdigest, original_data_hexdigest)
215-
216132
def test_numeric_node_id(self):
217133
self._reset_graphs()
218134
self.graph_directed.add_node(pydot.Node(1))
@@ -288,22 +204,24 @@ def test_quoting(self):
288204

289205
class TestQuoting(unittest.TestCase):
290206

207+
# TODO(prmtl): this need to be checked with DOT lang
208+
# sepcification (or how graphviz works) again
291209
def test_quote_cases(self):
292210
checks = (
293211
('A:', '"A:"'),
294212
(':B', '":B"'),
295-
('A:B', '"A:B"'),
213+
('A:B', 'A:B'),
296214
('1A', '"1A"'),
297215
('A', 'A'),
298216
('11', '11'),
299217
('_xyz', '_xyz'),
300-
('.11', '.11'),
301-
('-.09', '-.09'),
302-
('1.8', '1.8'),
303-
('', '""'),
218+
('.11', '".11"'),
219+
('-.09', '"-.09"'),
220+
('1.8', '"1.8"'),
221+
# ('', '""'),
304222
('"1abc"', '"1abc"'),
305223
('@', '"@"'),
306-
('ÿ', 'ÿ'),
224+
('ÿ', '"ÿ"'),
307225
('$GUID__/ffb73e1c-7495-40b3-9618-9e5462fc89c7',
308226
'"$GUID__/ffb73e1c-7495-40b3-9618-9e5462fc89c7"')
309227
)

test/test_rendering_dot_files.py

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def list_dots(path):
3737

3838

3939
def pytest_generate_tests(metafunc):
40+
if metafunc.function != test_render_and_compare_dot_files:
41+
return
42+
4043
idlist = []
4144
argvalues = []
4245
for name, dir in TESTS_DIRS:
@@ -52,39 +55,63 @@ def pytest_generate_tests(metafunc):
5255
)
5356

5457

58+
def _render_with_graphviz(filename):
59+
p = subprocess.Popen(
60+
(DOT_BINARY_PATH, '-Tjpe'),
61+
cwd=os.path.dirname(filename),
62+
stdin=open(filename, 'rt'),
63+
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
64+
65+
stdout = p.stdout
66+
67+
stdout_output = list()
68+
while True:
69+
data = stdout.read()
70+
if not data:
71+
break
72+
stdout_output.append(data)
73+
stdout.close()
74+
75+
if stdout_output:
76+
stdout_output = NULL_SEP.join(stdout_output)
77+
78+
# this returns a status code we should check
79+
p.wait()
80+
81+
return sha256(stdout_output).hexdigest()
82+
83+
84+
def _render_with_pydot(filename):
85+
g = pydot.graph_from_dot_file(filename)
86+
if not isinstance(g, list):
87+
g = [g]
88+
jpe_data = NULL_SEP.join([_g.create(format='jpe') for _g in g])
89+
return sha256(jpe_data).hexdigest()
90+
91+
5592
def test_render_and_compare_dot_files(filepath):
56-
def _render_with_graphviz(filename):
57-
p = subprocess.Popen(
58-
(DOT_BINARY_PATH, '-Tjpe'),
59-
cwd=os.path.dirname(filename),
60-
stdin=open(filename, 'rt'),
61-
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
62-
63-
stdout = p.stdout
64-
65-
stdout_output = list()
66-
while True:
67-
data = stdout.read()
68-
if not data:
69-
break
70-
stdout_output.append(data)
71-
stdout.close()
72-
73-
if stdout_output:
74-
stdout_output = NULL_SEP.join(stdout_output)
75-
76-
# this returns a status code we should check
77-
p.wait()
78-
79-
return sha256(stdout_output).hexdigest()
80-
81-
def _render_with_pydot(filename):
82-
g = pydot.graph_from_dot_file(filename)
83-
if not isinstance(g, list):
84-
g = [g]
85-
jpe_data = NULL_SEP.join([_g.create(format='jpe') for _g in g])
86-
return sha256(jpe_data).hexdigest()
8793
parsed_data_hexdigest = _render_with_pydot(filepath)
8894
original_data_hexdigest = _render_with_graphviz(filepath)
8995

9096
assert original_data_hexdigest == parsed_data_hexdigest
97+
98+
99+
def test_graph_with_shapefiles():
100+
shapefile_dir = os.path.join(TEST_DIR, 'from-past-to-future')
101+
dot_file = os.path.join(shapefile_dir, 'from-past-to-future.dot')
102+
103+
pngs = [
104+
os.path.join(shapefile_dir, fname)
105+
for fname in os.listdir(shapefile_dir)
106+
if fname.endswith('.png')]
107+
108+
with open(dot_file, 'rt') as f:
109+
graph_data = f.read()
110+
#
111+
g = pydot.graph_from_dot_data(graph_data)
112+
g.set_shape_files(pngs)
113+
jpe_data = g.create(format='jpe')
114+
hexdigest = sha256(jpe_data).hexdigest()
115+
hexdigest_original = _render_with_graphviz(dot_file)
116+
117+
assert hexdigest == hexdigest_original

0 commit comments

Comments
 (0)