Mercurial > hgsubversion
annotate tests/run.py @ 1455:8cfe074cd463
maps: use util.fileproperty for RevMap.lastpulled
It simplifies code a lot, and will avoid code duplication for the upcoming
SqliteRevMap.
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 13 Jun 2016 17:02:06 +0100 |
parents | 4217a050a088 |
children | dcf9eff9b5b7 |
rev | line source |
---|---|
1052
025de18d652b
tests: make our test runner executable
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents:
1047
diff
changeset
|
1 #!/usr/bin/env python |
025de18d652b
tests: make our test runner executable
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents:
1047
diff
changeset
|
2 |
610
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
3 import optparse |
16
48a44546c12f
Add a basic system for running the hgsubversion tests (although not the svnwrap ones) without requiring Nose. Nose is still the recommended way to run the tests.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
4 import os |
48a44546c12f
Add a basic system for running the hgsubversion tests (although not the svnwrap ones) without requiring Nose. Nose is still the recommended way to run the tests.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
5 import sys |
1452
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
6 |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
7 if sys.version_info[:2] < (2, 7): |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
8 import unittest2 as unittest |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
9 else: |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
10 import unittest |
394
d70c8e45cb9e
tests: add -A option to run.py for running comprehensive tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
393
diff
changeset
|
11 |
16
48a44546c12f
Add a basic system for running the hgsubversion tests (although not the svnwrap ones) without requiring Nose. Nose is still the recommended way to run the tests.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
12 if __name__ == '__main__': |
610
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
13 description = ("This script runs the hgsubversion tests. If no tests are " |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
14 "specified, all known tests are implied.") |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
15 parser = optparse.OptionParser(usage="%prog [options] [TESTS ...]", |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
16 description=description) |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
17 parser.add_option("-A", "--all", |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
18 dest="comprehensive", action="store_true", default=False, |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
19 help="include slow, but comprehensive tests") |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
20 parser.add_option("-v", "--verbose", |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
21 dest="verbose", action="store_true", default=False, |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
22 help="enable verbose output") |
614
4f6017ba4d3d
testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
613
diff
changeset
|
23 parser.add_option("", "--no-demandimport", |
4f6017ba4d3d
testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
613
diff
changeset
|
24 dest="demandimport", action="store_false", default=True, |
4f6017ba4d3d
testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
613
diff
changeset
|
25 help="disable Mercurial demandimport loading") |
682
52fbb272a147
tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
653
diff
changeset
|
26 parser.add_option("", "--bindings", |
52fbb272a147
tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
653
diff
changeset
|
27 dest="bindings", action="store", default=None, |
52fbb272a147
tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
653
diff
changeset
|
28 choices=["swig", "subvertpy"], |
52fbb272a147
tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
653
diff
changeset
|
29 help="test using the specified bindings (swig or " |
52fbb272a147
tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
653
diff
changeset
|
30 "subvertpy)") |
688
073132fc27f1
tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
684
diff
changeset
|
31 parser.add_option("", "--show-stdout", |
073132fc27f1
tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
684
diff
changeset
|
32 dest="showstdout", action="store_true", default=False, |
073132fc27f1
tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
684
diff
changeset
|
33 help="show stdout (hidden by default)") |
357
d19843ac13c9
Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
347
diff
changeset
|
34 |
610
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
35 (options, args) = parser.parse_args() |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
36 |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
37 if options.verbose: |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
38 testargs = { 'descriptions': 3, 'verbosity': 2 } |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
39 else: |
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
40 testargs = {'descriptions': 2} |
303
f423a8780832
Minor tweaks to how the tests are run.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
174
diff
changeset
|
41 |
615
edd112855189
tests/run.py: make sure our hgsubversion loads correctly
Augie Fackler <durin42@gmail.com>
parents:
614
diff
changeset
|
42 sys.path.append(os.path.dirname(os.path.dirname(__file__))) |
edd112855189
tests/run.py: make sure our hgsubversion loads correctly
Augie Fackler <durin42@gmail.com>
parents:
614
diff
changeset
|
43 |
614
4f6017ba4d3d
testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
613
diff
changeset
|
44 if options.demandimport: |
4f6017ba4d3d
testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
613
diff
changeset
|
45 from mercurial import demandimport |
4f6017ba4d3d
testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
613
diff
changeset
|
46 demandimport.enable() |
4f6017ba4d3d
testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
613
diff
changeset
|
47 |
682
52fbb272a147
tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
653
diff
changeset
|
48 if options.bindings: |
697
e9306b23d323
testrunner: don't use os.putenv(), as it may not affect os.environ.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
688
diff
changeset
|
49 os.environ['HGSUBVERSION_BINDINGS'] = options.bindings |
682
52fbb272a147
tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
653
diff
changeset
|
50 |
644
95abc4cfc78f
tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
629
diff
changeset
|
51 # make sure our copy of hgsubversion gets imported by loading test_util |
95abc4cfc78f
tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
629
diff
changeset
|
52 import test_util |
95abc4cfc78f
tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
629
diff
changeset
|
53 test_util.TestBase |
95abc4cfc78f
tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
629
diff
changeset
|
54 |
338
47c0110046dc
tests: silence tests when using run.py
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
337
diff
changeset
|
55 # silence output when running outside nose |
688
073132fc27f1
tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
684
diff
changeset
|
56 if not options.showstdout: |
073132fc27f1
tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
684
diff
changeset
|
57 import tempfile |
073132fc27f1
tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
684
diff
changeset
|
58 sys.stdout = tempfile.TemporaryFile() |
338
47c0110046dc
tests: silence tests when using run.py
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
337
diff
changeset
|
59 |
1452
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
60 args = [os.path.basename(os.path.splitext(arg)[0]).replace('-', '_') |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
61 for arg in args] |
357
d19843ac13c9
Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
347
diff
changeset
|
62 |
1043
69a9fb45cad5
tests: consolidate all test-loading into the test runner
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents:
1042
diff
changeset
|
63 loader = unittest.TestLoader() |
69a9fb45cad5
tests: consolidate all test-loading into the test runner
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents:
1042
diff
changeset
|
64 suite = unittest.TestSuite() |
69a9fb45cad5
tests: consolidate all test-loading into the test runner
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents:
1042
diff
changeset
|
65 |
357
d19843ac13c9
Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
347
diff
changeset
|
66 if not args: |
1452
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
67 suite = loader.discover('.') |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
68 |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
69 if options.comprehensive: |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
70 suite.addTests(loader.discover('comprehensive', |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
71 top_level_dir='comprehensive')) |
357
d19843ac13c9
Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
347
diff
changeset
|
72 else: |
1452
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
73 sys.path.append(os.path.join(os.path.dirname(__file__), 'comprehensive')) |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
74 |
4217a050a088
tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1052
diff
changeset
|
75 suite.addTests(loader.loadTestsFromNames(args)) |
357
d19843ac13c9
Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
347
diff
changeset
|
76 |
610
300b917d23c5
testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
577
diff
changeset
|
77 runner = unittest.TextTestRunner(**testargs) |
1043
69a9fb45cad5
tests: consolidate all test-loading into the test runner
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents:
1042
diff
changeset
|
78 result = runner.run(suite) |
571
f3e5ef8760cb
tests.run: exit nonzero if tests did not pass
Augie Fackler <durin42@gmail.com>
parents:
426
diff
changeset
|
79 if not result.wasSuccessful(): |
f3e5ef8760cb
tests.run: exit nonzero if tests did not pass
Augie Fackler <durin42@gmail.com>
parents:
426
diff
changeset
|
80 sys.exit(1) |