Skip to content

Commit 7699d5a

Browse files
committed
add more tests
1 parent a5ef6fa commit 7699d5a

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Including certain files (e.g. license.md) in sdists via MANIFEST.in (@proinsias)
33
- Relax licensing by moving from BSD to MIT
44
- Add Python 3.5 support
5+
- Add more tests
56

67
## 1.2.0
78

pep8.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#!/bin/bash
22

3-
echo -e "\nRunning: pep8 ... \n"
4-
53
# Ignoring autogenerated files
64
# -- Migration directories
75
# Ignoring error codes
86
# -- E128 continuation line under-indented for visual indent
7+
# -- E261 at least two spaces before inline comment
98
# -- E225 missing whitespace around operator
109
# -- E501 line too long
1110

12-
pep8 --ignore=E128,E225,E501 slugify test.py setup.py
13-
14-
echo -e "Done.\n"
11+
pep8 --ignore=E128,E261,E225,E501 slugify test.py setup.py

slugify/slugify.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import unidecode
1717

1818

19-
__all__ = ['slugify']
19+
__all__ = ['slugify', 'smart_truncate']
2020

2121

2222
CHAR_ENTITY_PATTERN = re.compile('&(%s);' % '|'.join(name2codepoint))
@@ -65,7 +65,7 @@ def smart_truncate(string, max_length=0, word_boundaries=False, separator=' ', s
6565
else:
6666
if save_order:
6767
break
68-
if not truncated:
68+
if not truncated: # pragma: no cover
6969
truncated = string[:max_length]
7070
return truncated.strip(separator)
7171

@@ -152,7 +152,7 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
152152
return text
153153

154154

155-
def main():
155+
def main(): # pragma: no cover
156156
if len(sys.argv) < 2:
157157
print("Usage %s TEXT TO SLUGIFY" % sys.argv[0])
158158
else:

test.py

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import unittest
44
from slugify import slugify
5+
from slugify import smart_truncate
56

67

78
class TestSlugification(unittest.TestCase):
@@ -167,5 +168,17 @@ def test_numbers_and_symbols(self):
167168
self.assertEqual(r, '1000-reasons-you-are-1')
168169

169170

171+
class TestUtils(unittest.TestCase):
172+
173+
def test_smart_truncate_no_max_length(self):
174+
txt = '1,000 reasons you are #1'
175+
r = smart_truncate(txt)
176+
self.assertEqual(r, txt)
177+
178+
def test_smart_truncate_no_seperator(self):
179+
txt = '1,000 reasons you are #1'
180+
r = smart_truncate(txt, max_length=100, separator='_')
181+
self.assertEqual(r, txt)
182+
170183
if __name__ == '__main__':
171184
unittest.main()

0 commit comments

Comments
 (0)