def setUp(self): builder = TreeBuilder() builder.start = MagicMock() builder.data = MagicMock() builder.end = MagicMock() self.builder = builder
def setUp(self): builder = TreeBuilder() builder.start = MagicMock() builder.data = MagicMock() builder.end = MagicMock() self.builder = builder
class TreeBuilderRegexTestCase(TestCase): """ """ def setUp(self): self.builder = TreeBuilder() self.builder._feedmatch = MagicMock() self.regex = self.builder.regex def tearDown(self): del self.regex del self.builder def _parsetag(self, markup): """ Call regex.match() on input string; return match groups """ m = self.regex.match(markup) self.assertIsNotNone(m) groupdict = m.groupdict() self.assertEqual(len(groupdict), 4) return (groupdict["tag"], groupdict["text"], groupdict["closetag"]) def test_sgml_tag(self): markup = "<TAG>data" parsed = self._parsetag(markup) self.assertEqual(parsed, ("TAG", "data", None)) def test_sgml_endtag(self): markup = "</TAG>data" parsed = self._parsetag(markup) self.assertEqual(parsed, ("/TAG", "data", None)) def test_xml_tag(self): markup = "<TAG>data</TAG>" parsed = self._parsetag(markup) self.assertEqual(parsed, ("TAG", "data", "TAG")) def test_xml_mismatched_endtag(self): markup = "<TAG>data</GAT>" parsed = self._parsetag(markup) self.assertEqual(parsed, ("TAG", "data", None)) def test_xml_selfclosing_tag(self): markup = "<TAG />" parsed = self._parsetag(markup) self.assertEqual(parsed, ("TAG /", None, None)) def test_finditer_sgml(self): markup = "<TAG1><TAG2>value" self.builder.feed(markup) expected = [call("TAG1", None, None), call("TAG2", "value", None)] self.assertEqual(self.builder._feedmatch.mock_calls, expected) def test_finditer_xml(self): markup = "<TAG1><TAG2>value</TAG2></TAG1>" self.builder.feed(markup) expected = [ call("TAG1", None, None), call("TAG2", "value", "TAG2"), call("/TAG1", None, None), ] self.assertEqual(self.builder._feedmatch.mock_calls, expected)
class TreeBuilderRegexTestCase(TestCase): """ """ def setUp(self): self.builder = TreeBuilder() self.builder._feedmatch = MagicMock() self.regex = self.builder.regex def tearDown(self): del self.regex del self.builder def _parsetag(self, markup): """Call regex.match() on input string; return match groups""" m = self.regex.match(markup) self.assertIsNotNone(m) groupdict = m.groupdict() self.assertEqual(len(groupdict), 4) return (groupdict["tag"], groupdict["text"], groupdict["closetag"]) def test_sgml_tag(self): markup = "<TAG>data" parsed = self._parsetag(markup) self.assertEqual(parsed, ("TAG", "data", None)) def test_sgml_endtag(self): markup = "</TAG>data" parsed = self._parsetag(markup) self.assertEqual(parsed, ("/TAG", "data", None)) def test_xml_tag(self): markup = "<TAG>data</TAG>" parsed = self._parsetag(markup) self.assertEqual(parsed, ("TAG", "data", "TAG")) def test_xml_mismatched_endtag(self): markup = "<TAG>data</GAT>" parsed = self._parsetag(markup) self.assertEqual(parsed, ("TAG", "data", None)) def test_xml_selfclosing_tag(self): markup = "<TAG />" parsed = self._parsetag(markup) self.assertEqual(parsed, ("TAG /", None, None)) def test_finditer_sgml(self): markup = "<TAG1><TAG2>value" self.builder.feed(markup) expected = [call("TAG1", None, None), call("TAG2", "value", None)] self.assertEqual(self.builder._feedmatch.mock_calls, expected) def test_finditer_xml(self): markup = "<TAG1><TAG2>value</TAG2></TAG1>" self.builder.feed(markup) expected = [ call("TAG1", None, None), call("TAG2", "value", "TAG2"), call("/TAG1", None, None), ] self.assertEqual(self.builder._feedmatch.mock_calls, expected)
def parse(self, source): if not hasattr(source, 'read'): source = open(source) with source as s: source = s.read() if hasattr(source, 'decode'): source = source.decode() # Validate and strip the OFX header source = OFXHeader.strip(source) # Then parse tag soup into tree of Elements parser = TreeBuilder(element_factory=self.element_factory) parser.feed(source) self._root = parser.close()
def _testFeedSonrs(self, body): """ str -> Element tests reused to test responses with identical content but different formatting. """ builder = TreeBuilder() builder.feed(body) root = builder.close() self._testElement(root, tag="OFX", text=None, length=1) msgsrs = root[0] self._testElement(msgsrs, tag="SIGNONMSGSRSV1", text=None, length=1) sonrs = msgsrs[0] self._testElement(sonrs, tag="SONRS", text=None, length=6) status, dtserver, language, dtprofup, dtacctup, fi = sonrs self._testElement(status, tag="STATUS", text=None, length=2) code, severity = status self._testElement(code, tag="CODE", text="0", length=0) self._testElement(severity, tag="SEVERITY", text="INFO", length=0) self._testElement(dtserver, tag="DTSERVER", text="20051029101003", length=0) self._testElement(language, tag="LANGUAGE", text="ENG", length=0) self._testElement(dtprofup, tag="DTPROFUP", text="19991029101003", length=0) self._testElement(dtacctup, tag="DTACCTUP", text="20031029101003", length=0) self._testElement(fi, tag="FI", text=None, length=2) org, fid = fi self._testElement(org, tag="ORG", text="NCH", length=0) self._testElement(fid, tag="FID", text="1001", length=0)
def _testFeedSonrs(self, body): """ str -> Element tests reused to test responses with identical content but different formatting. """ builder = TreeBuilder() builder.feed(body) root = builder.close() self._testElement(root, tag="OFX", text=None, length=1) msgsrs = root[0] self._testElement(msgsrs, tag="SIGNONMSGSRSV1", text=None, length=1) sonrs = msgsrs[0] self._testElement(sonrs, tag="SONRS", text=None, length=6) status, dtserver, language, dtprofup, dtacctup, fi = sonrs self._testElement(status, tag="STATUS", text=None, length=2) code, severity = status self._testElement(code, tag="CODE", text="0", length=0) self._testElement(severity, tag="SEVERITY", text="INFO", length=0) self._testElement(dtserver, tag="DTSERVER", text="20051029101003", length=0) self._testElement(language, tag="LANGUAGE", text="ENG", length=0) self._testElement(dtprofup, tag="DTPROFUP", text="19991029101003", length=0) self._testElement(dtacctup, tag="DTACCTUP", text="20031029101003", length=0) self._testElement(fi, tag="FI", text=None, length=2) org, fid = fi self._testElement(org, tag="ORG", text="NCH", length=0) self._testElement(fid, tag="FID", text="1001", length=0)
def setUpClass(cls): cls.tree = OFXTree() parser = TreeBuilder() parser.feed(cls.ofx) cls.tree._root = parser.close()
def setUpClass(cls): cls.tree = OFXTree() parser = TreeBuilder() parser.feed(cls.ofx) cls.tree._root = parser.close()
def setUp(self): self.builder = TreeBuilder() self.builder._feedmatch = MagicMock() self.regex = self.builder.regex
def setUp(self): self.builder = TreeBuilder() self.builder._feedmatch = MagicMock() self.regex = self.builder.regex