Commit e0ef4064 authored by Julien Muchembled's avatar Julien Muchembled

ui_dump_test: fix comparison between expected & actual results

Due to some debug code, it never checked anything.
parent 8e9c6d42
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
############################################################################## ##############################################################################
import os, sys, weakref import errno, os, sys, weakref
from difflib import unified_diff from difflib import unified_diff
from pprint import pprint, pformat from pprint import pprint, pformat
from AccessControl.SecurityManagement \ from AccessControl.SecurityManagement \
...@@ -41,8 +41,7 @@ class ui_dump_test(object): ...@@ -41,8 +41,7 @@ class ui_dump_test(object):
""" """
User Interface dump generator while running unit test. User Interface dump generator while running unit test.
This class is usually subclassed. If you wish to store dump file, This class is usually subclassed.
you should export os environment variable "save_<subclass_name>=1"
""" """
_enabled = None _enabled = None
...@@ -165,24 +164,25 @@ class ui_dump_test(object): ...@@ -165,24 +164,25 @@ class ui_dump_test(object):
context = self.context context = self.context
test_file = sys.modules[context.__class__.__module__].__file__ test_file = sys.modules[context.__class__.__module__].__file__
dump_name = self.__class__.__name__ dump_name = self.__class__.__name__
dump_path = os.path.join(os.path.abspath(os.path.dirname(test_file)), dump_path = save_path = os.path.join(
dump_name, '%s.py' % context.id()) os.path.abspath(os.path.dirname(test_file)),
save_env_name = 'save_' + dump_name dump_name, '%s.py' % context.id())
if os.environ.get(save_env_name) == '1': try:
with open(dump_path, 'w') as f: try:
pprint(self.dump, f) with open(dump_path) as f:
else: diff = self.diff(f.read())
# The following 2 lines are only for debugging purpose: it saves the except IOError as e:
# actual results in a temporary place, so that when the diff is not if e.errno != errno.ENOENT:
# clear enough, one can inspect them in whole. save_path = None
with open(dump_path, 'w') as f: raise
pprint(self.dump, f)
with open(dump_path) as f:
diff = self.diff(f.read())
if diff: if diff:
msg = ("UI dump for %r changed:\n%s\n\nTo update the dump, please" save_path += '.new'
" run the test again setting the environment variable %r to 1.") context.fail("UI dump for %r changed:\n%s" % (dump_path, diff))
context.fail(msg % (dump_path, diff, save_env_name)) save_path = None
finally:
if save_path:
with open(save_path, 'w') as f:
pprint(self.dump, f)
def getTrackingKey(self, path, obj): def getTrackingKey(self, path, obj):
"""Return the 'type' of object (only 1 object per 'type' is tracked) """Return the 'type' of object (only 1 object per 'type' is tracked)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment