Cover the libvirt helper and its CLI - #101
Merged
Merged
Conversation
eroussy
approved these changes
Sep 14, 2026
39 unit tests against a fake connection, no daemon. helpers/libvirt.py goes from 65% to 100%. test_libvirt_manager.py keeps driving a real qemu:///system. What is added here is what a daemon will not produce on demand: the crashed and PM-suspended domain states, the console handover and the XML export. Only libvirt.open() is replaced, so the VIR_DOMAIN_* constants under test are the ones the daemon reports. Signed-off-by: Florent Carli <florent.carli@rte-france.com>
18 unit tests driving main() through argv against a recording manager. helpers/libvirt_cmd.py goes from 0% to 94%. The two spots left are the __main__ guard and the fall-through of the command chain, which argparse makes unreachable. Signed-off-by: Florent Carli <florent.carli@rte-france.com>
insatomcat
force-pushed
the
libvirt-unit-coverage
branch
from
September 14, 2026 12:03
fbc64ef to
b6b99ac
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Last of the three PRs on the helpers.
helpers/libvirt.pygoes from 65% to 100% andhelpers/libvirt_cmd.pyfrom 0% to 94%, in 57 unit tests, with no libvirt daemon. The two modules travel together because they are 55 uncovered statements between them, too little to be worth splitting.test_libvirt_manager.pystill drives a realqemu:///systemand is untouched. What is added covers what a daemon will not produce on demand: a crashed or PM-suspended domain, the console handover to virsh, the XML export. Onlylibvirt.open()is replaced, so a test asserting onVIR_DOMAIN_PMSUSPENDEDasserts on the value the daemon reports; the constants and exception types still come from the real module, through a__getattr__fall-through on the fake.libvirt_cmdis driven throughsys.argvagainst a recording manager. The two spots left uncovered are the__main__guard and the fall-through of the command chain, which argparse makes unreachable. Both also stand uncovered invm_manager_cmd.py, and neither is worth a coverage exclusion.No production code changes, and no defect found in either module this time.
Twelve mutations are all caught, among them the word each domain state maps to, the
VIR_DOMAIN_UNDEFINE_NVRAMandVIR_DOMAIN_DEFINE_VALIDATEflags, the autostart value, theCalledProcessErrorthe console swallows, theshell=Trueof the export, and the argument orderlibvirt_cmd exportpasses on.Independent of #99 and #100. With the three merged, the project reaches roughly 99% statement coverage, past the OpenSSF gold target of 90%.