qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v8 2/5] iotests: add testenv.py


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [PATCH v8 2/5] iotests: add testenv.py
Date: Tue, 26 Jan 2021 11:28:09 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1

26.01.2021 01:05, Kevin Wolf wrote:
Am 23.01.2021 um 22:04 hat Vladimir Sementsov-Ogievskiy geschrieben:
Add TestEnv class, which will handle test environment in a new python
iotests running framework.

Don't add compat=1.1 for qcow2 IMGOPTS, as v3 is default anyway.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
  tests/qemu-iotests/testenv.py | 278 ++++++++++++++++++++++++++++++++++
  1 file changed, 278 insertions(+)
  create mode 100644 tests/qemu-iotests/testenv.py

diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
new file mode 100644
index 0000000000..348af593e9
--- /dev/null
+++ b/tests/qemu-iotests/testenv.py
@@ -0,0 +1,278 @@
+# TestEnv class to manage test environment variables.
+#
+# Copyright (c) 2020-2021 Virtuozzo International GmbH
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import os
+import sys
+import tempfile
+from pathlib import Path
+import shutil
+import collections
+import random
+import subprocess
+import glob
+from contextlib import AbstractContextManager
+from typing import Dict, Any, Optional
+
+
+def get_default_machine(qemu_prog: str) -> str:
+    outp = subprocess.run([qemu_prog, '-machine', 'help'], check=True,
+                          universal_newlines=True,
+                          stdout=subprocess.PIPE).stdout
+
+    machines = outp.split('\n')
+    default_machine = next(m for m in machines if m.endswith(' (default)'))
+    default_machine = default_machine.split(' ', 1)[0]
+
+    alias_suf = ' (alias of {})'.format(default_machine)
+    alias = next((m for m in machines if m.endswith(alias_suf)), None)
+    if alias is not None:
+        default_machine = alias.split(' ', 1)[0]
+
+    return default_machine
+
+
+class TestEnv(AbstractContextManager['TestEnv']):

I'm getting CI failures here:

Traceback (most recent call last):
   File "./check", line 23, in <module>
     from testenv import TestEnv
   File "/builds/.../qemu/tests/qemu-iotests/testenv.py", line 49, in <module>
     class TestEnv(AbstractContextManager['TestEnv']):
TypeError: 'ABCMeta' object is not subscriptable

On the other hand, if I make it just AbstractContextManager without
giving the type parameter, mypy complains:

testenv.py:49: error: Missing type parameters for generic type "ContextManager"

I guess I need to have another look into this tomorrow.

It may help to use typing.ContextManager instead of AbstractContextManager. 
mypy is OK with it, probably CI will be OK too..


By the way, mypy --strict still finds a few errors. I think we want to
address at least the warnings about missing type annotatings and calling
untyped functions.


OK


--
Best regards,
Vladimir



reply via email to

[Prev in Thread] Current Thread [Next in Thread]