[svn r37411] Fix a bit rest and test_rest. Note that actually these tests are
testing anything from time to time, need closer look. --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									e3dfe80856
								
							
						
					
					
						commit
						d929f633a7
					
				| 
						 | 
					@ -37,20 +37,21 @@ class RestReporter(AbstractReporter):
 | 
				
			||||||
        return self.hosts[0]
 | 
					        return self.hosts[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def report_SendItem(self, item):
 | 
					    def report_SendItem(self, item):
 | 
				
			||||||
        address = self.gethost(item)
 | 
					        address = self.gethost(item).hostname
 | 
				
			||||||
        if self.config.option.verbose:
 | 
					        if self.config.option.verbose:
 | 
				
			||||||
            self.add_rest(Paragraph('sending item %s to %s' % (item.item,
 | 
					            self.add_rest(Paragraph('sending item %s to %s' % (item.item,
 | 
				
			||||||
                                                               address)))
 | 
					                                                               address)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def report_HostRSyncing(self, item):
 | 
					    def report_HostRSyncing(self, item):
 | 
				
			||||||
        self.add_rest(LiteralBlock('%10s: RSYNC ==> %s' % (item.host.hostname[:10],
 | 
					        self.add_rest(LiteralBlock('%10s: RSYNC ==> %s' % (item.host.hostname[:10],
 | 
				
			||||||
                                                        item.remoterootpath)))
 | 
					                                                        item.host.relpath)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def report_HostReady(self, item):
 | 
					    def report_HostReady(self, item):
 | 
				
			||||||
        self.add_rest(LiteralBlock('%10s: READY' % (item.host.hostname[:10],)))
 | 
					        self.add_rest(LiteralBlock('%10s: READY' % (item.host.hostname[:10],)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def report_TestStarted(self, event):
 | 
					    def report_TestStarted(self, event):
 | 
				
			||||||
        txt = "Running tests on hosts: %s" % ", ".join(event.hosts)
 | 
					        txt = "Running tests on hosts: %s" % ", ".join([i.hostname for i in
 | 
				
			||||||
 | 
					                                                        event.hosts])
 | 
				
			||||||
        self.add_rest(Title(txt, abovechar='=', belowchar='='))
 | 
					        self.add_rest(Title(txt, abovechar='=', belowchar='='))
 | 
				
			||||||
        self.timestart = event.timestart
 | 
					        self.timestart = event.timestart
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,24 +9,13 @@ from py.__.test.rsession import report
 | 
				
			||||||
from py.__.test.rsession.rest import RestReporter, NoLinkWriter
 | 
					from py.__.test.rsession.rest import RestReporter, NoLinkWriter
 | 
				
			||||||
from py.__.rest.rst import *
 | 
					from py.__.rest.rst import *
 | 
				
			||||||
from py.__.test.rsession.hostmanage import HostInfo
 | 
					from py.__.test.rsession.hostmanage import HostInfo
 | 
				
			||||||
 | 
					from py.__.test.rsession.outcome import Outcome
 | 
				
			||||||
py.test.skip("This tests are not really testing, needs rewrite")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class RestTestReporter(RestReporter):
 | 
					class RestTestReporter(RestReporter):
 | 
				
			||||||
    def __init__(self, *args, **kwargs):
 | 
					    def __init__(self, *args, **kwargs):
 | 
				
			||||||
        if args:
 | 
					        if args:
 | 
				
			||||||
            super(RestReporter, self).__init__(*args, **kwargs)
 | 
					            super(RestReporter, self).__init__(*args, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Container(object):
 | 
					 | 
				
			||||||
    def __init__(self, **kwargs):
 | 
					 | 
				
			||||||
        self.__dict__.update(kwargs)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class FakeOutcome(Container, report.ReceivedItemOutcome):
 | 
					 | 
				
			||||||
    pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class FakeTryiter(Container, report.SkippedTryiter):
 | 
					 | 
				
			||||||
    pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class TestRestUnits(object):
 | 
					class TestRestUnits(object):
 | 
				
			||||||
    def setup_method(self, method):
 | 
					    def setup_method(self, method):
 | 
				
			||||||
        config = py.test.config._reparse(["some_sub"])
 | 
					        config = py.test.config._reparse(["some_sub"])
 | 
				
			||||||
| 
						 | 
					@ -47,30 +36,31 @@ class TestRestUnits(object):
 | 
				
			||||||
        self.config.option.verbose = False
 | 
					        self.config.option.verbose = False
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def test_report_SendItem(self):
 | 
					    def test_report_SendItem(self):
 | 
				
			||||||
        item = Container(item='foo/bar.py', channel=ch)
 | 
					        event = report.SendItem(item='foo/bar.py', channel=ch)
 | 
				
			||||||
        reporter.report_SendItem(item)
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == ''
 | 
					        assert stdout.getvalue() == ''
 | 
				
			||||||
        stdout.seek(0)
 | 
					        stdout.seek(0)
 | 
				
			||||||
        stdout.truncate()
 | 
					        stdout.truncate()
 | 
				
			||||||
        reporter.config.option.verbose = True
 | 
					        reporter.config.option.verbose = True
 | 
				
			||||||
        reporter.report_SendItem(item)
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == ('sending item foo/bar.py to '
 | 
					        assert stdout.getvalue() == ('sending item foo/bar.py to '
 | 
				
			||||||
                                     'localhost\n\n')
 | 
					                                     'localhost\n\n')
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def test_report_HostRSyncing(self):
 | 
					    def test_report_HostRSyncing(self):
 | 
				
			||||||
        item = Container(hostname='localhost', remoterootpath='/foo/bar')
 | 
					        event = report.HostRSyncing(HostInfo('localhost', '/foo/bar'))
 | 
				
			||||||
        reporter.report_HostRSyncing(item)
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == ('::\n\n   localhost: RSYNC ==> '
 | 
					        assert stdout.getvalue() == ('::\n\n   localhost: RSYNC ==> '
 | 
				
			||||||
                                     '/foo/bar\n\n')
 | 
					                                     '/foo/bar\n\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_report_HostReady(self):
 | 
					    def test_report_HostReady(self):
 | 
				
			||||||
        item = Container(hostname='localhost')
 | 
					        event = report.HostReady(HostInfo('localhost'))
 | 
				
			||||||
        reporter.report_HostReady(item)
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == '::\n\n   localhost: READY\n\n'
 | 
					        assert stdout.getvalue() == '::\n\n   localhost: READY\n\n'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_report_TestStarted(self):
 | 
					    def test_report_TestStarted(self):
 | 
				
			||||||
        event = Container(hosts=['localhost', 'foo.com'], timestart=0)
 | 
					        event = report.TestStarted(hosts=[HostInfo('localhost'),
 | 
				
			||||||
        reporter.report_TestStarted(event)
 | 
					                                          HostInfo('foo.com')])
 | 
				
			||||||
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == """\
 | 
					        assert stdout.getvalue() == """\
 | 
				
			||||||
===========================================
 | 
					===========================================
 | 
				
			||||||
Running tests on hosts\: localhost, foo.com
 | 
					Running tests on hosts\: localhost, foo.com
 | 
				
			||||||
| 
						 | 
					@ -87,9 +77,15 @@ Running tests on hosts\: localhost, foo.com
 | 
				
			||||||
                return ['test_foo', 'test_bar']
 | 
					                return ['test_foo', 'test_bar']
 | 
				
			||||||
            def listnames(self):
 | 
					            def listnames(self):
 | 
				
			||||||
                return ['package', 'foo', 'bar.py']
 | 
					                return ['package', 'foo', 'bar.py']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        class Container(object):
 | 
				
			||||||
 | 
					            def __init__(self, **args):
 | 
				
			||||||
 | 
					                for arg, val in args.items():
 | 
				
			||||||
 | 
					                    setattr(self, arg, val) 
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        parent = Container(parent=None, fspath=py.path.local('.'))
 | 
					        parent = Container(parent=None, fspath=py.path.local('.'))
 | 
				
			||||||
        event = Container(item=FakeModule(parent))
 | 
					        event = report.ItemStart(item=FakeModule(parent))
 | 
				
			||||||
        reporter.report_ItemStart(event)
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == """\
 | 
					        assert stdout.getvalue() == """\
 | 
				
			||||||
Testing module foo/bar.py (2 items)
 | 
					Testing module foo/bar.py (2 items)
 | 
				
			||||||
-----------------------------------
 | 
					-----------------------------------
 | 
				
			||||||
| 
						 | 
					@ -108,32 +104,58 @@ Testing module foo/bar.py (2 items)
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_ReceivedItemOutcome_PASSED(self):
 | 
					    def test_ReceivedItemOutcome_PASSED(self):
 | 
				
			||||||
        outcome = Container(passed=True, excinfo=False)
 | 
					        outcome = Outcome()
 | 
				
			||||||
 | 
					        class Container(object):
 | 
				
			||||||
 | 
					            def __init__(self, **args):
 | 
				
			||||||
 | 
					                for arg, val in args.items():
 | 
				
			||||||
 | 
					                    setattr(self, arg, val) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
 | 
					        item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
 | 
				
			||||||
        event = Container(channel=ch, outcome=outcome, item=item)
 | 
					        event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item)
 | 
				
			||||||
        reporter.report_ReceivedItemOutcome(event)
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == ('* localhost\\: **PASSED** '
 | 
					        assert stdout.getvalue() == ('* localhost\\: **PASSED** '
 | 
				
			||||||
                                     'foo.py/bar()/baz\n\n')
 | 
					                                     'foo.py/bar()/baz\n\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_ReceivedItemOutcome_SKIPPED(self):
 | 
					    def test_ReceivedItemOutcome_SKIPPED(self):
 | 
				
			||||||
        outcome = Container(passed=False, skipped=True, excinfo=False)
 | 
					        class Container(object):
 | 
				
			||||||
 | 
					            def __init__(self, **args):
 | 
				
			||||||
 | 
					                for arg, val in args.items():
 | 
				
			||||||
 | 
					                    setattr(self, arg, val) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        outcome = Outcome(skipped="reason")
 | 
				
			||||||
        item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
 | 
					        item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
 | 
				
			||||||
        event = Container(channel=ch, outcome=outcome, item=item)
 | 
					        event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item)
 | 
				
			||||||
        reporter.report_ReceivedItemOutcome(event)
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == ('* localhost\\: **SKIPPED** '
 | 
					        assert stdout.getvalue() == ('* localhost\\: **SKIPPED** '
 | 
				
			||||||
                                     'foo.py/bar()/baz\n\n')
 | 
					                                     'foo.py/bar()/baz\n\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_ReceivedItemOutcome_FAILED(self):
 | 
					    def test_ReceivedItemOutcome_FAILED(self):
 | 
				
			||||||
        outcome = Container(passed=False, skipped=False)
 | 
					        class Container(object):
 | 
				
			||||||
 | 
					            def __init__(self, **args):
 | 
				
			||||||
 | 
					                for arg, val in args.items():
 | 
				
			||||||
 | 
					                    setattr(self, arg, val) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        outcome = Outcome(excinfo="xxx")
 | 
				
			||||||
        item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
 | 
					        item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
 | 
				
			||||||
        event = Container(channel=ch, outcome=outcome, item=item)
 | 
					        event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item)
 | 
				
			||||||
        reporter.report_ReceivedItemOutcome(event)
 | 
					        reporter.report(event)
 | 
				
			||||||
        assert stdout.getvalue() == """\
 | 
					        assert stdout.getvalue() == """\
 | 
				
			||||||
* localhost\: **FAILED** `traceback0`_ foo.py/bar()/baz
 | 
					* localhost\: **FAILED** `traceback0`_ foo.py/bar()/baz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def test_skips(self):
 | 
					    def test_skips(self):
 | 
				
			||||||
 | 
					        class Container(object):
 | 
				
			||||||
 | 
					            def __init__(self, **args):
 | 
				
			||||||
 | 
					                for arg, val in args.items():
 | 
				
			||||||
 | 
					                    setattr(self, arg, val) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        class FakeOutcome(Container, report.ReceivedItemOutcome):
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        class FakeTryiter(Container, report.SkippedTryiter):
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        reporter.skips()
 | 
					        reporter.skips()
 | 
				
			||||||
        assert stdout.getvalue() == ''
 | 
					        assert stdout.getvalue() == ''
 | 
				
			||||||
        reporter.skipped_tests_outcome = [
 | 
					        reporter.skipped_tests_outcome = [
 | 
				
			||||||
| 
						 | 
					@ -153,6 +175,15 @@ Reasons for skipped tests\:
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_failures(self):
 | 
					    def test_failures(self):
 | 
				
			||||||
 | 
					        py.test.skip("This one is totally artificial, needs to be rewritten")
 | 
				
			||||||
 | 
					        class Container(object):
 | 
				
			||||||
 | 
					            def __init__(self, **args):
 | 
				
			||||||
 | 
					                for arg, val in args.items():
 | 
				
			||||||
 | 
					                    setattr(self, arg, val) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        class FakeOutcome(Container, report.ReceivedItemOutcome):
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parent = Container(parent=None, fspath=py.path.local('.'))
 | 
					        parent = Container(parent=None, fspath=py.path.local('.'))
 | 
				
			||||||
        reporter.failed_tests_outcome = [
 | 
					        reporter.failed_tests_outcome = [
 | 
				
			||||||
            FakeOutcome(
 | 
					            FakeOutcome(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue