Skip to content

Commit 683178d

Browse files
committed
Remove some magic from module bound to host instantiation
This silent mypy errors about modules not having attributes run, check_output, etc I think this should still need work to be more readable/understandable.
1 parent 7c7bdec commit 683178d

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

testinfra/modules/base.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,49 @@
99
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
12+
import abc
13+
import typing
1214

1315

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
1621

1722
@classmethod
1823
def get_module(cls, _host):
1924
klass = cls.get_module_class(_host)
2025
return type(
2126
klass.__name__,
2227
(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},
3129
)
3230

3331
@classmethod
3432
def get_module_class(cls, host):
3533
return cls
3634

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+
3755

3856
class InstanceModule(Module):
3957
@classmethod

0 commit comments

Comments
 (0)