Merge pull request #236 from prculley/bug9697

bug 9697, fix Test Case Generator to avoid GUI progress meter in CLI mode
This commit is contained in:
Sam Manzi 2016-09-19 14:34:17 +10:00 committed by GitHub
commit 72aafd7471

View File

@ -71,7 +71,6 @@ from gramps.gen.db import DbTxn
from gramps.gen.mime import get_type from gramps.gen.mime import get_type
from gramps.gui.plug import tool from gramps.gui.plug import tool
from gramps.gen.utils.string import conf_strings from gramps.gen.utils.string import conf_strings
from gramps.gui.utils import ProgressMeter
from gramps.gen.utils.lds import TEMPLES from gramps.gen.utils.lds import TEMPLES
from gramps.gen.db.dbconst import * from gramps.gen.db.dbconst import *
from gramps.gen.const import ICON, LOGO, SPLASH from gramps.gen.const import ICON, LOGO, SPLASH
@ -180,6 +179,7 @@ class TestcaseGenerator(tool.BatchTool):
parent_window = uistate.window parent_window = uistate.window
else: else:
parent_window = None parent_window = None
self.progress = user.progress
self.person = None self.person = None
if dbstate.db.readonly: if dbstate.db.readonly:
return return
@ -338,81 +338,81 @@ class TestcaseGenerator(tool.BatchTool):
else: else:
self.window = None self.window = None
self.progress = ProgressMeter(
_('Generating testcases'), '', parent=self.window)
self.transaction_count = 0; self.transaction_count = 0;
if self.options.handler.options_dict['lowlevel']: if self.options.handler.options_dict['lowlevel']:
self.progress.set_pass(_('Generating low level database errors'), with self.progress(_('Generating testcases'),
1) _('Generating low level database errors'),
self.test_low_level(); self.progress.step() 1) as step:
self.test_low_level()
step()
if self.options.handler.options_dict['bugs'] or \ if self.options.handler.options_dict['bugs'] or \
self.options.handler.options_dict['persons']: self.options.handler.options_dict['persons']:
self.generate_tags() self.generate_tags()
if self.options.handler.options_dict['bugs']: if self.options.handler.options_dict['bugs']:
self.generate_data_errors() with self.progress(_('Generating testcases'),
_('Generating database errors'),
18) as step:
self.generate_data_errors(step)
if self.options.handler.options_dict['persons']: if self.options.handler.options_dict['persons']:
self.progress.set_pass(_('Generating families'), with self.progress(_('Generating testcases'),
self.options.handler.options_dict['person_count']) _('Generating families'),
self.person_count = 0 self.options.handler.options_dict['person_count']) \
self.progress_step = self.progress.step as self.progress_step:
self.person_count = 0
while True: while True:
if not self.persons_todo: if not self.persons_todo:
ph = self.generate_person(0) ph = self.generate_person(0)
self.persons_todo.append( ph) self.persons_todo.append( ph)
self.parents_todo.append( ph) self.parents_todo.append( ph)
person_h = self.persons_todo.pop(0) person_h = self.persons_todo.pop(0)
self.generate_family(person_h)
if randint(0,3) == 0:
self.generate_family(person_h) self.generate_family(person_h)
if randint(0,7) == 0: if randint(0,3) == 0:
self.generate_family(person_h) self.generate_family(person_h)
if self.person_count > self.options.handler.options_dict['person_count']: if randint(0,7) == 0:
break self.generate_family(person_h)
for child_h in self.parents_todo:
self.generate_parents(child_h)
if self.person_count > self.options.handler.options_dict['person_count']: if self.person_count > self.options.handler.options_dict['person_count']:
break break
self.progress.close() for child_h in self.parents_todo:
self.generate_parents(child_h)
if self.person_count > self.options.handler.options_dict['person_count']:
break
if( not cli): if( not cli):
self.top.destroy() self.top.destroy()
def generate_data_errors(self): def generate_data_errors(self, step):
"""This generates errors in the database to test src/plugins/tool/Check """This generates errors in the database to test src/plugins/tool/Check
The module names correspond to the checking methods in The module names correspond to the checking methods in
src/plugins/tool/Check.CheckIntegrity """ src/plugins/tool/Check.CheckIntegrity """
self.progress.set_pass(_('Generating database errors'),
18)
# The progress meter is normally stepped every time a person is # The progress meter is normally stepped every time a person is
# generated by generate_person. However in this case, generate_person is # generated by generate_person. However in this case, generate_person is
# called by some of the constituent functions, but we only want the # called by some of the constituent functions, but we only want the
# meter to be stepped every time a test function has been completed. # meter to be stepped every time a test function has been completed.
self.progress_step = lambda: None self.progress_step = lambda: None
self.test_fix_encoding(); self.progress.step() self.test_fix_encoding(); step()
self.test_fix_ctrlchars_in_notes(); self.progress.step() self.test_fix_ctrlchars_in_notes(); step()
self.test_cleanup_missing_photos(); self.progress.step() self.test_cleanup_missing_photos(); step()
self.test_cleanup_deleted_name_formats(); self.progress.step() self.test_cleanup_deleted_name_formats(); step()
self.test_cleanup_empty_objects(); self.progress.step() self.test_cleanup_empty_objects(); step()
self.test_check_for_broken_family_links(); self.progress.step() self.test_check_for_broken_family_links(); step()
self.test_check_parent_relationships(); self.progress.step() self.test_check_parent_relationships(); step()
self.test_cleanup_empty_families(); self.progress.step() self.test_cleanup_empty_families(); step()
self.test_cleanup_duplicate_spouses(); self.progress.step() self.test_cleanup_duplicate_spouses(); step()
self.test_check_events(); self.progress.step() self.test_check_events(); step()
self.test_check_person_references(); self.progress.step() self.test_check_person_references(); step()
self.test_check_family_references(); self.progress.step() self.test_check_family_references(); step()
self.test_check_place_references(); self.progress.step() self.test_check_place_references(); step()
self.test_check_source_references(); self.progress.step() self.test_check_source_references(); step()
self.test_check_citation_references(); self.progress.step() self.test_check_citation_references(); step()
self.test_check_media_references(); self.progress.step() self.test_check_media_references(); step()
self.test_check_repo_references(); self.progress.step() self.test_check_repo_references(); step()
self.test_check_note_references(); self.progress.step() self.test_check_note_references(); step()
self.progress.close()
def test_low_level(self): def test_low_level(self):
with DbTxn(_("Testcase generator step %d") % self.transaction_count, with DbTxn(_("Testcase generator step %d") % self.transaction_count,