Skip to content

Improve test coverage #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 26, 2022
Merged

Conversation

ydirson
Copy link
Contributor

@ydirson ydirson commented Jul 29, 2022

This brings the test coverage from 38.4% to 66.6%, to help in checking the port to python3.

self.assertRegexpMatches(line, r"^(5a6,13$|>)")


class TestBootloaderAdHoc(unittest.TestCase):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if grub1 and extlinux are actually used nowadays.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too, but the code is still there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grub1 maybe not. extlinux, yes :-(


class TestAccessor(unittest.TestCase):
def test_http(self):
raise unittest.SkipTest("comment out if you really mean it")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain this in the commit message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@stormi
Copy link

stormi commented Jul 29, 2022

General comment: a few commit titles are longer than 70 chars (at XCP-ng it's the limit we try not to cross, and that's also when github starts eliding the displayed title). I think you could easily avoid it in most cases by simply prefixing the titles with "Coverage:" rather than "Improve coverage:" (maybe you'll also have to save a few chars here and there too).

@ydirson ydirson force-pushed the improve-test-coverage branch 2 times, most recently from c1e4eba to daeca57 Compare July 29, 2022 15:38
@ydirson ydirson force-pushed the improve-test-coverage branch from daeca57 to e1474df Compare August 8, 2022 15:15
@ydirson
Copy link
Contributor Author

ydirson commented Aug 8, 2022

General comment: a few commit titles are longer than 70 chars (at XCP-ng it's the limit we try not to cross, and that's also when github starts eliding the displayed title). I think you could easily avoid it in most cases by simply prefixing the titles with "Coverage:" rather than "Improve coverage:" (maybe you'll also have to save a few chars here and there too).

should be OK now

@psafont psafont self-requested a review August 9, 2022 08:27
@ydirson ydirson force-pushed the improve-test-coverage branch 2 times, most recently from d4acc74 to e314350 Compare August 9, 2022 12:31
Copy link
Member

@psafont psafont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really happy to see the tests being improved so much, even catching some bugs. I had a comment but it's not really related to the tests

# CpioFileCompat testing

def archiveExtractCompat(self, fn, comp):
arc = CpioFileCompat(fn, mode="r", compression={"": CPIO_PLAIN,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an enhancement it'd be nice to get a context manager to close the resource when reaching the end of the scope instead of forcing users to close them every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree. This feature has been added to tarfile.py in python3, and we should be able to get it, likely together with other goodies, but we would first have to sync with the 2.7 version, and we don't even have a clue which version was used as a base for this work :/

Copy link
Contributor

@andyhhp andyhhp Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 2.2. Please do feel free to nuke P <2.7-isms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but that will likely be for a separate PR, let's not mix this with the tests stuff :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to stay as close to upstream as possible, and get the <2.7-isms removed from cpython's tarfile first. We'll then get them into cpiofile by merging newer upstream versions.

@ydirson ydirson force-pushed the improve-test-coverage branch from e314350 to af3e5a0 Compare August 9, 2022 13:47
Adds more data to the archive (a copy of the same file, from another wd).
Uses the "." special case for even more coverage.

Coverage change:
xcp.cpiofile: 50% -> 51.7%
total: 38.4% -> 39%

Signed-off-by: Yann Dirson <[email protected]>
Coverage change:
xcp.cpiofile: 51.7% -> 58.1%
total: 39% -> 41.1%

Signed-off-by: Yann Dirson <[email protected]>
Coverage change:
xcp.pci: 40.9% -> 76.3%
total: 41.1% -> 43%

Signed-off-by: Yann Dirson <[email protected]>
Coverage change:
xcp.cmd: 0% -> 78.0%
total: 43% -> 44.2%

Signed-off-by: Yann Dirson <[email protected]>
Coverage change:
xcp.xmlunwrap: 0% -> 68.6%%
total: 44.2% -> 45.2%

Signed-off-by: Yann Dirson <[email protected]>
We may want to do some real checks on the output, this first version
only exercises the code.

Includes ad-hoc testing of write/read methods for grub/extlinux from a
grub2 configuration, for lack of representative versions of those
deprecated config files.

Ad-hoc test for extlinux reveals inconsistent typing, and is marked as
failing for now:

                print("serial %d %d" % (self.serial['port'],
 >                                       self.serial['baud']), file=fh)
 E               TypeError: %d format: a number is required, not str

Coverage change:
xcp.bootloader: 0% -> 59.1%%
total: 45.2% -> 53.4%

Signed-off-by: Yann Dirson <[email protected]>
File format parsers do not all agree whether to store some parameters as
int or str.  This relax the format strings to accept both.  Fixes creating
an extlinux config from a grub2 config.

Coverage change:
xcp.bootloader: 59.1% -> 72.8%
total: 53.4% -> 55.3%

Signed-off-by: Yann Dirson <[email protected]>
@ydirson ydirson force-pushed the improve-test-coverage branch 2 times, most recently from 89011f4 to d38a648 Compare August 30, 2022 14:02
Only FileAccessor is actually covered by these tests.  HTTPAccessor
tests are provided, but are skipped by default, as they currently need
network access to xcp-ng.org repository.  We will want at some point
to mock the HTTP access.

Coverage change:
xcp.accessor: 0% -> 30.0%
xcp.repository: 0% -> 72.2%
total: 55.3% -> 62.7%

Signed-off-by: Yann Dirson <[email protected]>
Coverage change:
xcp.environ: 0% -> 80.0%
total: 62.7% -> 63.3%

Signed-off-by: Yann Dirson <[email protected]>
Direct test execution only brings us dependency on `sys` :)

Signed-off-by: Yann Dirson <[email protected]>
Coverage change:
xcp.net.biosdevname: 41.5% to 87.8%
total: 63.3% -> 63.8%

Signed-off-by: Yann Dirson <[email protected]>
This function is private, not called, and if called would not do what the
docstring says (does not pass "eth" as argument to the command called).

Coverage change:
xcp.net.biosdevname: 87.8% -> 94.6%
total: 63.8% -> 63.9%

Signed-off-by: Yann Dirson <[email protected]>
Coverage change:
xcp.cpiofile: 58.1% -> 62.1%
total: 63.9% -> 65.2%

Signed-off-by: Yann Dirson <[email protected]>
Coverage change:
xcp.bootloader: 72.8% -> 81.9%
total: 65.4% -> 66.6%

Signed-off-by: Yann Dirson <[email protected]>
@ydirson ydirson force-pushed the improve-test-coverage branch from d38a648 to 056238e Compare September 26, 2022 11:48
@ydirson ydirson mentioned this pull request Sep 26, 2022
Copy link
Contributor

@edwintorok edwintorok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes/introduces test code, except for:

  • removal of some main from certain files and moving it into test code (ok)
  • changing some formats from %d to %s, apparently this fixes a bug in a unit test that previously was marked as FIXME, so this should be fine

@edwintorok edwintorok merged commit decbb50 into xenserver:master Sep 26, 2022
@ydirson ydirson deleted the improve-test-coverage branch September 29, 2022 13:21
bernhardkaindl added a commit to rosslagerwall/python-libs that referenced this pull request May 8, 2024
…5506-improve-tests

CP-45506: Verify that /etc/systemd does not have files(moved to tarball)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants