<commit_before>from twisted.trial.unittest import TestCase
from twilio import twiml
import xml.etree.ElementTree as ET

from vumi_twilio_api.twiml_parser import TwiMLParser, TwiMLParseError, Verb


class TestVerb(TestCase):
    def test_verb_defaults(self):
        """Defaults are set correctly when no args are given"""
        verb = Verb("Say")
        self.assertEqual(verb.verb, "Say")
        self.assertEqual(verb.attributes, {})
        self.assertEqual(verb.nouns, {})


class TestParser(TestCase):
    def setUp(self):
        self.parser = TwiMLParser()
        self.response = twiml.Response()

    def test_invalid_root(self):
        """An invalid root raises an exception"""
        root = ET.Element('foobar')
        xml = ET.tostring(root)
        e = self.assertRaises(TwiMLParseError, self.parser.parse, xml)
        self.assertEqual(
            e.args[0], "Invalid root 'foobar'. Should be 'Request'.")

    def test_default_parse(self):
        """The default parse function is called when a verb parser cannot be
        found"""
        self.parser._parse_Say = None
        self.response.say("Foobar")
        e = self.assertRaises(
            TwiMLParseError, self.parser.parse, str(self.response))
        self.assertEqual(e.args[0], "Cannot find parser for verb 'Say'")

    def test_verb_parse(self):
        """The correct parse function is called when parsing"""
        def dummy_parser(element):
            return "dummy_parser"
        self.parser._parse_Say = dummy_parser
        self.response.say("Foobar")
        [result] = self.parser.parse(str(self.response))
        self.assertEqual(result, "dummy_parser")<commit_msg>Fix test that would fail in the future<commit_after>from twisted.trial.unittest import TestCase
from twilio import twiml
import xml.etree.ElementTree as ET

from vumi_twilio_api.twiml_parser import TwiMLParser, TwiMLParseError, Verb


class TestVerb(TestCase):
    def test_verb_defaults(self):
        """Defaults are set correctly when no args are given"""
        verb = Verb("Say")
        self.assertEqual(verb.verb, "Say")
        self.assertEqual(verb.attributes, {})
        self.assertEqual(verb.nouns, {})


class TestParser(TestCase):
    def setUp(self):
        self.parser = TwiMLParser()
        self.response = twiml.Response()

    def test_invalid_root(self):
        """An invalid root raises an exception"""
        root = ET.Element('foobar')
        xml = ET.tostring(root)
        e = self.assertRaises(TwiMLParseError, self.parser.parse, xml)
        self.assertEqual(
            e.args[0], "Invalid root 'foobar'. Should be 'Request'.")

    def test_default_parse(self):
        """The default parse function is called when a verb parser cannot be
        found"""
        self.response.sms("Foobar")
        e = self.assertRaises(
            TwiMLParseError, self.parser.parse, str(self.response))
        self.assertEqual(e.args[0], "Cannot find parser for verb 'Sms'")

    def test_verb_parse(self):
        """The correct parse function is called when parsing"""
        def dummy_parser(element):
            return "dummy_parser"
        self.parser._parse_Say = dummy_parser
        self.response.say("Foobar")
        [result] = self.parser.parse(str(self.response))
        self.assertEqual(result, "dummy_parser")
{'fraction_non_alphanumeric': 0.1100391920410009, 'fraction_numerical': 0.0012059089538739825, 'mean_word_length': 2.8989424206815513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2639282', 'n_tokens_mistral': 993, 'n_tokens_neox': 960, 'n_words': 248}