Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit e1e5e09

Browse files
committed
tests: Rearrange virtconv test files.
Split everything into input or output dirs. Don't maintain file lists in the test code: every input file should at least not crash if converted to a valid output format.
1 parent 0fa08e5 commit e1e5e09

5 files changed

Lines changed: 49 additions & 32 deletions

File tree

File renamed without changes.

tests/virtconv-files/vmx2virtimage/test.virt-image renamed to tests/virtconv-files/virtimage_output/vmx2virtimage_test1.virt-image

File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/virtconv-test.py

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,79 @@
1919
import os, os.path, glob
2020
import tests
2121

22-
vmx2virtimage_dir = "tests/virtconv-files/vmx2virtimage"
23-
vmx2virtimage_files = [ "test" ]
22+
BASE = "tests/virtconv-files"
2423

25-
virtimage2vmx_dir = "tests/virtconv-files/virtimage2vmx"
26-
virtimage2vmx_files = [ "image" ]
24+
vmx_input = BASE + "/vmx_input"
25+
vmx_output = BASE + "/vmx_output"
2726

28-
# For x2x conversion, we want to use already tested output, since ideally
29-
# we should be able to run a generated config continually through the
30-
# converter and it will generate the same result
31-
vmx2vmx_dirs = [ virtimage2vmx_dir ]
32-
virtimage2virtimage_dirs = [ vmx2virtimage_dir ]
27+
virtimage_input = BASE + "/virtimage_input"
28+
virtimage_output = BASE + "/virtimage_output"
3329

3430
class TestVirtConv(unittest.TestCase):
3531

3632
def setUp(self):
3733
pass
3834

39-
def _convert_helper(self, dirname, filebase, input_type, output_type):
40-
infile = os.path.join(dirname, filebase + "." + input_type)
41-
outfile = os.path.join(dirname, filebase + "." + output_type)
42-
35+
def _convert_helper(self, infile, outfile, in_type, out_type):
4336
inp = virtconv.formats.find_parser_by_file(infile)
44-
outp = virtconv.formats.parser_by_name(output_type)
37+
outp = virtconv.formats.parser_by_name(out_type)
4538

46-
if not inp or inp.name != input_type:
39+
if not inp or inp.name != in_type:
4740
raise AssertionError("find_parser_by_file for '%s' returned "
4841
"wrong parser type.\n"
4942
"Expected: %s\n"
5043
"Received: %s\n" % \
51-
(infile, input_type,
44+
(infile, in_type,
5245
str((not inp) and str(inp) or inp.name)))
5346

5447
vmdef = inp.import_file(infile)
5548
out_expect = outp.export(vmdef)
5649
tests.diff_compare(out_expect, outfile)
5750

51+
def _build_compare_path(self, base, in_path, out_dir, out_type):
52+
out_path = os.path.basename(in_path).rsplit(".", 1)[0]
53+
return "%s/%s_%s.%s" % (out_dir, base, out_path, out_type)
54+
55+
def _compare_files(self, base, in_type, out_type, in_dir, out_dir):
56+
for in_path in glob.glob(os.path.join(in_dir, "*." + in_type)):
57+
if in_type != out_type:
58+
out_path = self._build_compare_path(base, in_path,
59+
out_dir, out_type)
60+
else:
61+
out_path = in_path
62+
self._convert_helper(in_path, out_path, in_type, out_type)
63+
5864
def testVMX2VirtImage(self):
59-
for filename in vmx2virtimage_files:
60-
self._convert_helper(vmx2virtimage_dir, filename,
61-
"vmx", "virt-image")
65+
base = "vmx2virtimage"
66+
in_type = "vmx"
67+
out_type = "virt-image"
68+
in_dir = vmx_input
69+
out_dir = virtimage_output
6270

63-
def testVMX2VMX(self):
64-
for dirname in vmx2vmx_dirs:
65-
for filepath in glob.glob(os.path.join(dirname, "*.vmx")):
66-
filename = os.path.splitext(os.path.basename(filepath))[0]
67-
self._convert_helper(dirname, filename, "vmx", "vmx")
71+
self._compare_files(base, in_type, out_type, in_dir, out_dir)
6872

6973
def testVirtImage2VMX(self):
70-
for filename in virtimage2vmx_files:
71-
self._convert_helper(virtimage2vmx_dir, filename,
72-
"virt-image", "vmx")
74+
base = "virtimage2vmx"
75+
in_type = "virt-image"
76+
out_type = "vmx"
77+
in_dir = virtimage_input
78+
out_dir = vmx_output
79+
80+
self._compare_files(base, in_type, out_type, in_dir, out_dir)
81+
82+
# For x2x conversion, we want to use already tested output, since ideally
83+
# we should be able to run a generated config continually through the
84+
# converter and it will generate the same result
85+
def testVMX2VMX(self):
86+
base = None
87+
in_type = out_type = "vmx"
88+
in_dir = out_dir = vmx_output
89+
90+
self._compare_files(base, in_type, out_type, in_dir, out_dir)
7391

7492
def testVirtImage2VirtImage(self):
75-
for dirname in virtimage2virtimage_dirs:
76-
for filepath in glob.glob(os.path.join(dirname, "*.virt-image")):
77-
filename = os.path.splitext(os.path.basename(filepath))[0]
78-
self._convert_helper(dirname, filename, "virt-image",
79-
"virt-image")
93+
base = None
94+
in_type = out_type = "virt-image"
95+
in_dir = out_dir = virtimage_output
8096

97+
self._compare_files(base, in_type, out_type, in_dir, out_dir)

0 commit comments

Comments
 (0)