jinja
jinja copied to clipboard
Missing test coverage from pull request #1511?
As part of pull request #1511, the changes may have fixed a bug related to native type rendering for iterator; it could be worth adding test coverage related to that.
Before #1511, the code was calling itertools.islice(values, 2) to retrieve the head elements from a values collection (potentially of an iterator type) and then using itertools.chain(head, values) to subsequently produce output.
In the case where values is an iterator, I think that works correctly. But in cases where values is not an iterator, it can result in output duplication (something that I think #1511 indirectly resolves with this check).
For example:
>>> from itertools import islice
>>> values = [1,2,3,4]
>>> head = islice(values, 2)
>>> from itertools import chain
>>> list(chain(head, values))
[1, 2, 1, 2, 3, 4]
(note: opened this as a separate issue thread since the existing thread(s) have been locked)
Happy to consider a PR that fixes this or adds tests.
Work-in-progress at https://github.com/openculinary/jinja/tree/issue-1806/pr-1511-additional-test-coverage:
- [x] Test coverage to demonstrate that a problem could have occurred during
asyncrendering of templates containing native types - [ ] ~~Enable
asyncsupport forpytestandtox~~ (doesn't appear to be required; continuous integration already includes async unit test coverage)
Does the test coverage offered in #1807 seem reasonable for this? (that's one of my pull requests, and I'm trying to close/refresh a few that have been open for a while)
Seems fine, just haven't had time to get to merges here.