Gnumed.timelinelib.test.cases.unit

Package Gnumed :: Package timelinelib :: Package test :: Package cases :: Module unit |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.test.cases.unit

     1  # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018  Rickard Lindberg, Roger Lindberg
     2  #
     3  # This file is part of Timeline.
     4  #
     5  # Timeline is free software: you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License as published by
     7  # the Free Software Foundation, either version 3 of the License, or
     8  # (at your option) any later version.
     9  #
    10  # Timeline is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  # GNU General Public License for more details.
    14  #
    15  # You should have received a copy of the GNU General Public License
    16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>.
    17
    18
    19  import random
    20  import unittest
    21
    22  import wx
    23
    24  from timelinelib.calendar.gregorian.timetype import GregorianTimeType
    25
    26
    27 -class UnitTestCase(unittest.TestCase):
    28
    29      HALT_GUI = False
    30      AUTO_CLOSE = False
    31
    32 -    def assertPeriodsEqual(self, first, second, time_type=GregorianTimeType()):
    33          message = "Periods not equal.\n  First:  %s \"%s\"\n  Second: %s \"%s\"" % (
    34              first,
    35              time_type.format_period(first),
    36              second,
    37              time_type.format_period(second),
    38          )
    39          self.assertEqual(first, second, message)
    40
    41 -    def assertInstanceNotIn(self, object_, list_):
    42          for element in list_:
    43              if element is object_:
    44                  self.fail("%r was in list" % object_)
    45
    46 -    def assertEqNeImplementationIsCorrect(self, create_fn, modifiers):
    47          (modification_description, modifier_fn) = get_random_modifier(modifiers)
    48          one = modifier_fn(create_fn())
    49          other = modifier_fn(create_fn())
    50          fail_message_one_other = "%r vs %r (%s)" % (one, other,
    51                                                      modification_description)
    52          self.assertTrue(type(one) == type(other), fail_message_one_other)
    53          self.assertFalse(one is None, fail_message_one_other)
    54          self.assertTrue(one is not None, fail_message_one_other)
    55          self.assertTrue(one is not other, fail_message_one_other)
    56          self.assertFalse(one is other, fail_message_one_other)
    57          self.assertTrue(one == other, fail_message_one_other)
    58          self.assertFalse(one != other, fail_message_one_other)
    59          self.assertTrue(one == one, fail_message_one_other)
    60          self.assertFalse(one != one, fail_message_one_other)
    61          (modification_description, modifier_fn) = get_random_modifier(modifiers)
    62          modified = modifier_fn(other)
    63          fail_message_modified_one = "%r vs %r (%s)" % (modified, one,
    64                                                         modification_description)
    65          self.assertTrue(type(modified) == type(one), fail_message_modified_one)
    66          self.assertTrue(modified is not one, fail_message_modified_one)
    67          self.assertFalse(modified is one, fail_message_modified_one)
    68          self.assertTrue(modified != one, fail_message_modified_one)
    69          self.assertFalse(modified == one, fail_message_modified_one)
    70
    71 -    def show_dialog(self, dialog_class, *args, **kwargs):
    72          app = self.get_wxapp()
    73          try:
    74              dialog = dialog_class(*args, **kwargs)
    75              try:
    76                  if self.HALT_GUI:
    77                      if self.AUTO_CLOSE:
    78                          wx.CallLater(2000, dialog.Close)
    79                      dialog.ShowModal()
    80              finally:
    81                  dialog.Destroy()
    82          finally:
    83              if app.GetTopWindow():
    84                  app.GetTopWindow().Destroy()
    85              app.Destroy()
    86
    87 -    def get_wxapp(self):
    88          app = wx.App(False)
    89          import locale
    90          locale.setlocale(locale.LC_ALL, 'C')
    91          self.locale = wx.Locale()
    92          self.locale.Init(wx.LANGUAGE_DEFAULT)
    93          return app
    94
    95
    96 -def get_random_modifier(modifiers):
    97      return random.choice(modifiers)
    98