Skip to content

Add infrastucture for asserting a series of related values within a single test. #112

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

Closed
wants to merge 2 commits into from

Conversation

albu-diku
Copy link
Contributor

No description provided.

@albu-diku albu-diku mentioned this pull request Aug 20, 2024
@albu-diku albu-diku force-pushed the test/assert-multiple-values branch from 9b982d4 to 6d7741d Compare August 24, 2024 14:00
In out desired use of the test suite is a requirement to allow writing
a test that is the same assertion agianst a series of related values.
As an example, imagine an operation on chunks and wishing to assert
multiple sizes.

This is obviously something to be extremely careful in promoting given
it is in a fair amount of conflict with the notion of separate test
cases, which experience says more "generally" leads to better outcomes.
However, used judiciously this can be useful, and this is far better
supported by a mechanism designed to support it: namely, that _all_
failures are reported up front rather than the first failing assertion
cancelling the test block and the ending up in a fix-and-rerun cycle.

Add a facility and associated assertion to the test support library
that allows executing an operation and its assertion against a series
of values, buffers any exceptions that occurs and enforce that either
a no exception or all exception outcome is asserted by end of test.

Include a mechanism to the support library so arbitrary objects can do
checks and use this in multi-value assertions to ensure a result is
validated by its containing case.
@albu-diku albu-diku force-pushed the test/assert-multiple-values branch from 6d7741d to 6f6ec2a Compare August 24, 2024 14:08
@albu-diku albu-diku marked this pull request as ready for review August 24, 2024 14:12
@jonasbardino jonasbardino added enhancement New feature or request unit test labels Aug 31, 2024
@jonasbardino jonasbardino self-assigned this Aug 31, 2024
@@ -3,7 +3,6 @@
#
# --- BEGIN_HEADER ---
#
# support - helper functions for unit testing
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-pick: these should stay to fit existing template. I've left them in when merging.

# -- END_HEADER ---
#

"""Infrastruture to support assertion over a range of values.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-pick: one-line docstrings shouldn't add newline according to PEP8.
https://peps.python.org/pep-0008/#documentation-strings

class NoCasesError(AssertionError):
pass

class AssertOver:
Copy link
Contributor

Choose a reason for hiding this comment

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

Classes are slightly ashamed to stand around bare-naked, without even a docstring ;-)

@@ -0,0 +1,41 @@
import unittest
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing license header. I'll add one here, but perhaps you could make a PR to do the same in the test_support, test_boolean and any other tests modules where I've missed them?

return self._attempts.append(attempt_info)

def to_check_callable(self):
def raise_unless_consuted():
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll fix this typo during merge and sprinkle in a few missing docstrings.

def record_attempt(self, attempt_info):
return self._attempts.append(attempt_info)

def to_check_callable(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This nested method without direct statements looks a bit strange to me, please at least document it for my sake.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah no, it does return the function call ... but still it would like a docstring.

@jonasbardino
Copy link
Contributor

Merged through svn with a number of minor corrections as mentioned in review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants