Skip to content

Add tests for the datetime C API #80963

Closed

Description

@pganssle
BPO 36782
Nosy @vstinner, @ericvw, @Mariatta, @pganssle, @tonybaloney, @SimiCode
PRs
  • bpo-36782: Created C API wrappers and added missing tests for functions in the PyDateTimeAPI. #13088
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/Mariatta'
    closed_at = <Date 2019-05-27.23:36:05.321>
    created_at = <Date 2019-05-03.13:46:57.506>
    labels = ['easy', '3.8', 'type-feature', 'tests']
    title = 'Add tests for the datetime C API'
    updated_at = <Date 2019-05-27.23:36:05.316>
    user = 'https://github.com/pganssle'

    bugs.python.org fields:

    activity = <Date 2019-05-27.23:36:05.316>
    actor = 'vstinner'
    assignee = 'Mariatta'
    closed = True
    closed_date = <Date 2019-05-27.23:36:05.321>
    closer = 'vstinner'
    components = ['Tests']
    creation = <Date 2019-05-03.13:46:57.506>
    creator = 'p-ganssle'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36782
    keywords = ['patch', 'easy']
    message_count = 9.0
    messages = ['341336', '341346', '341400', '341408', '341497', '341673', '341674', '342761', '343705']
    nosy_count = 6.0
    nosy_names = ['vstinner', 'ericvw', 'Mariatta', 'p-ganssle', 'anthony shaw', 'edison.abahurire']
    pr_nums = ['13088']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue36782'
    versions = ['Python 3.8']

    Activity

    1. pganssle commented on May 3, 2019

      @pganssle
      MemberAuthor

      A decent fraction of the datetime C API has no tests. If we had tests, we could have prevented bpo bpo-36025, which was a regression in the FromTimestamp method.

      I would like to open this issue to suggest the addition of tests for the full interface, to prevent further regressions here.

      To write a test, first add a wrapper function in the _testcapimodule module: https://github.com/python/cpython/blob/master/Modules/_testcapimodule.c#L2218

      Then test that function here: https://github.com/python/cpython/blob/master/Lib/test/datetimetester.py#L5821

      See an example at GH PR 11922: #11922

      I recommend testing *both* the version of the function accessed by the Macro (e.g. PyDate_FromTimestamp) and from the C API capsule (e.g. PyDateTimeApi->FromTimestamp), since projects access these functions in both ways.

      C API Documentation is here: https://docs.python.org/3/c-api/datetime.html

      Currently untested:

      • PyDate_FromDate / PyDateTimeAPI->Date_FromDate
      • PyDateTime_FromDateAndTime / PyDateTimeAPI->DateTime_FromDateAndTime
      • PyDateTime_FromDateAndTimeAndFold / PyDateTimeAPI->DateTime_FromDateAndTimeAndFold
      • PyTime_FromTime -> PyDateTimeAPI->Time_FromTime
      • PyTime_FromTimeAndFold -> PyDateTime->Time_FromTimeAndFold
      • PyDelta_FromDSU / PyDateTime->Delta_FromDelta

      Untested macros with no corresponding API module:

      • PyDateTime_DATE_GET_YEAR

      • PyDateTime_DATE_GET_MONTH

      • PyDateTime_DATE_GET_DAY

      • PyDateTime_DATE_GET_HOUR

      • PyDateTime_DATE_GET_MINUTE

      • PyDateTime_DATE_GET_SECOND

      • PyDateTime_DATE_GET_MICROSECOND

      • PyDateTime_DELTA_GET_DAYS

      • PyDateTime_DELTA_GET_SECONDS

      • PyDateTime_DELTA_GET_MICROSECONDS

      I can spawn smaller issues for this if that's preferred, but I figured we'd start with this big meta-issue.

    2. added
      3.9 (EOL)
      3.8 (EOL)
      tests
      type-feature
      on May 3, 2019
    3. pganssle commented on May 3, 2019

      @pganssle
      MemberAuthor

      This ticket should be reserved for the mentored sprint.

    4. tonybaloney commented on May 4, 2019

      tonybaloneymannequin
      Mannequin

      Reserving this issue (in mentored sprint)

    5. simicode commented on May 4, 2019

      simicodemannequin
      Mannequin

      I have done PyDate_FromDate in #57297

    6. simicode commented on May 6, 2019

      simicodemannequin
      Mannequin

      I have done PyDateTime_FromDateAndTime. I'm moving on to add PyDateTime_FromDateAndTimeAndFold (plus documentation for fold as requested in https://bugs.python.org/issue36783) before making a PR.

    7. simicode commented on May 7, 2019

      simicodemannequin
      Mannequin

      I have submitted PR (under review) for these tests:

      • PyDate_FromDate / PyDateTimeAPI->Date_FromDate
      • PyDateTime_FromDateAndTime / PyDateTimeAPI->DateTime_FromDateAndTime
      • PyDateTime_FromDateAndTimeAndFold / PyDateTimeAPI->DateTime_FromDateAndTimeAndFold
      • PyTime_FromTime -> PyDateTimeAPI->Time_FromTime
      • PyTime_FromTimeAndFold -> PyDateTime->Time_FromTimeAndFold
      • PyDelta_FromDSU / PyDateTime->Delta_FromDelta
    8. simicode commented on May 7, 2019

      simicodemannequin
      Mannequin

      @p-ganssle
      Please open a new bpo for the Untested macros. I will be happy to work on that in the sprints tomorrow.

    9. vstinner commented on May 17, 2019

      @vstinner
      Member

      New changeset 98ff4d5 by Victor Stinner (Edison A) in branch 'master':
      bpo-36782: Created C API wrappers and added missing tests for functions in the PyDateTimeAPI. (bpo-13088)
      98ff4d5

    10. vstinner commented on May 27, 2019

      @vstinner
      Member

      Paul Ganssle is in favor of backporting new tests to Python 3.7:
      #13088 (comment)

      But automated backports failed with a conflict. If someone wants to backport it manually, please go ahead!

      In the meanwhile, I close the issue.

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.8 (EOL)easyteststype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions