annotate tests/comprehensive/test_stupid_pull.py @ 1056:0932bb4d8870

tests: add a metaclass for triggering stupid on a class level We use a metaclass similar to the tests for obsolete mode. This metaclass deliberately duplicates each test for each mode; enabling both means that each test function is run four times. This makes it less likely that a fix is accidentally applied to replay mode only, as new tests will often automatically cover both modes. However, as certiain features remain deliberately unimplemented in stupid modes -- filemaps being a notable example -- we also add a decorator function for marking methods testing them. We do this for reasons of both consistency and coverage; we avoid littering the tests with *_stupid variants, and thus are less likely to forget adding them. I already found a couple of bugs in stupid mode thanks to this increased coverage.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 09 Aug 2013 23:34:16 +0200
parents 903c9c9dfe6a
children cd256960b622
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 import os
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 import pickle
766
124cd25de4ef tests: fix running the comprehensive tests using nose.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
3 import sys
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 import unittest
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 from mercurial import hg
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 from mercurial import ui
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8
613
58f397523604 testrunner: delay and `simplify' importing of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 499
diff changeset
9 # wrapped in a try/except because of weirdness in how
58f397523604 testrunner: delay and `simplify' importing of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 499
diff changeset
10 # run.py works as compared to nose.
58f397523604 testrunner: delay and `simplify' importing of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 499
diff changeset
11 try:
58f397523604 testrunner: delay and `simplify' importing of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 499
diff changeset
12 import test_util
58f397523604 testrunner: delay and `simplify' importing of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 499
diff changeset
13 except ImportError:
766
124cd25de4ef tests: fix running the comprehensive tests using nose.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
14 sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
124cd25de4ef tests: fix running the comprehensive tests using nose.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
15 import test_util
613
58f397523604 testrunner: delay and `simplify' importing of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 499
diff changeset
16
354
36d26e158748 comprehensive: fix for new repo layout.
Augie Fackler <durin42@gmail.com>
parents: 347
diff changeset
17 from hgsubversion import wrappers
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
20 def _do_case(self, name, layout):
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 subdir = test_util.subdir.get(name, '')
867
50c13e01c7e3 test_util: add a load_and_fetch() returning the repo_path
Patrick Mezard <patrick@mezard.eu>
parents: 833
diff changeset
22 repo, repo_path = self.load_and_fetch(name, subdir=subdir, stupid=False,
50c13e01c7e3 test_util: add a load_and_fetch() returning the repo_path
Patrick Mezard <patrick@mezard.eu>
parents: 833
diff changeset
23 layout=layout)
1048
903c9c9dfe6a tests: count revisions explicitly
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1044
diff changeset
24 assert test_util.repolen(self.repo) > 0, \
903c9c9dfe6a tests: count revisions explicitly
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1044
diff changeset
25 'Repo had no changes, maybe you need to add a subdir entry in test_util?'
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 wc2_path = self.wc_path + '_stupid'
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 u = ui.ui()
867
50c13e01c7e3 test_util: add a load_and_fetch() returning the repo_path
Patrick Mezard <patrick@mezard.eu>
parents: 833
diff changeset
28 checkout_path = repo_path
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 if subdir:
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 checkout_path += '/' + subdir
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 257
diff changeset
31 u.setconfig('hgsubversion', 'stupid', '1')
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
32 u.setconfig('hgsubversion', 'layout', layout)
816
86d124a8768e Fix hg.clone() calls changed by d976542986d2
Patrick Mezard <pmezard@gmail.com>
parents: 766
diff changeset
33 test_util.hgclone(u, test_util.fileurl(checkout_path), wc2_path, update=False)
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
34 if layout == 'single':
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
35 self.assertEqual(len(self.repo.heads()), 1)
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 self.repo2 = hg.repository(ui.ui(), wc2_path)
445
24a8471069c0 tests: test for heads equality instead of branchtags
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 383
diff changeset
37 self.assertEqual(self.repo.heads(), self.repo2.heads())
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
40 def buildmethod(case, name, layout):
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
41 m = lambda self: self._do_case(case, layout)
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 m.__name__ = name
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
43 m.__doc__ = 'Test stupid produces same as real on %s. (%s)' % (case, layout)
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44 return m
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46 attrs = {'_do_case': _do_case,
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 }
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 for case in (f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')):
892
3bfb7e985c47 svn verify: add a test for corrupt repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 867
diff changeset
49 if case == 'corrupt.svndump':
3bfb7e985c47 svn verify: add a test for corrupt repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 867
diff changeset
50 continue
902
7d9cd708f412 tests: fix automatically generated test names
Bryan O'Sullivan <bryano@fb.com>
parents: 892
diff changeset
51 name = 'test_' + case[:-len('.svndump')].replace('-', '_')
821
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 816
diff changeset
52 # Automatic layout branchtag collision exposes a minor defect
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 816
diff changeset
53 # here, but since it isn't a regression we suppress the test case.
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 816
diff changeset
54 if case != 'branchtagcollision.svndump':
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 816
diff changeset
55 attrs[name] = buildmethod(case, name, 'auto')
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
56 name += '_single'
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
57 attrs[name] = buildmethod(case, name, 'single')
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 445
diff changeset
58
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 821
diff changeset
59 StupidPullTests = type('StupidPullTests', (test_util.TestBase,), attrs)