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_determine_scope(self): stack = ParentStack() t = Terms(None) stack.add(0, Node(label=['1000'])) stack.add(1, Node(label=['1000', '1'])) # Defaults to the entire reg self.assertEqual([('1000',)], t.determine_scope(stack)) stack.add(1, Node('For the purposes of this part, blah blah', label=['1001', '2'])) self.assertEqual([('1001',), ('1001', Node.INTERP_MARK)], t.determine_scope(stack)) t.subpart_map = { 'SubPart 1': ['A', '3'], 'Other': [] } stack.add(1, Node(label=['1000', '3'])) stack.add(2, Node('For the purposes of this subpart, yada yada', label=['1000', '3', 'c'])) self.assertEqual([('1000', 'A'), ('1000', '3'), ('1000', 'A', Node.INTERP_MARK), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(2, Node('For the purposes of this section, blah blah', label=['1000', '3', 'd'])) self.assertEqual([('1000', '3'), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(3, Node('For the purposes of this paragraph, blah blah', label=['1000', '3', 'd', '5'])) self.assertEqual([('1000', '3', 'd', '5'), ('1000', '3', 'd', '5', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(3, Node(label=['1002', '3', 'd', '6'])) self.assertEqual([('1000', '3'), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(4, Node(u'For the purposes of this § 1000.3(d)(6)(i), blah', label=['1000', '3', 'd', '6', 'i'])) self.assertEqual([('1000', '3', 'd', '6', 'i'), ('1000', '3', 'd', '6', 'i', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(4, Node(u'For the purposes of § 1000.3, blah', label=['1000', '3', 'd', '6', 'ii'])) self.assertEqual([('1000', '3'), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack))
def test_subpart_scope(self): t = Terms(None) t.subpart_map = { None: ['1', '2', '3'], 'A': ['7', '5', '0'], 'Q': ['99', 'abc', 'q'] } self.assertEqual([['111', '1'], ['111', '2'], ['111', '3']], t.subpart_scope(['111', '3'])) self.assertEqual([['115', '7'], ['115', '5'], ['115', '0']], t.subpart_scope(['115', '5'])) self.assertEqual([['62', '99'], ['62', 'abc'], ['62', 'q']], t.subpart_scope(['62', 'abc'])) self.assertEqual([], t.subpart_scope(['71', 'Z']))
def test_determine_scope(self): stack = ParentStack() t = Terms(None) stack.add(0, Node(label=['1000'])) stack.add(1, Node(label=['1000', '1'])) # Defaults to the entire reg self.assertEqual([('1000',)], t.determine_scope(stack)) stack.add(1, Node('For the purposes of this part, blah blah', label=['1001', '2'])) self.assertEqual([('1001',), ('1001', Node.INTERP_MARK)], t.determine_scope(stack)) t.subpart_map = { 'SubPart 1': ['A', '3'], 'Other': [] } stack.add(1, Node(label=['1000', '3'])) stack.add(2, Node('For the purposes of this subpart, yada yada', label=['1000', '3', 'c'])) self.assertEqual([('1000', 'A'), ('1000', '3'), ('1000', 'A', Node.INTERP_MARK), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(2, Node('For the purposes of this section, blah blah', label=['1000', '3', 'd'])) self.assertEqual([('1000', '3'), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(3, Node('For the purposes of this paragraph, blah blah', label=['1000', '3', 'd', '5'])) self.assertEqual([('1000', '3', 'd', '5'), ('1000', '3', 'd', '5', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(3, Node(label=['1002', '3', 'd', '6'])) self.assertEqual([('1000', '3'), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(3, Node('Blah as used in this paragraph, blah blah', label=['1000', '3', 'd', '7'])) self.assertEqual([('1000', '3', 'd', '7'), ('1000', '3', 'd', '7', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(4, Node(u'For the purposes of this § 1000.3(d)(6)(i), blah', label=['1000', '3', 'd', '6', 'i'])) self.assertEqual([('1000', '3', 'd', '6', 'i'), ('1000', '3', 'd', '6', 'i', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(4, Node(u'For the purposes of § 1000.3, blah', label=['1000', '3', 'd', '6', 'ii'])) self.assertEqual([('1000', '3'), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack)) stack.add(4, Node('As used in this section, blah blah', label=['1000', '3', 'd', '6', 'iii'])) self.assertEqual( [('1000', '3'), ('1000', '3', Node.INTERP_MARK)], t.determine_scope(stack))