|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a simple registry containing the available test framework |
|
8 interfaces. |
|
9 """ |
|
10 |
|
11 import copy |
|
12 |
|
13 |
|
14 class UTFrameworkRegistry(): |
|
15 """ |
|
16 Class implementing a simple registry of test framework interfaces. |
|
17 |
|
18 The test executor for a framework is responsible for running the tests, |
|
19 receiving the results and preparing them for display. It must implement |
|
20 the interface of UTExecutorBase. |
|
21 |
|
22 Frameworks must first be registered using '.register()'. This registry |
|
23 can then create the assoicated test executor when '.createExecutor()' is |
|
24 called. |
|
25 """ |
|
26 def __init__(self): |
|
27 """ |
|
28 Constructor |
|
29 """ |
|
30 self.__frameworks = {} |
|
31 |
|
32 def register(self, executorClass): |
|
33 """ |
|
34 Public method to register a test framework executor. |
|
35 |
|
36 @param executorClass class implementing the test framework executor |
|
37 @type UTExecutorBase |
|
38 """ |
|
39 self.__frameworks[executorClass.name] = executorClass |
|
40 |
|
41 def createExecutor(self, framework, widget, logfile=None): |
|
42 """ |
|
43 Public method to create a test framework executor. |
|
44 |
|
45 Note: The executor classes have to be registered first. |
|
46 |
|
47 @param framework name of the test framework |
|
48 @type str |
|
49 @param widget reference to the unit test widget |
|
50 @type UnittestWidget |
|
51 @param logfile file name to log test results to (defaults to None) |
|
52 @type str (optional) |
|
53 @return test framework executor object |
|
54 """ |
|
55 cls = self.__frameworks[framework] |
|
56 return cls(widget, logfile=logfile) |
|
57 |
|
58 def getFrameworks(self): |
|
59 """ |
|
60 Public method to get a copy of the registered frameworks. |
|
61 |
|
62 @return copy of the registered frameworks |
|
63 @rtype dict |
|
64 """ |
|
65 return copy.copy(self.__frameworks) |