~justin-fathomdb/nova/bug744150

« back to all changes in this revision

Viewing changes to run_tests.py

  • Committer: Andy Smith
  • Date: 2011-01-18 23:51:13 UTC
  • mfrom: (579 nova)
  • mto: This revision was merged to the branch mainline in revision 581.
  • Revision ID: code@term.ie-20110118235113-ivu21efg3h9z6niq
merge from upstream and fix small issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
 
 
4
 
# Copyright 2010 United States Government as represented by the
5
 
# Administrator of the National Aeronautics and Space Administration.
6
 
# All Rights Reserved.
7
 
#
8
 
#    Licensed under the Apache License, Version 2.0 (the "License");
9
 
#    you may not use this file except in compliance with the License.
10
 
#    You may obtain a copy of the License at
11
 
#
12
 
#        http://www.apache.org/licenses/LICENSE-2.0
13
 
#
14
 
#    Unless required by applicable law or agreed to in writing, software
15
 
#    distributed under the License is distributed on an "AS IS" BASIS,
16
 
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 
#    See the License for the specific language governing permissions and
18
 
#    limitations under the License.
19
 
 
20
 
import gettext
21
 
import os
22
 
import unittest
23
 
import sys
24
 
 
25
 
from nose import config
26
 
from nose import result
27
 
from nose import core
28
 
 
29
 
gettext.install('nova', unicode=1)
30
 
 
31
 
from nova.db import migration
32
 
 
33
 
 
34
 
class NovaTestResult(result.TextTestResult):
35
 
    def __init__(self, *args, **kw):
36
 
        result.TextTestResult.__init__(self, *args, **kw)
37
 
        self._last_case = None
38
 
 
39
 
    def getDescription(self, test):
40
 
        return str(test)
41
 
 
42
 
    def startTest(self, test):
43
 
        unittest.TestResult.startTest(self, test)
44
 
        current_case = test.test.__class__.__name__
45
 
 
46
 
        if self.showAll:
47
 
            if current_case != self._last_case:
48
 
                self.stream.writeln(current_case)
49
 
                self._last_case = current_case
50
 
 
51
 
            self.stream.write(
52
 
                '    %s' % str(test.test._testMethodName).ljust(60))
53
 
            self.stream.flush()
54
 
 
55
 
 
56
 
class NovaTestRunner(core.TextTestRunner):
57
 
    def _makeResult(self):
58
 
        return NovaTestResult(self.stream,
59
 
                              self.descriptions,
60
 
                              self.verbosity,
61
 
                              self.config)
62
 
 
63
 
 
64
 
if __name__ == '__main__':
65
 
    c = config.Config(stream=sys.stdout,
66
 
                      env=os.environ,
67
 
                      verbosity=3)
68
 
    
69
 
    migration.db_sync()
70
 
 
71
 
 
72
 
    runner = NovaTestRunner(stream=c.stream,
73
 
                            verbosity=c.verbosity,
74
 
                            config=c)
75
 
    sys.exit(not core.run(config=c, testRunner=runner))