Skip to content

gh-107862: Add property tests for strftime/strptime - #124550

Draft
pganssle wants to merge 14 commits into
python:mainfrom
pganssle:strftime_hypothesis
Draft

pganssle wants to merge 14 commits into
python:mainfrom
pganssle:strftime_hypothesis

Conversation

@pganssle

@pganssle pganssle commented Sep 25, 2024 •

Copy link
Copy Markdown
Member

This adds a new test for strptime / strftime that uses hypothesis to ensure that some inverse relationships hold. While creating it I found several bugs: #124531, #124529 and #124549.

I am hoping this could be useful with #120752

To Do:

  • Add stubs to make sure this works without hypothesiis
  • Configure this the same way test_zoneinfo_property is configured so that it is run separately against the C and Python implementations.

@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Sep 25, 2024
@StanFromIreland StanFromIreland changed the title gh-NNNNNN: Add property tests for strftime/strptime gh-107862: Add property tests for strftime/strptime Sep 16, 2025
@StanFromIreland

Copy link
Copy Markdown
Member

Attached Hypothesis meta issue #107862

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

Add the missing timezones strategy stub and an explicit example so the
test runs without Hypothesis installed. Use the C locale for the example
to keep the composite format independent of the ambient locale.
Add a separate pure-Python test class using the same properties as the
C implementation. Give its strptime module matching Python timezone
classes and restore the module cache when the tests finish.
Correct the round-trip preconditions and preserve the minimized failures
as explicit examples. Generate delimited fields, account for ignored week
numbers and two-digit years, and keep locale composites in the C locale.
Check small years and ambiguous fields against independent expected values.
Construct numeric, ordinal, ISO-week and calendar-week inputs without
strftime, and compare parsed fields against date arithmetic. Keep leap
days, year boundaries and the two-digit-year pivot as explicit examples.
Check fractional precision and signed offset components independently of
datetime equality. Cover colon and compact spellings, Z, naive inputs,
negative zero and offsets immediately inside the 24-hour boundary.
Mutate otherwise valid dates into impossible calendar dates, out-of-range
clock fields and offsets, malformed fractions and incomplete ISO dates.
Check ValueError without treating permissive but valid spellings as errors.
Use independent C-locale name tables and exercise case variants, 12-hour
clock boundaries and Unicode whitespace. Keep NUL, surrogate, percent
and regex punctuation literals in the parser domain even where libc
strftime cannot round-trip them.
Compare date, time, datetime and struct_time results against independently
constructed fields. Cover partial-input defaults, discarded components,
ISO and ordinal dates, and agreeing redundant directives.
Week 53 and ordinal day 366 can normalize into the following year while
tm_yday remains relative to the input year. Preserve the independently
calculated date and day-of-year assertions as an expected failure until
this inconsistency is resolved.
Conflicting repeated years should raise ValueError, but compiling the
format leaks re.PatternError for the duplicate named group. Keep this
failure separate from the passing mixed-directive property.
Parse localized names while switching from C to an available non-C
locale and back. Build numeric fields independently, including years
below 1000, and restore the caller locale after the test.
Permute agreeing date, clock and offset representations and compare the
result with independently known fields. Cover calendar versus ISO years,
12-hour versus 24-hour clocks and both numeric offset directives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news stale Stale PR or inactive for long period of time. tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants