Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 273:6abd41f7d879
Unit-tests for almost all currently implemented features of the timestamps extension.
BUGS: Missing testing commits with explicit files given.
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Fri, 04 Jan 2019 22:09:06 +0100 |
| parents | 1c78d1cbe91a |
| children | 0b8907d3e411 |
| files | tests/lib-stat.py tests/test-timestamps.t |
| diffstat | 2 files changed, 124 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/lib-stat.py Fri Jan 04 22:09:06 2019 +0100 @@ -0,0 +1,56 @@ +from __future__ import absolute_import, print_function + + +import sys +import os +import datetime + + +class FloatTimesInStat(object): + """Context manager to ensure that stat returns float values. + + For 3.7 <= Mercurial < 4.6: Mercurial calls :func:`os.stat_float_times` + for `stat` and friends to return :class:`int` values. + + Temporarily fix this. + + """ + + __slots__ = ("_do_reset",) + + def __init__(self): + self._do_reset = False + + def __enter__(self): + if not os.stat_float_times(): + os.stat_float_times(True) + self._do_reset = True + return self + + def __exit__(self, *args): + if self._do_reset: + os.stat_float_times(False) + + +def to_isoformat(t): + """Return the POSIX timestamp `t` formatted in full ISO format. + + `t` is expected to be in the UTC timezone. + + """ + dt = datetime.datetime.utcfromtimestamp(t) + if dt.utcoffset() is None: + return dt.isoformat() + "Z" + else: + return dt.isoformat() + + +def main(): + with FloatTimesInStat(): + for f in sys.argv[1:]: + st = os.lstat(f) + print(to_isoformat(st.st_mtime)) + + +if __name__ == "__main__": + main()
--- a/tests/test-timestamps.t Fri Jan 04 21:26:23 2019 +0100 +++ b/tests/test-timestamps.t Fri Jan 04 22:09:06 2019 +0100 @@ -3,6 +3,18 @@ $ . $TESTDIR/lib-test-timestamps.sh +Determine a python executable for usage in the shell + + >>> from __future__ import print_function, absolute_import + >>> import io, os, sys + >>> if sys.version_info[0] < 3: + ... u = unicode + ... else: + ... u = str + >>> with io.open(os.path.join(os.environ["TESTTMP"], "tspy"), "wt", encoding="us-ascii") as tspy: + ... print(u(sys.executable), file=tspy, end=u('')) + $ TSPY=`cat $TESTTMP/tspy`; export TSPY + 2. Create a test repository with output check ============================================= @@ -51,11 +63,65 @@ 8 +2. Test with updates and reverts +================================ + + $ prepare_repo "ts2" + $ cd ts2 + +Updating ... + + $ hg id -n + 8 + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test1.txt + 2017-12-01T02:03:04Z + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test2.txt + 2017-12-01T08:09:10Z + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test3.txt + 2017-12-01T05:06:07Z + $ hg update --quiet -r7 + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test1.txt + 2017-12-01T02:03:04Z + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test2.txt + 2017-12-01T07:08:09Z + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test4-2.txt + 2017-12-01T06:07:08Z + $ hg update --quiet -r4 + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test1.txt + 2017-12-01T02:03:04Z + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test2.txt + 2017-12-01T04:05:06Z + +Reverting ... + + $ hg update --quiet -rtip + $ hg id -n + 8 + $ echo CHANGED... >files/test1.txt + $ hg st + M files/test1.txt + $ hg revert -C files/test1.txt + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test1.txt + 2017-12-01T02:03:04Z + $ hg st + $ echo "CHANGED 2 ..." >files/test1.txt + $ echo "CHANGED 2 ..." >>files/test2.txt + $ hg st + M files/test1.txt + M files/test2.txt + $ hg revert --all -C --quiet + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test1.txt + 2017-12-01T02:03:04Z + $ "$TSPY" "$TESTDIR/lib-stat.py" files/test2.txt + 2017-12-01T08:09:10Z + $ cd .. + + 3. Test a failing merge ======================= - $ prepare_repo "ts2" - $ cd ts2 + $ prepare_repo "ts3" + $ cd ts3 $ hg merge -r7 --tool=:merge3 merging .hgtimestamps.db merging files/test2.txt
