|
9 | 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10 | 10 | # See the License for the specific language governing permissions and
|
11 | 11 | # limitations under the License.
|
| 12 | +import abc |
| 13 | +import typing |
12 | 14 |
|
13 | 15 |
|
14 |
| -class Module: |
15 |
| - _host = None |
| 16 | +class Module(metaclass=abc.ABCMeta): |
| 17 | + if typing.TYPE_CHECKING: |
| 18 | + import testinfra.host |
| 19 | + |
| 20 | + _host: testinfra.host.Host |
16 | 21 |
|
17 | 22 | @classmethod
|
18 | 23 | def get_module(cls, _host):
|
19 | 24 | klass = cls.get_module_class(_host)
|
20 | 25 | return type(
|
21 | 26 | klass.__name__,
|
22 | 27 | (klass,),
|
23 |
| - { |
24 |
| - "_host": _host, |
25 |
| - "run": _host.run, |
26 |
| - "run_expect": _host.run_expect, |
27 |
| - "run_test": _host.run_test, |
28 |
| - "check_output": _host.check_output, |
29 |
| - "find_command": _host.find_command, |
30 |
| - }, |
| 28 | + {"_host": _host}, |
31 | 29 | )
|
32 | 30 |
|
33 | 31 | @classmethod
|
34 | 32 | def get_module_class(cls, host):
|
35 | 33 | return cls
|
36 | 34 |
|
| 35 | + @classmethod |
| 36 | + def run(cls, *args, **kwargs): |
| 37 | + return cls._host.run(*args, **kwargs) |
| 38 | + |
| 39 | + @classmethod |
| 40 | + def run_test(cls, *args, **kwargs): |
| 41 | + return cls._host.run_test(*args, **kwargs) |
| 42 | + |
| 43 | + @classmethod |
| 44 | + def run_expect(cls, *args, **kwargs): |
| 45 | + return cls._host.run_expect(*args, **kwargs) |
| 46 | + |
| 47 | + @classmethod |
| 48 | + def check_output(cls, *args, **kwargs): |
| 49 | + return cls._host.check_output(*args, **kwargs) |
| 50 | + |
| 51 | + @classmethod |
| 52 | + def find_command(cls, *args, **kwargs): |
| 53 | + return cls._host.find_command(*args, **kwargs) |
| 54 | + |
37 | 55 |
|
38 | 56 | class InstanceModule(Module):
|
39 | 57 | @classmethod
|
|
0 commit comments