diff options
| author | Val Neekman <val@neekware.com> | 2016-08-26 11:29:43 -0400 |
|---|---|---|
| committer | Val Neekman <val@neekware.com> | 2016-08-26 11:29:43 -0400 |
| commit | 7699d5a67a33239308a83f5dc4669f714af4123a (patch) | |
| tree | f64ff6c6bccce16846fe1a8fd518202093157390 | |
| parent | a5ef6fa3370f8dd278a47dc195fca30d661c156e (diff) | |
| download | python-slugify-7699d5a67a33239308a83f5dc4669f714af4123a.tar.gz | |
add more tests
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rwxr-xr-x | pep8.sh | 7 | ||||
| -rw-r--r-- | slugify/slugify.py | 6 | ||||
| -rw-r--r-- | test.py | 13 |
4 files changed, 19 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 152c5f1..1d2b7c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Including certain files (e.g. license.md) in sdists via MANIFEST.in (@proinsias) - Relax licensing by moving from BSD to MIT - Add Python 3.5 support + - Add more tests ## 1.2.0 @@ -1,14 +1,11 @@ #!/bin/bash -echo -e "\nRunning: pep8 ... \n" - # Ignoring autogenerated files # -- Migration directories # Ignoring error codes # -- E128 continuation line under-indented for visual indent +# -- E261 at least two spaces before inline comment # -- E225 missing whitespace around operator # -- E501 line too long -pep8 --ignore=E128,E225,E501 slugify test.py setup.py - -echo -e "Done.\n" +pep8 --ignore=E128,E261,E225,E501 slugify test.py setup.py diff --git a/slugify/slugify.py b/slugify/slugify.py index 113afdd..327f2c1 100644 --- a/slugify/slugify.py +++ b/slugify/slugify.py @@ -16,7 +16,7 @@ except ImportError: import unidecode -__all__ = ['slugify'] +__all__ = ['slugify', 'smart_truncate'] CHAR_ENTITY_PATTERN = re.compile('&(%s);' % '|'.join(name2codepoint)) @@ -65,7 +65,7 @@ def smart_truncate(string, max_length=0, word_boundaries=False, separator=' ', s else: if save_order: break - if not truncated: + if not truncated: # pragma: no cover truncated = string[:max_length] return truncated.strip(separator) @@ -152,7 +152,7 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w return text -def main(): +def main(): # pragma: no cover if len(sys.argv) < 2: print("Usage %s TEXT TO SLUGIFY" % sys.argv[0]) else: @@ -2,6 +2,7 @@ import unittest from slugify import slugify +from slugify import smart_truncate class TestSlugification(unittest.TestCase): @@ -167,5 +168,17 @@ class TestSlugification(unittest.TestCase): self.assertEqual(r, '1000-reasons-you-are-1') +class TestUtils(unittest.TestCase): + + def test_smart_truncate_no_max_length(self): + txt = '1,000 reasons you are #1' + r = smart_truncate(txt) + self.assertEqual(r, txt) + + def test_smart_truncate_no_seperator(self): + txt = '1,000 reasons you are #1' + r = smart_truncate(txt, max_length=100, separator='_') + self.assertEqual(r, txt) + if __name__ == '__main__': unittest.main() |
