コード例 #1
0
 def test_identifying_parallel_citations(self) -> None:
     """Given a string, can we identify parallel citations"""
     tests = (
         # A pair consisting of a test string and the number of parallel
         # citations that should be identifiable in that string.
         # Simple case
         ("1 U.S. 1 (22 U.S. 33)", 1, 2),
         # Too far apart
         ("1 U.S. 1 too many words 22 U.S. 33", 0, 0),
         # Three citations
         # ("1 U.S. 1, (44 U.S. 33, 99 U.S. 100)", 1, 3),
         # Parallel citation after a valid citation too early on
         ("1 U.S. 1 too many words, then 22 U.S. 33, 13 WL 33223", 1, 2),
     )
     for q, citation_group_count, expected_num_parallel_citations in tests:
         with self.subTest(
                 f"Testing parallel citation identification for: {q}...",
                 q=q,
                 citation_group_count=citation_group_count,
                 expected_num_parallel_citations=
                 expected_num_parallel_citations,
         ):
             citations = get_citations(q)
             citation_groups = identify_parallel_citations(citations)
             computed_num_citation_groups = len(citation_groups)
             self.assertEqual(
                 computed_num_citation_groups,
                 citation_group_count,
                 msg=
                 "Did not have correct number of citation groups. Got %s, "
                 "not %s." %
                 (computed_num_citation_groups, citation_group_count),
             )
             if not citation_groups:
                 # Add an empty list to make testing easier.
                 citation_groups = [[]]
             computed_num_parallel_citation = len(list(citation_groups)[0])
             self.assertEqual(
                 computed_num_parallel_citation,
                 expected_num_parallel_citations,
                 msg=
                 "Did not identify correct number of parallel citations in "
                 "the group. Got %s, not %s" % (
                     computed_num_parallel_citation,
                     expected_num_parallel_citations,
                 ),
             )
コード例 #2
0
ファイル: tests.py プロジェクト: freelawproject/courtlistener
 def test_identifying_parallel_citations(self):
     """Given a string, can we identify parallel citations"""
     tests = (
         # A pair consisting of a test string and the number of parallel
         # citations that should be identifiable in that string.
         # Simple case
         ("1 U.S. 1 (22 U.S. 33)", 1, 2),
         # Too far apart
         ("1 U.S. 1 too many words 22 U.S. 33", 0, 0),
         # Three citations
         ("1 U.S. 1, (44 U.S. 33, 99 U.S. 100)", 1, 3),
         # Parallel citation after a valid citation too early on
         ("1 U.S. 1 too many words, then 22 U.S. 33, 13 WL 33223", 1, 2),
     )
     for q, citation_group_count, expected_num_parallel_citations in tests:
         print "Testing parallel citation identification for: %s..." % q,
         citations = get_citations(q)
         citation_groups = identify_parallel_citations(citations)
         computed_num_citation_groups = len(citation_groups)
         self.assertEqual(
             computed_num_citation_groups,
             citation_group_count,
             msg="Did not have correct number of citation groups. Got %s, "
                 "not %s." % (computed_num_citation_groups,
                              citation_group_count)
         )
         if not citation_groups:
             # Add an empty list to make testing easier.
             citation_groups = [[]]
         computed_num_parallel_citation = len(list(citation_groups)[0])
         self.assertEqual(
             computed_num_parallel_citation,
             expected_num_parallel_citations,
             msg="Did not identify correct number of parallel citations in "
                 "the group. Got %s, not %s" % (
                     computed_num_parallel_citation,
                     expected_num_parallel_citations,
                 )
         )
         print '✓'