Skip to content

tests: add CalendarSpec unit tests#141

Merged
bmr-cymru merged 9 commits intomainfrom
bmr-calendarspec-tests
Mar 20, 2025
Merged

tests: add CalendarSpec unit tests#141
bmr-cymru merged 9 commits intomainfrom
bmr-calendarspec-tests

Conversation

@bmr-cymru
Copy link
Copy Markdown
Contributor

Add unit tests for the CalendarSpec class, based on the systemd
calendarspec tests at:

https://github.com/systemd/systemd/blob/main/src/test/test-calendarspec.c

Resolves: #122

Add a thin wrapper around the 'systemd-analyze calendar` command:
The CalendarSpec() class accepts a calendarspec string formatted
according to systemd.time(8):CALENDAR EVENTS.

Resolves: #121
This triggers false positives for many of out functions and methods:
disable it to avoid noise and unnecessary failures in CI.

Related: #121
Add unit tests for the CalendarSpec class, based on the systemd
calendarspec tests at:

  https://github.com/systemd/systemd/blob/main/src/test/test-calendarspec.c

Resolves: #122
There are two test cases in CalendarSpecTests that each have a large
(~50 entries) table of individual calls to either the _test_one() or
_test_next() methods.

Refactor this so that instead of individual calls we iterate over a list
of tuples comprising the input data and expected output, and call the
test methods under the context manager 'with self.subTest()'.

This generates a unique index for each subtest which is reported with
any failures, as well as a custom message that includes the input data
to the test.

This makes debugging easier since it makes it explicitly clear which
test case has failed.

Related: #122
@bmr-cymru bmr-cymru force-pushed the bmr-calendarspec-tests branch from c5dc40a to 9f11fb8 Compare March 20, 2025 20:04
The libfaketime package is not available in CentOS or RHEL: build
require the libfaketime package only if building on Fedora.

Related: #122
The _test_next() method relies on patching CalendarSpec to call
systemd-analyze under the faketime command to set the starting time of
the test.

Skip this test if the faketime command is unavailable at runtime.

Related: #122
@packit-as-a-service
Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/snapshotmanager-snapm-141
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

1 similar comment
@packit-as-a-service
Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/snapshotmanager-snapm-141
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

Ubuntu ships the /usr/bin/faketime binary in a separate 'faketime'
package: add this to the dependencies in snapm.yaml.

Without this package the test_calendar_spec_next test is skipped:

tests/test_calendar.py::CalendarSpecTests::test_calendar_spec_next SKIPPED [  5%]

Related: #122.
@bmr-cymru bmr-cymru merged commit 31f8c1f into main Mar 20, 2025
12 of 14 checks passed
@bmr-cymru bmr-cymru deleted the bmr-calendarspec-tests branch May 30, 2025 16:45
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.

CalendarSpec unit tests

1 participant