Mercurial > hg
annotate mercurial/testing/__init__.py @ 47456:93f4e183b3f5
deltas: at a `target_rev` parameter to finddeltainfo
Otherwise, recomputing a delta for a revision might result in a delta against a
later revision or a full snapshot thinking we are appending a new revision.
We will make use of this during censoring (and later, stripping).
Differential Revision: https://phab.mercurial-scm.org/D10887
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 20 Jun 2021 23:05:58 +0200 |
parents | 52cee44aa1a0 |
children | 2dac94edd98d |
rev | line source |
---|---|
46984
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
1 from __future__ import ( |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
2 absolute_import, |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
3 division, |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
4 ) |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
5 |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
6 import os |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
7 import time |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
8 |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
9 |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
10 # work around check-code complains |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
11 # |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
12 # This is a simple log level module doing simple test related work, we can't |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
13 # import more things, and we do not need it. |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
14 environ = getattr(os, 'environ') |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
15 |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
16 |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
17 def _timeout_factor(): |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
18 """return the current modification to timeout""" |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
19 default = int(environ.get('HGTEST_TIMEOUT_DEFAULT', 1)) |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
20 current = int(environ.get('HGTEST_TIMEOUT', default)) |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
21 return current / float(default) |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
22 |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
23 |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
24 def wait_file(path, timeout=10): |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
25 timeout *= _timeout_factor() |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
26 start = time.time() |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
27 while not os.path.exists(path): |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
28 if time.time() - start > timeout: |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
29 raise RuntimeError(b"timed out waiting for file: %s" % path) |
99c629101b73
testing: add a utility function to wait for file create
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39772
diff
changeset
|
30 time.sleep(0.01) |
46985
52cee44aa1a0
testing: add a `write_file` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46984
diff
changeset
|
31 |
52cee44aa1a0
testing: add a `write_file` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46984
diff
changeset
|
32 |
52cee44aa1a0
testing: add a `write_file` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46984
diff
changeset
|
33 def write_file(path, content=b''): |
52cee44aa1a0
testing: add a `write_file` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46984
diff
changeset
|
34 with open(path, 'wb') as f: |
52cee44aa1a0
testing: add a `write_file` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46984
diff
changeset
|
35 f.write(content) |