comparison tests/comprehensive/test_sqlite_revmap.py @ 1474:f21605bcda24

tests: add the sqlite revmap test The SqliteRevMap test generates new tests based on existing tests. The generated tests will use SqliteRevMap instead of RevMap. Tests are selected if they are both interesting and fast. For comprehensive tests like rebuildmeta and updatemeta, only a few svndumps are selected. On my laptop vm, the sqlite revmap test completes within 6.2s. Note: the current way tests are running will not gc the database connections well, meaning it can leak fd. Fortunately it's only 55 tests now. If we add a lot more tests in the future, be aware of the fd leak issue.
author Jun Wu <quark@fb.com>
date Fri, 27 May 2016 15:48:16 +0100
parents
children
comparison
equal deleted inserted replaced
1473:623af04c6e06 1474:f21605bcda24
1 import os
2 import unittest
3 import sys
4
5 # wrapped in a try/except because of weirdness in how
6 # run.py works as compared to nose.
7 try:
8 import test_util
9 except ImportError:
10 sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
11 import test_util
12
13 # interesting and fast tests
14 import test_fetch_mappings
15 import test_fetch_renames
16 import test_pull
17 import test_template_keywords
18 import test_utility_commands
19
20 # comprehensive tests
21 try:
22 import test_custom_layout
23 except ImportError:
24 sys.path.insert(0, os.path.dirname(__file__))
25 import test_custom_layout
26
27 import test_rebuildmeta
28 import test_updatemeta
29
30 from hgsubversion import svnmeta, maps
31
32
33 class SqliteRevMapMixIn(object):
34 # do not double the test size by being wrapped again
35 obsolete_mode_tests = False
36 stupid_mode_tests = False
37
38 def setUp(self):
39 assert svnmeta.SVNMeta._defaultrevmapclass is maps.RevMap
40 svnmeta.SVNMeta._defaultrevmapclass = maps.SqliteRevMap
41 super(SqliteRevMapMixIn, self).setUp()
42
43 def tearDown(self):
44 assert svnmeta.SVNMeta._defaultrevmapclass is maps.SqliteRevMap
45 svnmeta.SVNMeta._defaultrevmapclass = maps.RevMap
46 super(SqliteRevMapMixIn, self).tearDown()
47
48 def shortDescription(self):
49 text = super(SqliteRevMapMixIn, self).shortDescription()
50 if text:
51 text += ' (sqlite revmap)'
52 return text
53
54 def buildtestclass(cls, selector=None):
55 name = 'SqliteRevMap%s' % cls.__name__
56 newcls = type(name, (SqliteRevMapMixIn, cls,), {})
57
58 # remove test cases not selected by selector
59 if selector:
60 for name in dir(newcls):
61 if name.startswith('test_') and not selector(name[5:]):
62 setattr(newcls, name, None)
63
64 globals()[name] = newcls
65
66 def svndumpselector(name):
67 return name in ['branch_rename_to_trunk',
68 'tag_name_same_as_branch']
69
70 buildtestclass(test_fetch_mappings.MapTests)
71 buildtestclass(test_fetch_renames.TestFetchRenames)
72 buildtestclass(test_pull.TestPull)
73 buildtestclass(test_template_keywords.TestLogKeywords)
74 buildtestclass(test_utility_commands.UtilityTests)
75
76 buildtestclass(test_rebuildmeta.RebuildMetaTests, svndumpselector)
77 buildtestclass(test_updatemeta.UpdateMetaTests, svndumpselector)