stackalytics/tests/unit/test_utils.py
Ilya Shakhat 2a7ee69fb8 Long URLs are diluted with zero-width whitespaces
Zero-width spaces affect wrapping the same way as normal spaces but have no width.
Also added moved text formatting code into utils.

Closes bug 1229723

Change-Id: If6de83b6bf4125e8d48de203fe2d5cd935b20757
2013-09-24 18:23:01 +04:00

67 lines
2.3 KiB
Python

# Copyright (c) 2013 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import testtools
from stackalytics.processor import utils
class TestUtils(testtools.TestCase):
def setUp(self):
super(TestUtils, self).setUp()
def _test_one_range(self, start, end, step):
elements = set()
for chunk in utils.make_range(start, end, step):
for item in chunk:
self.assertFalse(item in elements)
elements.add(item)
self.assertTrue(set(range(start, end)) == elements)
def test_make_range_0_10_1(self):
self._test_one_range(0, 10, 1)
def test_make_range_0_10_3(self):
self._test_one_range(0, 10, 3)
def test_make_range_3_5_4(self):
self._test_one_range(3, 5, 4)
def test_make_range_5_26_10(self):
self._test_one_range(5, 26, 10)
def test_email_valid(self):
self.assertTrue(utils.check_email_validity('pupkin@gmail.com'))
self.assertTrue(utils.check_email_validity('v.pup_kin2@ntt.co.jp'))
def test_email_invalid(self):
self.assertFalse(utils.check_email_validity('pupkin@localhost'))
self.assertFalse(utils.check_email_validity('222@some.(trash)'))
def test_unwrap(self):
original = 'Lorem ipsum. Dolor\nsit amet.\n Lorem\n ipsum.\ndolor!\n'
expected = 'Lorem ipsum. Dolor sit amet.\n Lorem\n ipsum.\ndolor!'
self.assertEqual(expected, utils.unwrap_text(original))
def test_format_text_split_long_link(self):
original = ('https://blueprints.launchpad.net/stackalytics/+spec/'
'stackalytics-core')
expected = ('https://​blueprints.launchpad.net/​'
'stackalytics/​+spec/​stackalytics-core')
self.assertEqual(expected, utils.format_text(original))