Mercurial > hg
annotate tests/mockmakedate.py @ 42742:334c1ea57136
discovery: new devel.discovery.randomize option
By default, this is True, but setting it to False is a uniform
way to kill all randomness in integration tests such as test-setdiscovery.t
By "uniform" we mean that it can be passed to implementations in other
languages, for which the monkey-patching of random.sample would be
irrelevant.
In the above mentioned test file, we use it right away,
replacing the adhoc extension that had the same purpose, and to derandomize a
case with many round-trips, that we'll need to behave uniformly in the Rust
version.
Differential Revision: https://phab.mercurial-scm.org/D6427
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Tue, 21 May 2019 17:44:15 +0200 |
parents | 704a3aa3dc0a |
children | 2372284d9457 |
rev | line source |
---|---|
41213
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
1 # mock out util.makedate() to supply testable values |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
2 |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
3 from __future__ import absolute_import |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
4 |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
5 import os |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
6 |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
7 from mercurial import pycompat |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
8 from mercurial.utils import dateutil |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
9 |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
10 def mockmakedate(): |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
11 filename = os.path.join(os.environ['TESTTMP'], 'testtime') |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
12 try: |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
13 with open(filename, 'rb') as timef: |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
14 time = float(timef.read()) + 1 |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
15 except IOError: |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
16 time = 0.0 |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
17 with open(filename, 'wb') as timef: |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
18 timef.write(pycompat.bytestr(time)) |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
19 return (time, 0) |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
20 |
704a3aa3dc0a
histedit: add rewrite.update-timestamp support to fold and mess
Taapas Agrawal <taapas2897@gmail.com>
parents:
diff
changeset
|
21 dateutil.makedate = mockmakedate |