Skip to content

Commit

Permalink
Fix two unit tests. Reduce showing windows in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HelioGuilherme66 committed Nov 2, 2024
1 parent ce812a9 commit 338b005
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 24 deletions.
6 changes: 3 additions & 3 deletions utest/application/test_updatenotifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ def setUp(self):
self.source = self.app.tree.controller
self.app.frame.SetStatusText("File:" + self.app.project.data.source)
# Uncomment next line (and MainLoop in tests) if you want to see the app
self.frame.Show()
# self.frame.Show()

def tearDown(self):
self.plugin.unsubscribe_all()
PUBLISHER.unsubscribe_all()
self.app.project.close()
wx.CallAfter(self.app.ExitMainLoop)
self.app.MainLoop() # With this here, there is no Segmentation fault
# wx.CallAfter(self.app.ExitMainLoop)
# self.app.MainLoop() # With this here, there is no Segmentation fault
# wx.CallAfter(wx.Exit)
self.app.Destroy()
self.app = None
Expand Down
35 changes: 22 additions & 13 deletions utest/editor/test_z_kweditor_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def _datafile_controller(self):
return data_controller(new_test_case_file(datafilereader.TESTCASEFILE_WITH_EVERYTHING), None)

def OnExit(self): # Overrides wx method
os.remove(self.file_settings)
if hasattr(self, 'file_settings'):
os.remove(self.file_settings)


class KeywordEditorTest(unittest.TestCase):
Expand Down Expand Up @@ -237,7 +238,7 @@ def setUp(self):
self._editor = self._grid
self.app.frame.SetStatusText("File:" + self.app.project.data.source)
# Uncomment next line (and MainLoop in tests) if you want to see the app
self.frame.Show()
# self.frame.Show()

def _register(self, iclass, eclass):
self._registered_editors[iclass] = eclass
Expand Down Expand Up @@ -269,7 +270,7 @@ def tearDown(self):
self.plugin.unsubscribe_all()
PUBLISHER.unsubscribe_all()
self.app.project.close()
wx.CallAfter(self.app.ExitMainLoop)
# wx.CallAfter(self.app.ExitMainLoop)
# self.app.MainLoop() # With this here, there is no Segmentation fault
# wx.CallAfter(wx.Exit)
self.app.Destroy()
Expand Down Expand Up @@ -302,8 +303,8 @@ def test_show(self):
print(f"DEBUG: Editor is {show}")
assert show is not None
# Uncomment next lines if you want to see the app
wx.CallLater(5000, self.app.ExitMainLoop)
self.app.MainLoop()
# wx.CallLater(5000, self.app.ExitMainLoop)
# self.app.MainLoop()

def test_on_comment_cells(self):
self.creator.editor_for(self.plugin, self._panel, self.frame.tree)
Expand All @@ -313,8 +314,8 @@ def test_on_comment_cells(self):
# self.plugin.on_comment_cells(None)
data = self._grid.get_selected_content()
print(f"DEBUG: After Sharp Comment Data Cell is {data}")
wx.CallLater(5000, self.app.ExitMainLoop)
self.app.MainLoop()
# wx.CallLater(5000, self.app.ExitMainLoop)
# self.app.MainLoop()


""" Clipboard tests moved frpm test_grid.py to here """
Expand Down Expand Up @@ -358,17 +359,25 @@ def _cut_block_and_verify(self, block, exp_clipboard, exp_grid):
self._verify_grid_content(exp_grid)

def test_undo_with_cut(self):
self._cut_undo_and_verify((0, 0, 0, 0), DATA)
self._cut_undo_and_verify((0, 0, 2, 2), DATA)

def _cut_undo_and_verify(self, block, exp_data_after_undo):
self._cut_block(block)
self._cut_block((0, 0, 0, 0))
self._editor.undo()
self._verify_grid_content(DATA)
self._cut_block((0, 0, 2, 2))
# We have problems here. We need undo for each cell removed
self._editor.undo()
self._verify_grid_content(exp_data_after_undo)
self._editor.undo()
self._editor.undo()
self._editor.undo()
self._editor.undo()
self._editor.undo()
self._verify_grid_content(DATA)

def test_multiple_levels_of_undo(self):
self._cut_block((0, 0, 0, 0))
self._cut_block((2, 0, 2, 2))
# We have problems here. We need undo for each cell removed
self._editor.undo()
self._editor.undo()
self._editor.undo()
self._verify_grid_content([['', '', '']] + DATA[1:])
self._editor.undo()
Expand Down
4 changes: 2 additions & 2 deletions utest/resources/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,6 @@ def setUp(self):
self.app = wx.App()

def tearDown(self):
wx.CallAfter(self.app.ExitMainLoop)
self.app.MainLoop()
# wx.CallAfter(self.app.ExitMainLoop)
# self.app.MainLoop()
self.app = None
6 changes: 3 additions & 3 deletions utest/run/test_ui_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ def setUp(self):
self.frame.tree = Tree(self.frame, ActionRegisterer(AuiManager(self.frame),
MenuBar(self.frame), ToolBar(self.frame),
ShortcutRegistry(self.frame)), settings)
self.frame.Show()
# self.frame.Show()
self.model = self._create_model()

def tearDown(self):
PUBLISHER.unsubscribe_all()
wx.CallAfter(self.app.ExitMainLoop)
# wx.CallAfter(self.app.ExitMainLoop)
self.app.Destroy()
self.app = None

Expand Down Expand Up @@ -138,7 +138,7 @@ def test_log_output(self):
time.sleep(1)
log_output.update_log(['line one', 'line two'])
time.sleep(1)
self.frame.Maximize()
# self.frame.Maximize()
sim = wx.UIActionSimulator()
sim.KeyDown(keycode=wx.WXK_CONTROL_A)
time.sleep(5)
Expand Down
2 changes: 1 addition & 1 deletion utest/ui/test_tagdialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def setUp(self):

def tearDown(self):
PUBLISHER.unsubscribe_all()
wx.CallAfter(self.app.ExitMainLoop)
# wx.CallAfter(self.app.ExitMainLoop)
# self.app.MainLoop() # With this here, there is no Segmentation fault
# wx.CallAfter(wx.Exit)
self.app.Destroy()
Expand Down
2 changes: 1 addition & 1 deletion utest/ui/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def tearDown(self):
PUBLISHER.unsubscribe_all()
wx.CallAfter(self.frame.Close)
wx.CallAfter(self.app.ExitMainLoop)
self.app.MainLoop() # With this here, there is no Segmentation fault
# self.app.MainLoop() # With this here, there is no Segmentation fault
self.app = None

def _create_model(self):
Expand Down
2 changes: 1 addition & 1 deletion utest/zulu_misc/test_get_language_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_get_code(self):
code = main_app._get_language_code()
assert code in (wx.LANGUAGE_ENGLISH, wx.LANGUAGE_ENGLISH_WORLD, wx.LANGUAGE_PORTUGUESE)
# Uncomment next lines if you want to see the app
wx.CallLater(8000, main_app.ExitMainLoop)
# wx.CallLater(8000, main_app.ExitMainLoop)
# main_app.MainLoop()


Expand Down

0 comments on commit 338b005

Please sign in to comment.