def test_definitions_scopes(self):
        t = Terms(None)
        node = Node(label=['1000', '22', 'a', '5'])
        node.text = 'For the purposes of this part, blah blah'
        self.assertEqual([('1000',), ('1000', Node.INTERP_MARK)], 
            t.definitions_scopes(node))

        t.subpart_map = {
            'SubPart 1': ['a', '22'],
            'Other': []
        }
        node.text = 'For the purposes of this subpart, yada yada'
        self.assertEqual([('1000', 'a'), ('1000', '22'), 
            ('1000', 'a', Node.INTERP_MARK), ('1000', '22', Node.INTERP_MARK)],
            t.definitions_scopes(node))

        node.text = 'For the purposes of this section, blah blah'
        self.assertEqual([('1000', '22'), ('1000', '22', Node.INTERP_MARK)], 
                t.definitions_scopes(node))

        node.text = 'For the purposes of this paragraph, blah blah'
        self.assertEqual([('1000','22','a','5'), 
            ('1000','22','a','5',Node.INTERP_MARK)], 
            t.definitions_scopes(node))

        node.text = 'Default'
        self.assertEqual([('1000',), ('1000', Node.INTERP_MARK)], 
            t.definitions_scopes(node))
    def test_create_xml_changes_child_stars(self):
        labels_amended = [Amendment('PUT', '200-2-a')]
        xml = etree.fromstring("<ROOT><P>(a) Content</P><STARS /></ROOT>")
        n2a = Node('(a) Content', label=['200', '2', 'a'],
                   source_xml=xml.xpath('//P')[0])
        n2b = Node('(b) Content', label=['200', '2', 'b'])
        n2 = Node('n2', label=['200', '2'], children=[n2a, n2b])
        root = Node('root', label=['200'], children=[n2])

        notice_changes = changes.NoticeChanges()
        build.create_xml_changes(labels_amended, root, notice_changes)

        self.assertTrue('200-2-a' in notice_changes.changes)
        self.assertTrue(1, len(notice_changes.changes['200-2-a']))
        change = notice_changes.changes['200-2-a'][0]
        self.assertEqual('PUT', change['action'])
        self.assertFalse('field' in change)

        n2a.text = n2a.text + ":"
        n2a.source_xml.text = n2a.source_xml.text + ":"

        notice_changes = changes.NoticeChanges()
        build.create_xml_changes(labels_amended, root, notice_changes)

        self.assertTrue('200-2-a' in notice_changes.changes)
        self.assertTrue(1, len(notice_changes.changes['200-2-a']))
        change = notice_changes.changes['200-2-a'][0]
        self.assertEqual('PUT', change['action'])
        self.assertEqual('[text]', change.get('field'))
Ejemplo n.º 3
0
    def test_create_xml_changes_child_stars(self):
        labels_amended = [Amendment('PUT', '200-2-a')]
        xml = etree.fromstring("<ROOT><P>(a) Content</P><STARS /></ROOT>")
        n2a = Node('(a) Content', label=['200', '2', 'a'],
                   source_xml=xml.xpath('//P')[0])
        n2b = Node('(b) Content', label=['200', '2', 'b'])
        n2 = Node('n2', label=['200', '2'], children=[n2a, n2b])
        root = Node('root', label=['200'], children=[n2])

        notice_changes = changes.NoticeChanges()
        build.create_xml_changes(labels_amended, root, notice_changes)

        self.assertTrue('200-2-a' in notice_changes.changes)
        self.assertTrue(1, len(notice_changes.changes['200-2-a']))
        change = notice_changes.changes['200-2-a'][0]
        self.assertEqual('PUT', change['action'])
        self.assertFalse('field' in change)

        n2a.text = n2a.text + ":"
        n2a.source_xml.text = n2a.source_xml.text + ":"

        notice_changes = changes.NoticeChanges()
        build.create_xml_changes(labels_amended, root, notice_changes)

        self.assertTrue('200-2-a' in notice_changes.changes)
        self.assertTrue(1, len(notice_changes.changes['200-2-a']))
        change = notice_changes.changes['200-2-a'][0]
        self.assertEqual('PUT', change['action'])
        self.assertEqual('[text]', change.get('field'))
Ejemplo n.º 4
0
def test_create_xml_changes_child_stars():
    labels_amended = [Amendment('PUT', '200-?-2-a')]
    with XMLBuilder("ROOT") as ctx:
        ctx.P("(a) Content")
        ctx.STARS()
    n2a = Node('(a) Content', label=['200', '2', 'a'],
               source_xml=ctx.xml.xpath('//P')[0])
    n2b = Node('(b) Content', label=['200', '2', 'b'])
    n2 = Node('n2', label=['200', '2'], children=[n2a, n2b])
    root = Node('root', label=['200'], children=[n2])

    notice_changes = changes.NoticeChanges()
    fetch.create_xml_changes(labels_amended, root, notice_changes)
    data = notice_changes[None]

    assert '200-2-a' in data
    assert len(data['200-2-a']) == 1
    change = data['200-2-a'][0]
    assert change['action'] == 'PUT'
    assert 'field' not in change

    n2a.text = n2a.text + ":"
    n2a.source_xml.text = n2a.source_xml.text + ":"

    notice_changes = changes.NoticeChanges()
    fetch.create_xml_changes(labels_amended, root, notice_changes)
    data = notice_changes[None]

    assert '200-2-a' in data
    assert len(data['200-2-a']) == 1
    change = data['200-2-a'][0]
    assert change['action'] == 'PUT'
    assert change.get('field') == '[text]'
    def test_create_xml_changes_child_stars(self):
        labels_amended = [Amendment('PUT', '200-?-2-a')]
        with XMLBuilder("ROOT") as ctx:
            ctx.P("(a) Content")
            ctx.STARS()
        n2a = Node('(a) Content', label=['200', '2', 'a'],
                   source_xml=ctx.xml.xpath('//P')[0])
        n2b = Node('(b) Content', label=['200', '2', 'b'])
        n2 = Node('n2', label=['200', '2'], children=[n2a, n2b])
        root = Node('root', label=['200'], children=[n2])

        notice_changes = changes.NoticeChanges()
        amendments.create_xml_changes(labels_amended, root, notice_changes)
        data = notice_changes.changes_by_xml[None]

        self.assertIn('200-2-a', data)
        self.assertTrue(1, len(data['200-2-a']))
        change = data['200-2-a'][0]
        self.assertEqual('PUT', change['action'])
        self.assertNotIn('field', change)

        n2a.text = n2a.text + ":"
        n2a.source_xml.text = n2a.source_xml.text + ":"

        notice_changes = changes.NoticeChanges()
        amendments.create_xml_changes(labels_amended, root, notice_changes)
        data = notice_changes.changes_by_xml[None]

        self.assertIn('200-2-a', data)
        self.assertTrue(1, len(data['200-2-a']))
        change = data['200-2-a'][0]
        self.assertEqual('PUT', change['action'])
        self.assertEqual('[text]', change.get('field'))
    def test_create_xml_changes_child_stars(self):
        labels_amended = [Amendment("PUT", "200-2-a")]
        xml = etree.fromstring("<ROOT><P>(a) Content</P><STARS /></ROOT>")
        n2a = Node("(a) Content", label=["200", "2", "a"], source_xml=xml.xpath("//P")[0])
        n2b = Node("(b) Content", label=["200", "2", "b"])
        n2 = Node("n2", label=["200", "2"], children=[n2a, n2b])
        root = Node("root", label=["200"], children=[n2])

        notice_changes = changes.NoticeChanges()
        build.create_xml_changes(labels_amended, root, notice_changes)

        self.assertTrue("200-2-a" in notice_changes.changes)
        self.assertTrue(1, len(notice_changes.changes["200-2-a"]))
        change = notice_changes.changes["200-2-a"][0]
        self.assertEqual("PUT", change["action"])
        self.assertFalse("field" in change)

        n2a.text = n2a.text + ":"
        n2a.source_xml.text = n2a.source_xml.text + ":"

        notice_changes = changes.NoticeChanges()
        build.create_xml_changes(labels_amended, root, notice_changes)

        self.assertTrue("200-2-a" in notice_changes.changes)
        self.assertTrue(1, len(notice_changes.changes["200-2-a"]))
        change = notice_changes.changes["200-2-a"][0]
        self.assertEqual("PUT", change["action"])
        self.assertEqual("[text]", change.get("field"))
 def test_process_with_results(self):
     pm = ParagraphMarkers(None)
     for m, nt, l in (('(c)', Node.REGTEXT, ['c']),
                      ('(vi)', Node.REGTEXT, ['c', 'vi']),
                      ('ii.', Node.INTERP, ['ii', Node.INTERP_MARK]),
                      ('A.', Node.INTERP, ['ii', 'A', Node.INTERP_MARK]),
                      ('(a)', Node.APPENDIX, ['111', 'A', 'a']),
                      ('a.', Node.APPENDIX, ['111', 'A', 'a'])):
         expected_result = [{"text": m, "locations": [0]}]
         node = Node(m + " Paragraph", label=l, node_type=nt)
         self.assertEqual(pm.process(node), expected_result)
         # whitespace is ignored
         node.text = "\n" + node.text
         self.assertEqual(pm.process(node), expected_result)
Ejemplo n.º 8
0
    def test_is_exclusion(self):
        """There are certain indicators that a definition _should not_ be
        considered the definition of that term. For example, exclusions to a
        general definition should not replace the original. We can also
        explicitly ignore chunks of text when finding definitions.."""
        t = Terms(None)
        n = Node('ex ex ex', label=['1111', '2'])
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111', ): [Ref('abc', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111', ): [Ref('ex', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))
        n.text = u'Something something the term “ex” does not include potato'
        self.assertTrue(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111', ): [Ref('abc', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))

        settings.IGNORE_DEFINITIONS_IN['1111'] = ['phrase with abc in it']
        self.assertFalse(t.is_exclusion('abc', n))
        n.text = "Now the node has a phrase with abc in it, doesn't it?"
        self.assertTrue(t.is_exclusion('abc', n))
    def test_is_exclusion(self):
        t = Terms(None)
        n = Node('ex ex ex', label=['1111', '2'])
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('ex', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))
        n.text = u'Something something the term “ex” does not include potato'
        self.assertTrue(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))
    def test_is_exclusion(self):
        """There are certain indicators that a definition _should not_ be
        considered the definition of that term. For example, exclusions to a
        general definition should not replace the original. We can also
        explicitly ignore chunks of text when finding definitions.."""
        t = Terms(None)
        n = Node('ex ex ex', label=['1111', '2'])
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('ex', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))
        n.text = u'Something something the term “ex” does not include potato'
        self.assertTrue(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))

        settings.IGNORE_DEFINITIONS_IN['1111'] = ['phrase with abc in it']
        self.assertFalse(t.is_exclusion('abc', n))
        n.text = "Now the node has a phrase with abc in it, doesn't it?"
        self.assertTrue(t.is_exclusion('abc', n))
Ejemplo n.º 11
0
 def test_process_with_results(self):
     pm = ParagraphMarkers(None)
     for m, nt, l in (('(c)', Node.REGTEXT, ['c']), ('(vi)', Node.REGTEXT,
                                                     ['c', 'vi']),
                      ('ii.', Node.INTERP, ['ii', Node.INTERP_MARK]),
                      ('A.', Node.INTERP, ['ii', 'A', Node.INTERP_MARK]),
                      ('(a)', Node.APPENDIX, ['111', 'A',
                                              'a']), ('a.', Node.APPENDIX,
                                                      ['111', 'A', 'a'])):
         expected_result = [{"text": m, "locations": [0]}]
         node = Node(m + " Paragraph", label=l, node_type=nt)
         self.assertEqual(pm.process(node), expected_result)
         # whitespace is ignored
         node.text = "\n" + node.text
         self.assertEqual(pm.process(node), expected_result)
    def test_is_exclusion(self):
        t = Terms(None)
        n = Node('ex ex ex', label=['1111', '2'])
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('ex', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))
        n.text = u'Something something the term “ex” does not include potato'
        self.assertTrue(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))
 def test_process_with_results(self):
     pm = ParagraphMarkers(None)
     for m, nt, l in (
         ("(c)", Node.REGTEXT, ["c"]),
         ("(vi)", Node.REGTEXT, ["c", "vi"]),
         ("ii.", Node.INTERP, ["ii", Node.INTERP_MARK]),
         ("A.", Node.INTERP, ["ii", "A", Node.INTERP_MARK]),
         ("(a)", Node.APPENDIX, ["111", "A", "a"]),
         ("a.", Node.APPENDIX, ["111", "A", "a"]),
     ):
         expected_result = [{"text": m, "locations": [0]}]
         node = Node(m + " Paragraph", label=l, node_type=nt)
         self.assertEqual(pm.process(node), expected_result)
         # whitespace is ignored
         node.text = "\n" + node.text
         self.assertEqual(pm.process(node), expected_result)