src/eric7/eric7_testing.py

branch
eric7-maintenance
changeset 10349
df7edc29cbfb
parent 10272
7ae72d1df070
parent 10303
ee1aadab1215
child 10460
3b34efa2857c
equal deleted inserted replaced
10273:e075c8fe07fd 10349:df7edc29cbfb
10 This is the main Python script that performs the necessary initialization 10 This is the main Python script that performs the necessary initialization
11 of the testing module and starts the Qt event loop. This is a standalone 11 of the testing module and starts the Qt event loop. This is a standalone
12 version of the integrated testing module. 12 version of the integrated testing module.
13 """ 13 """
14 14
15 import argparse
15 import os 16 import os
16 import sys 17 import sys
17 18
18 from PyQt6.QtGui import QGuiApplication 19 from PyQt6.QtGui import QGuiApplication
19 20
20 for arg in sys.argv[:]:
21 if arg.startswith("--config="):
22 from eric7 import Globals
23 21
24 configDir = arg.replace("--config=", "") 22 def createArgparseNamespace():
25 Globals.setConfigDir(configDir) 23 """
26 sys.argv.remove(arg) 24 Function to create an argument parser.
27 elif arg.startswith("--settings="):
28 from PyQt6.QtCore import QSettings
29 25
30 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) 26 @return created argument parser object
31 if not os.path.isdir(settingsDir): 27 @rtype argparse.ArgumentParser
32 os.makedirs(settingsDir) 28 """
33 QSettings.setPath( 29 from eric7.UI.Info import Version
34 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir
35 )
36 sys.argv.remove(arg)
37 30
38 from eric7.Globals import AppInfo 31 # 1. create the argument parser
32 parser = argparse.ArgumentParser(
33 description="Graphical tool of the eric tool suite to execute unit tests.",
34 epilog="Copyright (c) 2002 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.",
35 )
36
37 # 2. add the arguments
38 parser.add_argument(
39 "-V",
40 "--version",
41 action="version",
42 version="%(prog)s {0}".format(Version),
43 help="show version information and exit",
44 )
45 parser.add_argument(
46 "--config",
47 metavar="config_dir",
48 help="use the given directory as the one containing the config files",
49 )
50 parser.add_argument(
51 "--settings",
52 metavar="settings_dir",
53 help="use the given directory to store the settings files",
54 )
55 parser.add_argument(
56 "file",
57 nargs="?",
58 help="test script",
59 )
60
61 # 3. create the Namespace object by parsing the command line
62 args = parser.parse_args()
63 return args
64
65
66 args = createArgparseNamespace()
67 if args.config:
68 from eric7 import Globals
69
70 Globals.setConfigDir(args.config)
71 if args.settings:
72 from PyQt6.QtCore import QSettings
73
74 SettingsDir = os.path.expanduser(args.settings)
75 if not os.path.isdir(SettingsDir):
76 os.makedirs(SettingsDir)
77 QSettings.setPath(
78 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir
79 )
80
39 from eric7.Toolbox import Startup 81 from eric7.Toolbox import Startup
40 82
41 # make Python debug client available as a package repository (needed for 'coverage') 83 # make Python debug client available as a package repository (needed for 'coverage')
42 sys.path.insert(2, os.path.join(os.path.dirname(__file__), "DebugClients", "Python")) 84 sys.path.insert(2, os.path.join(os.path.dirname(__file__), "DebugClients", "Python"))
43 85
44 86
45 def createMainWidget(argv): 87 def createMainWidget(args):
46 """ 88 """
47 Function to create the main widget. 89 Function to create the main widget.
48 90
49 @param argv list of commandline parameters 91 @param args namespace object containing the parsed command line parameters
50 @type list of str 92 @type argparse.Namespace
51 @return reference to the main widget 93 @return reference to the main widget
52 @rtype QWidget 94 @rtype QWidget
53 """ 95 """
54 from eric7.Testing.TestingWidget import TestingWindow 96 from eric7.Testing.TestingWidget import TestingWindow
55 97
56 try: 98 return TestingWindow(args.file)
57 fn = argv[1]
58 except IndexError:
59 fn = None
60 return TestingWindow(fn)
61 99
62 100
63 def main(): 101 def main():
64 """ 102 """
65 Main entry point into the application. 103 Main entry point into the application.
66 """ 104 """
67 QGuiApplication.setDesktopFileName("eric7_testing") 105 QGuiApplication.setDesktopFileName("eric7_testing")
68 106
69 options = [ 107 res = Startup.appStartup(args, createMainWidget)
70 (
71 "--config=configDir",
72 "use the given directory as the one containing the config files",
73 ),
74 (
75 "--settings=settingsDir",
76 "use the given directory to store the settings files",
77 ),
78 ]
79 appinfo = AppInfo.makeAppInfo(
80 sys.argv, "eric Testing", "file", "Graphical test application", options
81 )
82 res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget)
83 sys.exit(res) 108 sys.exit(res)
84 109
85 110
86 if __name__ == "__main__": 111 if __name__ == "__main__":
87 main() 112 main()

eric ide

mercurial