annotate tests/test-simplekeyvaluefile.py @ 31971:73e9328e5307

obsolescence: add test case D-3 for obsolescence markers exchange About 3 years ago, in August 2014, the logic to select what markers to select on push was ported from the evolve extension to Mercurial core. However, for some unclear reasons, the tests for that logic were not ported alongside. I realised it a couple of weeks ago while working on another push related issue. I've made a clean up pass on the tests and they are now ready to integrate the core test suite. This series of changesets do not change any logic. I just adds test for logic that has been around for about 10 versions of Mercurial. They are a patch for each test case. It makes it easier to review and postpone one with documentation issues without rejecting the wholes series. This patch introduce case D3: missing prune target (prune not in "pushed set") Each test case comes it in own test file. It help parallelism and does not introduce a significant overhead from having a single unified giant test file. Here are timing to support this claim. # Multiple test files version: # run-tests.py --local -j 1 test-exchange-*.t 53.40s user 6.82s system 85% cpu 1:10.76 total 52.79s user 6.97s system 85% cpu 1:09.97 total 52.94s user 6.82s system 85% cpu 1:09.69 total # Single test file version: # run-tests.py --local -j 1 test-exchange-obsmarkers.t 52.97s user 6.85s system 85% cpu 1:10.10 total 52.64s user 6.79s system 85% cpu 1:09.63 total 53.70s user 7.00s system 85% cpu 1:11.17 total
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Mon, 10 Apr 2017 16:54:43 +0200
parents c6921568cd20
children ed2c44741190
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31553
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
1 from __future__ import absolute_import
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
2
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
3 import unittest
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
4 import silenttestrunner
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
5
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
6 from mercurial import (
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
7 error,
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
8 scmutil,
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
9 )
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
10
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
11 class mockfile(object):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
12 def __init__(self, name, fs):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
13 self.name = name
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
14 self.fs = fs
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
15
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
16 def __enter__(self):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
17 return self
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
18
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
19 def __exit__(self, *args, **kwargs):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
20 pass
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
21
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
22 def write(self, text):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
23 self.fs.contents[self.name] = text
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
24
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
25 def read(self):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
26 return self.fs.contents[self.name]
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
27
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
28 class mockvfs(object):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
29 def __init__(self):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
30 self.contents = {}
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
31
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
32 def read(self, path):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
33 return mockfile(path, self).read()
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
34
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
35 def readlines(self, path):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
36 return mockfile(path, self).read().split('\n')
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
37
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
38 def __call__(self, path, mode, atomictemp):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
39 return mockfile(path, self)
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
40
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
41 class testsimplekeyvaluefile(unittest.TestCase):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
42 def setUp(self):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
43 self.vfs = mockvfs()
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
44
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
45 def testbasicwriting(self):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
46 d = {'key1': 'value1', 'Key2': 'value2'}
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
47 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d)
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
48 self.assertEqual(sorted(self.vfs.read('kvfile').split('\n')),
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
49 ['', 'Key2=value2', 'key1=value1'])
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
50
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
51 def testinvalidkeys(self):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
52 d = {'0key1': 'value1', 'Key2': 'value2'}
31585
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
53 self.assertRaises(error.ProgrammingError,
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
54 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write,
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
55 d)
31553
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
56 d = {'key1@': 'value1', 'Key2': 'value2'}
31585
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
57 self.assertRaises(error.ProgrammingError,
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
58 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write,
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
59 d)
31553
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
60
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
61 def testinvalidvalues(self):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
62 d = {'key1': 'value1', 'Key2': 'value2\n'}
31585
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
63 self.assertRaises(error.ProgrammingError,
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
64 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write,
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
65 d)
31553
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
66
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
67 def testcorruptedfile(self):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
68 self.vfs.contents['badfile'] = 'ababagalamaga\n'
31585
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
69 self.assertRaises(error.CorruptedState,
c6921568cd20 tests: make test-simplekeyvaluefile.py py2.6-compatible
Kostia Balytskyi <ikostia@fb.com>
parents: 31553
diff changeset
70 scmutil.simplekeyvaluefile(self.vfs, 'badfile').read)
31553
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
71
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
72 if __name__ == "__main__":
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
73 silenttestrunner.main(__name__)