Repository navigation
r.timestamp: Add pytest test suite - #7802
Conversation
|
Hi, and thanks for your PR. Please note that we are moving tests from unittests to pytest. So, new tests should be written using pytest. Since you are using AI, please note that there are Agent instructions in the repo. So please make use of them. |
|
@ninsbl Thanks for the feedback! I've updated the PR to use The old I ran the full suite against a real GRASS session and all 8 tests pass. |
r.timestamp had no test coverage. Add a gunittest-based test suite covering reading a map with no timestamp, setting/reading absolute dates and date ranges, overwriting, removing, invalid date input, and non-existent maps for both the read and write code paths.
6dffd3f to
3a39474
Compare
|
@ninsbl, can you review it? |
ninsbl
left a comment
There was a problem hiding this comment.
Thanks for rewriting it with pytest.
Some more comments:
- there are no tests that include time, please add some
- you are often creating a
rastermap as part of the test. That is probably better included in a fixure. Maybe @echoix or @wenzeslaus know what would be best practice here... - There have been questions about handling of timezone information, which - to my knowledge - r.timestamp does not do. I would say having a test failing if timezone information is included would be good, as demonstration, clarification and target if that should be changed at some point in future...
Replace the gunittest-style test_r_timestamp.py with a pytest version in tests/, using the shared session_tools fixture from raster/conftest.py instead of the NC SPM sample dataset, per AGENTS.md guidance to prefer pytest when NC SPM is not required.
…ture Address review feedback on the pytest suite: - Add a conftest.py with a raster fixture that creates a fresh, timestamp-less raster in the current mapset, replacing the r_mapcalc call repeated at the top of every test. - Add parametrized tests for time-of-day granularity (hour, hour:minute, hour:minute:second, fractional seconds). - Add tests for timezone offsets, including on both ends of a date range. r.timestamp's own get/set round-trip preserves timezone information correctly; the known gap (OSGeoGH-7166) is in grass.temporal's conversion of timestamps to Python datetime objects, a separate code path this tool does not use.
171af47 to
e22591f
Compare
|
@ninsbl I've pushed an update addressing all three points: Time-of-day tests — added a parametrized test covering hour-only, hour:minute, hour:minute:second, and fractional-second granularity, since the format function handles each of those as a separate case. Raster setup moved to a fixture — added a Timezone handling — I actually tested this directly (set a timestamp with All 15 tests pass against a real GRASS session. |
echoix
left a comment
There was a problem hiding this comment.
Could there be something to make sure there isn't a future mix up between American style 12 hour times and 24 hour times? I only saw times in the 10:30 range (except a round trip using a timezone).
Reviewer noted nearly all time-of-day test values used hour 10, which reads the same in 12-hour and 24-hour notation, so a future mix-up between the two conventions would not be caught. - Add test_set_and_read_midnight_and_noon, covering hour 00:00 and 12:00. These are the two values where a naive 24h-to-12h conversion classically breaks (0 % 12 == 12 % 12 == 0), so pinning down the correct round-trip there is more targeted than testing an arbitrary hour. - Add test_twelve_hour_am_pm_suffix_is_rejected, confirming "2:30 pm" / "02:30 PM" style input raises an error rather than being silently reinterpreted. The format is documented as 24-hour only (hour 0-23).
|
@echoix Good point, and it made me look more closely at why hour 10 wasn't a great choice rather than just picking a different arbitrary hour. Pushed an update:
Both pass against a real GRASS session, 19 tests total now. One thing worth flagging for future scope, not this PR: |
Please do, if you're able to make pytests from the exposed c api, and have the bandwidth to do so. (Probably from our bindings (based on ctypes, the same way Python functions access the c api). It would probably be cleaner and real unit tests, not integration tests. Start with something reviewable, as there are not many of these kinds of tests, so we might need to iterate a bit to find a good pattern |
|
@echoix @ninsbl If this PR looks good otherwise, can we move forward with it? |
Summary
r.timestamphad no test coverage. This adds a pytest suite (tests/r_timestamp_test.py) covering:date=none8 tests total. Uses the shared
session_toolsfixture fromraster/conftest.py(same oner.colors's tests use) instead of a local setup, perAGENTS.md's guidance to write new tests in pytest when the NC SPM sample dataset isn't needed.Testing
Ran the suite against a real
main-branch GRASS session (osgeo/grass-gis:main-alpineDocker image) — all 8 tests pass. Checked formatting/lint with the pinnedruffversion from.pre-commit-config.yaml(v0.15.17).AI disclosure
I used AI assistance (Claude) to draft and verify these tests, then reviewed and tested them myself as described above.