13
13
import cluecode_test_utils # NOQA
14
14
from commoncode .testcase import FileBasedTesting
15
15
from cluecode import copyrights
16
+ from textcode import markup
17
+ from cluecode .copyrights import prepare_text_line
16
18
17
19
18
20
class TestTextPreparation (FileBasedTesting ):
@@ -28,56 +30,56 @@ def test_strip_leading_numbers(self):
28
30
29
31
def test_prepare_text_line (self ):
30
32
cp = 'test (C) all rights reserved'
31
- result = copyrights . prepare_text_line (cp )
33
+ result = prepare_text_line (cp )
32
34
assert result == 'test (c) all rights reserved'
33
35
34
36
def test_prepare_text_line_debian (self ):
35
37
cp = 'Parts Copyright (c) 1992 <s>Uri Blumentha<s>l, I</s>BM</s>'
36
- result = copyrights . prepare_text_line (cp )
38
+ result = prepare_text_line (cp )
37
39
assert result == 'Parts Copyright (c) 1992 Uri Blumenthal, IBM'
38
40
39
41
def test_prepare_text_line_does_not_truncate_transliterable_unicode (self ):
40
42
cp = 'Muła'
41
- result = copyrights . prepare_text_line (cp )
43
+ result = prepare_text_line (cp )
42
44
assert result == 'Mula'
43
45
44
- def test_strip_markup (self ):
46
+ def test_strip_markup_removes_debian_legacy_s_tags (self ):
45
47
cp = 'Parts Copyright (c) 1992 <s>Uri Blumentha<s>l, I</s>BM</s>'
46
- result = copyrights . strip_markup (cp )
48
+ result = markup . strip_markup_text (cp )
47
49
assert result == 'Parts Copyright (c) 1992 Uri Blumenthal, IBM'
48
50
49
51
def test_prepare_text_line_removes_C_comments (self ):
50
52
cp = '/* Copyright 1996-2005, 2008-2011 by */'
51
- result = copyrights . prepare_text_line (cp )
53
+ result = prepare_text_line (cp )
52
54
assert result == 'Copyright 1996-2005, 2008-2011 by'
53
55
54
56
def test_prepare_text_line_removes_C_comments2 (self ):
55
57
cp = '/* David Turner, Robert Wilhelm, and Werner Lemberg. */'
56
- result = copyrights . prepare_text_line (cp )
58
+ result = prepare_text_line (cp )
57
59
assert result == 'David Turner, Robert Wilhelm, and Werner Lemberg.'
58
60
59
61
def test_prepare_text_line_removes_Cpp_comments (self ):
60
62
cp = '// David Turner, Robert Wilhelm, and Werner Lemberg. */'
61
- result = copyrights . prepare_text_line (cp )
63
+ result = prepare_text_line (cp )
62
64
assert result == 'David Turner, Robert Wilhelm, and Werner Lemberg.'
63
65
64
66
def test_prepare_text_line_does_not_damage_urls (self ):
65
67
cp = 'copyright (c) 2000 World Wide Web Consortium, http://www.w3.org'
66
- result = copyrights . prepare_text_line (cp )
68
+ result = prepare_text_line (cp )
67
69
assert result == 'copyright (c) 2000 World Wide Web Consortium, http://www.w3.org'
68
70
69
71
def test_is_end_of_statement (self ):
70
72
line = ''' "All rights reserved\\ n"'''
71
- _line , char_only_line = copyrights . prep_line (line )
73
+ _line , char_only_line = prepare_text_line (line )
72
74
assert copyrights .is_end_of_statement (char_only_line )
73
75
74
- def test_candidate_lines_simple (self ):
76
+ def test_collect_candidate_lines_simple (self ):
75
77
lines = [(1 , ' test (C) all rights reserved' )]
76
- result = list (copyrights .candidate_lines (lines ))
78
+ result = list (copyrights .collect_candidate_lines (lines ))
77
79
expected = [[(1 , ' test (C) all rights reserved' )]]
78
80
assert result == expected
79
81
80
- def test_candidate_lines_complex (self ):
82
+ def test_collect_candidate_lines_complex (self ):
81
83
lines = '''
82
84
Apache Xalan (Xalan XSLT processor)
83
85
Copyright 1999-2006 The Apache Software Foundation
@@ -118,57 +120,57 @@ def test_candidate_lines_complex(self):
118
120
[(22 , ' this product includes software developed by the following:' )]
119
121
]
120
122
121
- result = list (copyrights .candidate_lines (enumerate (lines , 1 )))
123
+ result = list (copyrights .collect_candidate_lines (enumerate (lines , 1 )))
122
124
assert result == expected
123
125
124
126
def test_is_candidates_should_not_select_line_with_bare_full_year (self ):
125
127
line = '2012'
126
- line , _char_only = copyrights . prep_line (line )
128
+ line , _char_only = prepare_text_line (line )
127
129
assert not copyrights .is_candidate (line )
128
130
129
131
def test_is_candidates_should_not_select_line_with_full_year_before_160_and_after_2018 (self ):
130
132
line = '1959 2019'
131
- line , _char_only = copyrights . prep_line (line )
133
+ line , _char_only = prepare_text_line (line )
132
134
assert not copyrights .is_candidate (line )
133
135
134
136
def test_is_candidate_should_not_select_line_with_only_two_digit_numbers (self ):
135
137
line = 'template<class V> struct v_iter<V, mpl::int_<10> > { typedef typename V::item10 type; typedef v_iter<V, mpl::int_<10 + 1> > next; };'
136
- line , _char_only = copyrights . prep_line (line )
138
+ line , _char_only = prepare_text_line (line )
137
139
assert not copyrights .is_candidate (line )
138
140
139
141
def test_is_candidate_should_select_line_with_sign (self ):
140
142
line = 'template<class V> struct v_iter<V, mpl::int_<10> (c) { typedef typename V::item10 type; typedef v_iter<V, mpl::int_<10 + 1> > next; };'
141
- line , _char_only = copyrights . prep_line (line )
143
+ line , _char_only = prepare_text_line (line )
142
144
assert copyrights .is_candidate (line )
143
145
144
146
def test_is_candidate_should_not_select_line_with_junk_hex (self ):
145
147
line = '01061C3F5280CD4AC504152B81E452BD82015442014'
146
- line , _char_only = copyrights . prep_line (line )
148
+ line , _char_only = prepare_text_line (line )
147
149
assert not copyrights .is_candidate (line )
148
150
149
151
def test_is_candidate_should_select_line_with_a_trailing_years (self ):
150
152
line = '01061C3F5280CD4AC504152B81E452BD820154 2014\n '
151
- line , _char_only = copyrights . prep_line (line )
153
+ line , _char_only = prepare_text_line (line )
152
154
assert copyrights .is_candidate (line )
153
155
154
156
def test_is_candidate_should_select_line_with_proper_years (self ):
155
157
line = '01061C3F5280CD4AC504152B81E452BD820154 2014-'
156
- line , _char_only = copyrights . prep_line (line )
158
+ line , _char_only = prepare_text_line (line )
157
159
assert copyrights .is_candidate (line )
158
160
159
161
def test_is_candidate_should_select_line_with_proper_years2 (self ):
160
162
line = '01061C3F5280CD4,2016 152B81E452BD820154'
161
- line , _char_only = copyrights . prep_line (line )
163
+ line , _char_only = prepare_text_line (line )
162
164
assert copyrights .is_candidate (line )
163
165
164
166
def test_is_candidate_should_select_line_with_dashed_year (self ):
165
167
line = 'pub 1024D/CCD6F801 2006-11-15'
166
- line , _char_only = copyrights . prep_line (line )
168
+ line , _char_only = prepare_text_line (line )
167
169
assert copyrights .is_candidate (line )
168
170
169
171
def test_is_candidate_should_select_line_with_iso_date_year (self ):
170
172
line = 'sig 3 ccd6f801 2006-11-15 nathan mittler <[email protected] >'
171
- line , _char_only = copyrights . prep_line (line )
173
+ line , _char_only = prepare_text_line (line )
172
174
assert copyrights .is_candidate (line )
173
175
174
176
def test_is_candidate_should_not_select_lines_made_only_of_punct_and_digits (self ):
@@ -189,7 +191,7 @@ def test_is_candidate_should_not_select_lines_made_only_of_punct_and_digits(self
189
191
''' .splitlines ()
190
192
191
193
for line in lines :
192
- line , _ = copyrights . prep_line (line )
194
+ line , _ = prepare_text_line (line )
193
195
assert not copyrights .is_candidate (line )
194
196
195
197
0 commit comments