Example #1
0
    def setUp(self):
        """\
        Initialise parts of wxGlade only
        """
        # initialise path settings
        if self.init_stage1:
            wxglade.init_stage1()

        # initialise sizers, widgets, codewriter
        wxglade.init_stage2(use_gui=self.init_use_gui)

        # initialise wxGlade configuration
        import config
        config.init_preferences()

        # set some useful preferences
        config.preferences.autosave = False
        config.preferences.write_timestamp = False
        config.preferences.show_progress = False

        # initiate empty structure to store files and there content
        self.vFiles = {}

        # replace some original implementations by test specific implementation
        self.orig_save_file = common.save_file
        common.save_file = self._save_file
        self.orig_load_file = codegen.BaseSourceFileContent._load_file 
        codegen.BaseSourceFileContent._load_file = self._load_lines
        self.orig_file_exists = codegen.BaseCodeWriter._file_exists 
        self.orig_os_access = os.access
        os.access = self._os_access
        self.orig_os_makedirs = os.makedirs
        os.makedirs = self._os_makedirs
        self.orig_os_path_isdir = os.path.isdir
        os.path.isdir = self._os_path_isdir
        codegen.BaseCodeWriter._file_exists = self._file_exists
        codegen.BaseCodeWriter._show_warnings = False

        # set own version string to prevent diff mismatches
        common.version = '"faked test version"'

        # Determinate case directory
        self.caseDirectory = os.path.join(
            os.path.dirname(__file__),
            self.caseDirectory,
            )
Example #2
0
 def setUpClass(cls):
     logging.disable(logging.WARNING)
     wxglade.init_stage1(options=None)
     #wxglade.init_localization()
     wxglade.init_stage2(False)
Example #3
0
def run_tests():
    "Create test suites and run all tests"

    # evaluate command line options first
    parser = OptionParser(
        usage="%prog [options]  Test wxGlade components",
    )
    parser.set_defaults(kind='cli')
    parser.add_option(
        '-g',
        '--gui',
        action='store_const',
        dest='kind',
        const='gui',
        help=_('Test GUI components instead of non-GUI components'),
    )
    parser.add_option(
        '-c',
        '--compile',
        action='store_const',
        dest='kind',
        const='compile',
        help=_('Compile generated C++ source code'),
    )

    options = parser.parse_args()[0]

    suites = []

    # disable logging first because the initialisation logs path details and
    # other details
    logging.disable(logging.WARNING)
    wxglade.init_stage1()
    wxglade.init_localization()
    wxglade.init_stage2(options.kind == 'gui')

    # select proper wxversion
    if options.kind == 'gui' and compat.IS_CLASSIC:
        # import proper wx-module using wxversion
        if not hasattr(sys, "frozen") and 'wx' not in sys.modules:
            try:
                import wxversion
                wxversion.ensureMinimal('2.8')
            except ImportError:
                print(_('Please install missing Python module "wxversion".'))
                sys.exit(1)
            except wxversion.VersionError:
                print(_('The requested wxPython version is not found. Disable GUI tests.'))
                sys.exit()

    if options.kind == 'gui':
        modules = ['test_gui.py']
        import wx
        i = wx.Locale(wx.LANGUAGE_DEFAULT)
    elif options.kind == 'compile':
        modules = ['test_compile.py']
    else:                               # options.kind == 'cli'
        modules = ['test_external.py', 'test_codegen.py', 'test_bugs.py', ]


    # try to import all files as modules
    for module_name in modules:

        module_name = os.path.splitext(module_name)[0]
        fp, path, info = imp.find_module(module_name, ['./tests'])
        try:
            module = imp.load_module(module_name, fp, path, info)
        finally:
            # Make sure fp is closed properly
            if fp:
                fp.close()

        # search all test cases in the loaded module
        suites.append(unittest.findTestCases(module))

    # summarise all suites and run tests
    all_tests = unittest.TestSuite(suites)
    unittest.TextTestRunner(verbosity=2).run(all_tests)