Back to index

plone3  3.1.7
Functions
plone.i18n.normalizer.tests.test_normalizer Namespace Reference

Functions

def configurationSetUp
def testIDNormalizer
def testLocaleAwareIDNormalizer
def testFileNameNormalizer
def testLocaleAwareFileNameNormalizer
def testURLNormalizer
def testLocaleAwareURLNormalizer
def test_suite

Function Documentation

Definition at line 21 of file test_normalizer.py.

00021 
00022 def configurationSetUp(self):
00023     setUp()
00024     XMLConfig('meta.zcml', zope.component)()
00025     XMLConfig('configure.zcml', plone.i18n.normalizer)()
00026 

Here is the call graph for this function:

Definition at line 260 of file test_normalizer.py.

00260 
00261 def test_suite():
00262     return unittest.TestSuite((
00263         DocTestSuite('plone.i18n.normalizer'),
00264         DocTestSuite('plone.i18n.normalizer.base'),
00265         DocTestSuite('plone.i18n.normalizer.de'),
00266         DocTestSuite('plone.i18n.normalizer.el'),
00267         DocTestSuite('plone.i18n.normalizer.fr'),
00268         DocTestSuite('plone.i18n.normalizer.pl'),
00269         DocTestSuite('plone.i18n.normalizer.ru'),
00270         DocTestSuite('plone.i18n.normalizer.tr'),
00271         DocTestSuite(setUp=configurationSetUp,
00272                      tearDown=tearDown,
00273                      optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
00274         ))

  >>> util = queryUtility(IFileNameNormalizer)
  >>> util
  <plone.i18n.normalizer.FileNameNormalizer object at ...>
  
  >>> util.normalize(u'simpleandsafe')
  'simpleandsafe'

  >>> util.normalize(u' Whitespace and capital Letters  ')
  'Whitespace and capital Letters'

  >>> util.normalize(u">here's another!")
  'heres another'

  >>> util.normalize(u">>>here'!--s yet another!!!")
  'here-s yet another'

  >>> util.normalize(u"{[(me too)]}")
  'me too'

  >>> util.normalize("pseudo_filename,pot,#1.doc")
  'pseudo_filename-pot-#1.doc'

  >>> util.normalize(unicode("umläut.doc", 'utf-8'))
  'umlaeut.doc'

  >>> len(util.normalize(u'aa' * 2000))
  1023

  >>> util.normalize(unicode("rest `n` peace", 'utf-8'))
  'rest -n- peace'

  >>> util.normalize(u"short-hello-version", max_length=10)
  'short'

Definition at line 118 of file test_normalizer.py.

00118 
00119 def testFileNameNormalizer():
00120     """
00121       >>> util = queryUtility(IFileNameNormalizer)
00122       >>> util
00123       <plone.i18n.normalizer.FileNameNormalizer object at ...>
00124       
00125       >>> util.normalize(u'simpleandsafe')
00126       'simpleandsafe'
00127 
00128       >>> util.normalize(u' Whitespace and capital Letters  ')
00129       'Whitespace and capital Letters'
00130 
00131       >>> util.normalize(u">here's another!")
00132       'heres another'
00133 
00134       >>> util.normalize(u">>>here'!--s yet another!!!")
00135       'here-s yet another'
00136 
00137       >>> util.normalize(u"{[(me too)]}")
00138       'me too'
00139 
00140       >>> util.normalize("pseudo_filename,pot,#1.doc")
00141       'pseudo_filename-pot-#1.doc'
00142 
00143       >>> util.normalize(unicode("umläut.doc", 'utf-8'))
00144       'umlaeut.doc'
00145 
00146       >>> len(util.normalize(u'aa' * 2000))
00147       1023
00148 
00149       >>> util.normalize(unicode("rest `n` peace", 'utf-8'))
00150       'rest -n- peace'
00151 
00152       >>> util.normalize(u"short-hello-version", max_length=10)
00153       'short'
00154     """
00155 

  >>> util = queryUtility(IIDNormalizer)
  >>> util
  <plone.i18n.normalizer.IDNormalizer object at ...>

  >>> util.normalize(u'simpleandsafe')
  'simpleandsafe'

  >>> util.normalize(u' Whitespace and capital Letters  ')
  'whitespace-and-capital-letters'

  >>> util.normalize(u">here's another!")
  'heres-another'

  >>> util.normalize(u">>>here'!--s yet another!!!")
  'here-s-yet-another'

  >>> util.normalize(unicode("umläut.doc", 'utf-8'))
  'umlaeut.doc'

  >>> from plone.i18n.normalizer import MAX_LENGTH
  
  >>> testString = u"thissentenceiswaytolongtobecroppedwithoutcuttedbythenormalizemethodbecauseithasnoplacetocrop"
  >>> util.normalize(testString)
  'thissentenceiswaytolongtobecroppedwithoutcuttedbyt'
  >>> len(util.normalize(testString)) == MAX_LENGTH
  True

  >>> testString = u"thissentenceisacropped-by-the-normalize-method-because-it-has-many-places-to-crop"
  >>> util.normalize(testString)
  'thissentenceisacropped-by-the-normalize-method'
  >>> len(util.normalize(testString)) <= MAX_LENGTH
  True

  >>> testString = u"this-sentence-is-way-to-long-but-can-be-cropped-by-the-normalize-method-because-it-has-many-places-to-crop"
  >>> util.normalize(testString)
  'this-sentence-is-way-to-long-but-can-be-cropped-by'
  >>> len(util.normalize(testString)) <= MAX_LENGTH
  True

  >>> util.normalize(unicode("rest `n` peace", 'utf-8'))
  'rest-n-peace'

  >>> util.normalize(u"short-hello-version", max_length=10)
  'short'

  >>> util.normalize(u"short-hello-version", max_length=15)
  'short-hello'

Definition at line 27 of file test_normalizer.py.

00027 
00028 def testIDNormalizer():
00029     """
00030       >>> util = queryUtility(IIDNormalizer)
00031       >>> util
00032       <plone.i18n.normalizer.IDNormalizer object at ...>
00033 
00034       >>> util.normalize(u'simpleandsafe')
00035       'simpleandsafe'
00036 
00037       >>> util.normalize(u' Whitespace and capital Letters  ')
00038       'whitespace-and-capital-letters'
00039 
00040       >>> util.normalize(u">here's another!")
00041       'heres-another'
00042 
00043       >>> util.normalize(u">>>here'!--s yet another!!!")
00044       'here-s-yet-another'
00045 
00046       >>> util.normalize(unicode("umläut.doc", 'utf-8'))
00047       'umlaeut.doc'
00048 
00049       >>> from plone.i18n.normalizer import MAX_LENGTH
00050       
00051       >>> testString = u"thissentenceiswaytolongtobecroppedwithoutcuttedbythenormalizemethodbecauseithasnoplacetocrop"
00052       >>> util.normalize(testString)
00053       'thissentenceiswaytolongtobecroppedwithoutcuttedbyt'
00054       >>> len(util.normalize(testString)) == MAX_LENGTH
00055       True
00056 
00057       >>> testString = u"thissentenceisacropped-by-the-normalize-method-because-it-has-many-places-to-crop"
00058       >>> util.normalize(testString)
00059       'thissentenceisacropped-by-the-normalize-method'
00060       >>> len(util.normalize(testString)) <= MAX_LENGTH
00061       True
00062 
00063       >>> testString = u"this-sentence-is-way-to-long-but-can-be-cropped-by-the-normalize-method-because-it-has-many-places-to-crop"
00064       >>> util.normalize(testString)
00065       'this-sentence-is-way-to-long-but-can-be-cropped-by'
00066       >>> len(util.normalize(testString)) <= MAX_LENGTH
00067       True
00068 
00069       >>> util.normalize(unicode("rest `n` peace", 'utf-8'))
00070       'rest-n-peace'
00071 
00072       >>> util.normalize(u"short-hello-version", max_length=10)
00073       'short'
00074 
00075       >>> util.normalize(u"short-hello-version", max_length=15)
00076       'short-hello'
00077     """
00078 

  >>> util = queryUtility(IFileNameNormalizer)
  >>> util
  <plone.i18n.normalizer.FileNameNormalizer object at ...>

  >>> util.normalize(u'simpleandsafe', locale='de')
  'simpleandsafe'

  >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
  'text with umlaeut'

Make sure we get the de normalizer as there's no special one for de_DE
registered.
   
  >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
  'text with umlaeut'

  >>> util.normalize(u'simpleandsafe', locale='pt_BR')
  'simpleandsafe'

  >>> util.normalize(u'simpleandsafe', locale='sr@Latn')
  'simpleandsafe'

  >>> util.normalize(u"short-hello-version", locale='de_DE', max_length=10)
  'short'

Definition at line 156 of file test_normalizer.py.

00156 
00157 def testLocaleAwareFileNameNormalizer():
00158     """
00159       >>> util = queryUtility(IFileNameNormalizer)
00160       >>> util
00161       <plone.i18n.normalizer.FileNameNormalizer object at ...>
00162 
00163       >>> util.normalize(u'simpleandsafe', locale='de')
00164       'simpleandsafe'
00165 
00166       >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
00167       'text with umlaeut'
00168 
00169     Make sure we get the de normalizer as there's no special one for de_DE
00170     registered.
00171        
00172       >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
00173       'text with umlaeut'
00174 
00175       >>> util.normalize(u'simpleandsafe', locale='pt_BR')
00176       'simpleandsafe'
00177 
00178       >>> util.normalize(u'simpleandsafe', locale='sr@Latn')
00179       'simpleandsafe'
00180 
00181       >>> util.normalize(u"short-hello-version", locale='de_DE', max_length=10)
00182       'short'
00183     """
00184 

  >>> util = queryUtility(IIDNormalizer)
  >>> util
  <plone.i18n.normalizer.IDNormalizer object at ...>

Register the German file name normalizer as an id normalizer as well, to
test the locale-aware id normalization logic:

  >>> de_util = queryUtility(IFileNameNormalizer, name='de')
  >>> sm = zope.component.getGlobalSiteManager()
  >>> sm.registerUtility(de_util, IIDNormalizer, name='de')

  >>> util.normalize(u'simpleandsafe', locale='de')
  'simpleandsafe'

  >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
  'text-with-umlaeut'

Make sure we get the de normalizer as there's no special one for de_DE
registered.
   
  >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
  'text-with-umlaeut'

  >>> util.normalize(u'simpleandsafe', locale='pt_BR')
  'simpleandsafe'

  >>> util.normalize(u'simpleandsafe', locale='sr@Latn')
  'simpleandsafe'

  >>> util.normalize(u"short-hello-version", locale='de_DE', max_length=10)
  'short'

  >>> util.normalize(u"short-hello-version", locale='de_DE', max_length=15)
  'short-hello'

Definition at line 79 of file test_normalizer.py.

00079 
00080 def testLocaleAwareIDNormalizer():
00081     """
00082       >>> util = queryUtility(IIDNormalizer)
00083       >>> util
00084       <plone.i18n.normalizer.IDNormalizer object at ...>
00085 
00086     Register the German file name normalizer as an id normalizer as well, to
00087     test the locale-aware id normalization logic:
00088 
00089       >>> de_util = queryUtility(IFileNameNormalizer, name='de')
00090       >>> sm = zope.component.getGlobalSiteManager()
00091       >>> sm.registerUtility(de_util, IIDNormalizer, name='de')
00092 
00093       >>> util.normalize(u'simpleandsafe', locale='de')
00094       'simpleandsafe'
00095 
00096       >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
00097       'text-with-umlaeut'
00098 
00099     Make sure we get the de normalizer as there's no special one for de_DE
00100     registered.
00101        
00102       >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
00103       'text-with-umlaeut'
00104 
00105       >>> util.normalize(u'simpleandsafe', locale='pt_BR')
00106       'simpleandsafe'
00107 
00108       >>> util.normalize(u'simpleandsafe', locale='sr@Latn')
00109       'simpleandsafe'
00110 
00111       >>> util.normalize(u"short-hello-version", locale='de_DE', max_length=10)
00112       'short'
00113 
00114       >>> util.normalize(u"short-hello-version", locale='de_DE', max_length=15)
00115       'short-hello'
00116     """
00117 

  >>> util = queryUtility(IURLNormalizer)
  >>> util
  <plone.i18n.normalizer.URLNormalizer object at ...>

  >>> util.normalize(u'simpleandsafe', locale='de')
  'simpleandsafe'

  >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
  'text-with-umlaeut'

Make sure we get the de normalizer as there's no special one for de_DE
registered.
   
  >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
  'text-with-umlaeut'

  >>> util.normalize(u'simpleandsafe', locale='pt_BR')
  'simpleandsafe'

  >>> util.normalize(u'simpleandsafe', locale='sr@Latn')
  'simpleandsafe'

  >>> util.normalize(u"short-hello-version", locale='de_DE', max_length=10)
  'short'

Definition at line 232 of file test_normalizer.py.

00232 
00233 def testLocaleAwareURLNormalizer():
00234     """
00235       >>> util = queryUtility(IURLNormalizer)
00236       >>> util
00237       <plone.i18n.normalizer.URLNormalizer object at ...>
00238 
00239       >>> util.normalize(u'simpleandsafe', locale='de')
00240       'simpleandsafe'
00241 
00242       >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
00243       'text-with-umlaeut'
00244 
00245     Make sure we get the de normalizer as there's no special one for de_DE
00246     registered.
00247        
00248       >>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
00249       'text-with-umlaeut'
00250 
00251       >>> util.normalize(u'simpleandsafe', locale='pt_BR')
00252       'simpleandsafe'
00253 
00254       >>> util.normalize(u'simpleandsafe', locale='sr@Latn')
00255       'simpleandsafe'
00256 
00257       >>> util.normalize(u"short-hello-version", locale='de_DE', max_length=10)
00258       'short'
00259     """

  >>> util = queryUtility(IURLNormalizer)
  >>> util
  <plone.i18n.normalizer.URLNormalizer object at ...>
  
  >>> util.normalize(u'simpleandsafe')
  'simpleandsafe'

  >>> util.normalize(u' Whitespace and capital Letters  ')
  'whitespace-and-capital-letters'

  >>> util.normalize(u">here's another!")
  'heres-another'

  >>> util.normalize(u">>>here'!--s yet another!!!")
  'here-s-yet-another'

  >>> util.normalize(u"Doe, Joe")
  'doe-joe'

  >>> util.normalize(unicode("umläut.doc", 'utf-8'))
  'umlaeut.doc'

  >>> util.normalize('quote "this"!')
  'quote-this'

  >>> util.normalize("quote 'this'!")
  'quote-this'

  >>> util.normalize("I'm not a FILE.txt")
  'im-not-a-file.txt'

  >>> util.normalize("I'm a big file.TXT")
  'im-a-big-file.txt'

  >>> util.normalize(unicode("rest `n` peace", 'utf-8'))
  'rest-n-peace'

  >>> len(util.normalize(u'aa' * 2000))
  255

  >>> util.normalize(u"short-hello-version", max_length=10)
  'short'

Definition at line 185 of file test_normalizer.py.

00185 
00186 def testURLNormalizer():
00187     """
00188       >>> util = queryUtility(IURLNormalizer)
00189       >>> util
00190       <plone.i18n.normalizer.URLNormalizer object at ...>
00191       
00192       >>> util.normalize(u'simpleandsafe')
00193       'simpleandsafe'
00194 
00195       >>> util.normalize(u' Whitespace and capital Letters  ')
00196       'whitespace-and-capital-letters'
00197 
00198       >>> util.normalize(u">here's another!")
00199       'heres-another'
00200 
00201       >>> util.normalize(u">>>here'!--s yet another!!!")
00202       'here-s-yet-another'
00203 
00204       >>> util.normalize(u"Doe, Joe")
00205       'doe-joe'
00206 
00207       >>> util.normalize(unicode("umläut.doc", 'utf-8'))
00208       'umlaeut.doc'
00209 
00210       >>> util.normalize('quote "this"!')
00211       'quote-this'
00212 
00213       >>> util.normalize("quote 'this'!")
00214       'quote-this'
00215 
00216       >>> util.normalize("I'm not a FILE.txt")
00217       'im-not-a-file.txt'
00218 
00219       >>> util.normalize("I'm a big file.TXT")
00220       'im-a-big-file.txt'
00221 
00222       >>> util.normalize(unicode("rest `n` peace", 'utf-8'))
00223       'rest-n-peace'
00224 
00225       >>> len(util.normalize(u'aa' * 2000))
00226       255
00227 
00228       >>> util.normalize(u"short-hello-version", max_length=10)
00229       'short'
00230     """
00231