def test_parser_shutdown_is_called(self):
        """ test whether shutdown is called if a node fuinction raises
        """
        testsuite = '''<wrapping name="facet genreCategory">
                        <setup xmlns="info:testsuite#"
                               xmlns:s="http://dbc.dk/xml/namespaces/solr">
                        </setup>
                        <test xmlns="info:testsuite#"
                              xmlns:s="http://dbc.dk/xml/namespaces/solr"
                              name="facet genreCategory">
                        </test>
                       </wrapping>'''

        tr = testrunner.TestRunner('testpath', 1, self.logfolder)
        tr.shutdown = Mock()
        tr.parse(etree.fromstring(testsuite))
        self.assertEqual(1, tr.shutdown.call_count)
    def test_parser_unknown_test_node_result_in_failure(self):
        """ test whether a unknown test node results in a failure as expected
        """
        testsuite = '''<wrapping name="facet genreCategory">
                        <setup xmlns="info:testsuite#"
                               xmlns:s="http://dbc.dk/xml/namespaces/solr">
                        </setup>
                        <test xmlns="info:testsuite#"
                              xmlns:s="http://dbc.dk/xml/namespaces/solr"
                              name="facet genreCategory">
                         <s:bar/>
                        </test>
                       </wrapping>'''

        tr = testrunner.TestRunner('testpath', 1, self.logfolder)
        tr.parse(etree.fromstring(testsuite))
        self.assertEqual(
            tr.failures,
            ["Tag '{http://dbc.dk/xml/namespaces/solr}bar' is not known."])
    def test_parser_node_function_fail_is_present_in_output(self):
        """ test whether a node function adding info to fail is present in the final output
        """
        testsuite = '''<wrapping name="facet genreCategory">
                        <setup xmlns="info:testsuite#"
                               xmlns:s="http://dbc.dk/xml/namespaces/solr">
                        </setup>
                        <test xmlns="info:testsuite#"
                              xmlns:s="http://dbc.dk/xml/namespaces/solr"
                              name="facet genreCategory">
                         <s:myfunc/>
                        </test>
                       </wrapping>'''

        def myfunc(node):
            return ([], ['TEST-FAIL'], [])

        tr = testrunner.TestRunner('testpath', 1, self.logfolder)
        tr.parser_functions.update(
            {'{http://dbc.dk/xml/namespaces/solr}myfunc': myfunc})
        tr.parse(etree.fromstring(testsuite))

        self.assertEqual(tr.failures, ['TEST-FAIL'])
    def test_parser_shutdown_is_called_if_node_function_raises(self):
        """ test whether shutdown is called if a node fuinction raises
        """
        testsuite = '''<wrapping name="facet genreCategory">
                        <setup xmlns="info:testsuite#"
                               xmlns:s="http://dbc.dk/xml/namespaces/solr">
                        </setup>
                        <test xmlns="info:testsuite#"
                              xmlns:s="http://dbc.dk/xml/namespaces/solr"
                              name="facet genreCategory">
                         <s:myfunc/>
                        </test>
                       </wrapping>'''

        def myfunc(node):
            raise RuntimeError('foo error')

        tr = testrunner.TestRunner('testpath', 1, self.logfolder)
        tr.parser_functions.update(
            {'{http://dbc.dk/xml/namespaces/solr}myfunc': myfunc})
        tr.shutdown = Mock()

        self.assertRaises(RuntimeError, tr.parse, etree.fromstring(testsuite))
        self.assertEqual(1, tr.shutdown.call_count)