annotate tests/test-storage.py @ 53042:cdd7bf612c7b stable tip

bundle-spec: properly format boolean parameter (issue6960) This was breaking automatic clone bundle generation. This changeset fixes it and add a test to catch it in the future.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 11 Mar 2025 02:29:42 +0100
parents e6069f84abbb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1 # This test verifies the conformance of various classes to various
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
2 # storage interfaces.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
3
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
4 import silenttestrunner
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
5
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
6 from mercurial import (
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
7 error,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
8 filelog,
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
9 revlog,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
10 transaction,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
11 ui as uimod,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
12 vfs as vfsmod,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
13 )
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
14
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
15 from mercurial.testing import storage as storagetesting
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
16
51227
f9a52a9603f9 tests: ignore test-storage when using Rust
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48875
diff changeset
17
f9a52a9603f9 tests: ignore test-storage when using Rust
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48875
diff changeset
18 try:
40326
fed697fa1734 sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
19 from mercurial import zstd
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
20
40326
fed697fa1734 sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
21 zstd.__version__
fed697fa1734 sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
22 except ImportError:
fed697fa1734 sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
23 zstd = None
fed697fa1734 sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
24
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
25 STATE = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
26 'lastindex': 0,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
27 'ui': uimod.ui(),
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
28 'vfs': vfsmod.vfs(b'.', realpath=True),
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
29 }
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
30
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
31
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
32 def makefilefn(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
33 """Factory for filelog instances."""
39953
a3a9b93bff80 py3: byteify test-storage.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39772
diff changeset
34 fl = filelog.filelog(STATE['vfs'], b'filelog-%d' % STATE['lastindex'])
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
35 STATE['lastindex'] += 1
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
36 return fl
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
37
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
38
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
39 def maketransaction(self):
40320
9b2e1b00ee94 tests: use byte literals in test-storage.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40056
diff changeset
40 vfsmap = {b'plain': STATE['vfs'], b'store': STATE['vfs']}
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
41
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
42 return transaction.transaction(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
43 STATE['ui'].warn, STATE['vfs'], vfsmap, b'journal', b'undo'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
44 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
45
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
46
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
47 def addrawrevision(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
48 self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
49 fl,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
50 tr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
51 node,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
52 p1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
53 p2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
54 linkrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
55 rawtext=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
56 delta=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
57 censored=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
58 ellipsis=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
59 extstored=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
60 ):
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
61 flags = 0
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
62
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
63 if censored:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
64 flags |= revlog.REVIDX_ISCENSORED
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
65 if ellipsis:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
66 flags |= revlog.REVIDX_ELLIPSIS
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
67 if extstored:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
68 flags |= revlog.REVIDX_EXTSTORED
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
69
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
70 if rawtext is not None:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
71 fl._revlog.addrawrevision(rawtext, tr, linkrev, p1, p2, node, flags)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
72 elif delta is not None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
73 fl._revlog.addrawrevision(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
74 rawtext, tr, linkrev, p1, p2, node, flags, cachedelta=delta
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
75 )
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
76 else:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
77 raise error.Abort('must supply rawtext or delta arguments')
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
78
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
79 # We may insert bad data. Clear caches to prevent e.g. cache hits to
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
80 # bypass hash verification.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
81 fl._revlog.clearcaches()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39953
diff changeset
82
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
83
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
84 # Assigning module-level attributes that inherit from unittest.TestCase
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
85 # is all that is needed to register tests.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
86 filelogindextests = storagetesting.makeifileindextests(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
87 makefilefn, maketransaction, addrawrevision
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
88 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
89 filelogdatatests = storagetesting.makeifiledatatests(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
90 makefilefn, maketransaction, addrawrevision
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
91 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
92 filelogmutationtests = storagetesting.makeifilemutationtests(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
93 makefilefn, maketransaction, addrawrevision
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
94 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40453
diff changeset
95
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
96 if __name__ == '__main__':
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
97 silenttestrunner.main(__name__)