Skip to content

Commit 0156624

Browse files
authored
Merge branch 'master' into feature/faster_address_exclude
2 parents 79570a7 + 1ef9f32 commit 0156624

File tree

5 files changed

+83
-7
lines changed

5 files changed

+83
-7
lines changed

Diff for: .travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ python:
33
- "3.6"
44
- "3.7"
55
# command to install dependencies
6-
install: "pip install -r requirements.txt . && pip install flake8"
6+
install: "pip install -r requirements.txt -r test-requirements.txt . && pip install flake8"
77
# command to run tests
88
script:
99
- pytest
10-
- flake8 . --count --select=W291,W293,W391 --statistics
10+
- flake8 . --count --select=W291,W293,W391 --statistic

Diff for: capirca/lib/aclgenerator.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,12 @@ def WrapWords(textlist, size, joiner='\n'):
556556
Returns:
557557
list of strings
558558
"""
559-
# \S*? is a non greedy match to collect words of len > size
560-
# .{1,%d} collects words and spaces up to size in length.
561-
# (?:\s|\Z) ensures that we break on spaces or at end of string.
559+
# \S{%d}(?!\s|\Z) collets the max size for words that are larger than the max
560+
# (?<=\S{%d})\S+ collects the remaining text for overflow words in their own line
561+
# \S.{1,%d}(?=\s|\Z)) collects all words and spaces up to max size, breaking at
562+
# the last space
562563
rval = []
563-
linelength_re = re.compile(r'(\S*?.{1,%d}(?:\s|\Z))' % size)
564+
linelength_re = re.compile(r'(\S{%d}(?!\s|\Z)|(?<=\S{%d})\S+|\S.{1,%d}(?=\s|\Z))' % (size, size, size-1))
564565
for index in range(len(textlist)):
565566
if len(textlist[index]) > size:
566567
# insert joiner into the string at appropriate places.

Diff for: requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
ipaddress>=1.0.22
66
absl-py
77
ply
8-
mock
98
six>=1.12.0

Diff for: test-requirements.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
attrs==19.3.0
2+
importlib-metadata==1.6.1
3+
mock==4.0.2
4+
more-itertools==8.3.0
5+
packaging==20.4
6+
pluggy==0.13.1
7+
py==1.8.1
8+
pyparsing==2.4.7
9+
pytest==5.4.3
10+
wcwidth==0.2.3
11+
zipp==3.1.0

Diff for: tests/unit/wrapwords_test.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from capirca.lib.aclgenerator import WrapWords
2+
import pytest
3+
4+
SINGLE_LINE_OVERFLOW_TEXT_LONG = \
5+
"http://github.com/google/capirca/commit/c5" + \
6+
"6ddf19e2679892ff078cf27aeb18310c2697ed This " + \
7+
"is a long header. It's long on purpose. It's " + \
8+
"purpose is to test that the splitting works co" + \
9+
"rrectly. It should be well over the line limit" + \
10+
". If it is shorter, it would not test the limit."
11+
12+
SINGLE_LINE_OVERFLOW_TEXT_LONG_EXPECTED = [
13+
"http://github.com/google/capirca/commit/c56ddf19e2679892ff078cf27aeb18",
14+
"310c2697ed",
15+
"This is a long header. It's long on purpose. It's purpose is to test",
16+
"that the splitting works correctly. It should be well over the line",
17+
"limit. If it is shorter, it would not test the limit."
18+
]
19+
20+
MULTI_LINE_OVERFLOW_TEXT_LONG = \
21+
"this is a veryveryveryveryveryveryveryveryver" + \
22+
"yveryveryveryveryveryveryveryveryveryveryvery" + \
23+
"veryveryveryveryveryveryveryveryveryveryveryv" + \
24+
"eryveryveryveryveryveryveryveryveryveryvery long word"
25+
26+
MULTI_LINE_OVERFLOW_TEXT_LONG_EXPECTED = [
27+
"this is a",
28+
"veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryve",
29+
"ryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryvery",
30+
"veryveryveryveryveryveryvery",
31+
"long word"
32+
]
33+
34+
NO_OVERFLOW_LONG = \
35+
"This " + \
36+
"is a long header. It's long on purpose. It's " + \
37+
"purpose is to test that the splitting works co" + \
38+
"rrectly. It should be well over the line limit" + \
39+
". If it is shorter, it would not test the limit."
40+
41+
NO_OVERFLOW_LONG_EXPECTED = [
42+
"This is a long header. It's long on purpose. It's purpose is to test",
43+
"that the splitting works correctly. It should be well over the line",
44+
"limit. If it is shorter, it would not test the limit."
45+
]
46+
47+
NO_OVERFLOW_SHORT = \
48+
"This is a short line of text"
49+
50+
NO_OVERFLOW_SHORT_EXPECTED = [
51+
"This is a short line of text"
52+
]
53+
54+
@pytest.mark.parametrize("test_input,expected", [
55+
(NO_OVERFLOW_SHORT, NO_OVERFLOW_SHORT_EXPECTED),
56+
(NO_OVERFLOW_LONG, NO_OVERFLOW_LONG_EXPECTED),
57+
(SINGLE_LINE_OVERFLOW_TEXT_LONG, SINGLE_LINE_OVERFLOW_TEXT_LONG_EXPECTED),
58+
(MULTI_LINE_OVERFLOW_TEXT_LONG, MULTI_LINE_OVERFLOW_TEXT_LONG_EXPECTED)
59+
]
60+
)
61+
62+
63+
def testWrapWords(test_input, expected):
64+
result = WrapWords([test_input], 70)
65+
assert all((res == exp for res, exp in zip(result, expected)))

0 commit comments

Comments
 (0)