/usr/lib/python3/dist-packages/pytils/test/test_typo.py is in python3-pytils 0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | # -*- coding: utf-8 -*-
"""
Unit-tests for pytils.typo
"""
import unittest
import os
from pytils import typo
def cb_testrule(x):
return x
class HelpersTestCase(unittest.TestCase):
"""
Test case for pytils.typo helpers
"""
def testGetRuleByName(self):
"""
unit-test for pytils.typo._get_rule_by_name
"""
self.assert_(
callable(
typo._get_rule_by_name('testrule')
))
self.assertEquals(
'rl_testrule',
typo._get_rule_by_name('testrule').__name__
)
def testResolveRule(self):
"""
unit-test for pytils.typo._resolve_rule
"""
self.assert_(
callable(
typo._resolve_rule_name('testrule')[1]
))
self.assert_(
callable(
typo._resolve_rule_name(cb_testrule)[1]
))
self.assertEquals(
'testrule',
typo._resolve_rule_name('testrule')[0]
)
self.assertEquals(
'cb_testrule',
typo._resolve_rule_name(cb_testrule)[0]
)
def testResolveRuleWithForcedName(self):
"""
unit-test for pytils.typo._resolve_rule with forced_name arg
"""
self.assert_(
callable(typo._resolve_rule_name('testrule', 'newrule')[1]
))
self.assert_(
callable(typo._resolve_rule_name(cb_testrule, 'newrule')[1]
))
self.assertEquals(
'newrule',
typo._resolve_rule_name('testrule', 'newrule')[0]
)
self.assertEquals(
'newrule',
typo._resolve_rule_name(cb_testrule, 'newrule')[0]
)
class TypographyApplierTestCase(unittest.TestCase):
"""
Test case for typography rule applier pytils.typo.Typography
"""
def testExpandEmptyArgs(self):
self.assertEquals(
{},
typo.Typography().rules
)
self.assertEquals(
[],
typo.Typography().rules_names
)
def testExpandSimpleStrArgs(self):
self.assertEquals(
{'testrule': typo.rl_testrule},
typo.Typography('testrule').rules
)
self.assertEquals(
['testrule'],
typo.Typography('testrule').rules_names
)
def testExpandDictStrArgs(self):
self.assertEquals(
{
'testrule': typo.rl_testrule,
'newrule': typo.rl_testrule
},
typo.Typography('testrule', {'newrule': 'testrule'}).rules
)
self.assertEquals(
['testrule', 'newrule'],
typo.Typography('testrule', {'newrule': 'testrule'}).rules_names
)
def testExpandSimpleCallableArgs(self):
self.assertEquals(
{'cb_testrule': cb_testrule},
typo.Typography(cb_testrule).rules
)
self.assertEquals(
['cb_testrule'],
typo.Typography(cb_testrule).rules_names
)
def testExpandDictCallableArgs(self):
self.assertEquals(
{
'cb_testrule': cb_testrule,
'newrule': cb_testrule
},
typo.Typography(cb_testrule, {'newrule': cb_testrule}).rules
)
self.assertEquals(
['cb_testrule', 'newrule'],
typo.Typography(cb_testrule, {'newrule': cb_testrule}).rules_names
)
def testExpandMixedArgs(self):
self.assertEquals(
{
'cb_testrule': cb_testrule,
'newrule': typo.rl_testrule
},
typo.Typography(cb_testrule, newrule='testrule').rules
)
self.assertEquals(
['cb_testrule', 'newrule'],
typo.Typography(cb_testrule, newrule='testrule').rules_names
)
self.assertEquals(
{
'cb_testrule': cb_testrule,
'testrule': typo.rl_testrule
},
typo.Typography(cb_testrule, 'testrule').rules
)
self.assertEquals(
['cb_testrule', 'testrule'],
typo.Typography(cb_testrule, 'testrule').rules_names
)
def testRecommendedArgsStyle(self):
lambdarule = lambda x: x
self.assertEquals(
{
'cb_testrule': cb_testrule,
'testrule': typo.rl_testrule,
'newrule': lambdarule
},
typo.Typography([cb_testrule], ['testrule'], {'newrule': lambdarule}).rules
)
self.assertEquals(
['cb_testrule', 'testrule', 'newrule'],
typo.Typography([cb_testrule], ['testrule'], {'newrule': lambdarule}).rules_names
)
class RulesTestCase(unittest.TestCase):
def checkRule(self, name, input_value, expected_result):
"""
Check how rule is acted on input_value with expected_result
"""
self.assertEquals(
expected_result,
typo._get_rule_by_name(name)(input_value)
)
def testCleanspaces(self):
"""
Unit-test for cleanspaces rule
"""
self.checkRule(
'cleanspaces',
u" Точка ,точка , запятая, вышла рожица кривая . ",
u"Точка, точка, запятая, вышла рожица кривая."
)
self.checkRule(
'cleanspaces',
u" Точка ,точка , %(n)sзапятая,%(n)s вышла рожица кривая . " % {'n': os.linesep},
u"Точка, точка,%(n)sзапятая,%(n)sвышла рожица кривая." % {'n': os.linesep}
)
self.checkRule(
'cleanspaces',
u"Газета ( ее принес мальчишка утром ) всё еще лежала на столе.",
u"Газета (ее принес мальчишка утром) всё еще лежала на столе.",
)
self.checkRule(
'cleanspaces',
u"Газета, утром принесенная мальчишкой ( это был сосед, подзарабатывающий летом ) , всё еще лежала на столе.",
u"Газета, утром принесенная мальчишкой (это был сосед, подзарабатывающий летом), всё еще лежала на столе.",
)
self.checkRule(
'cleanspaces',
u"Что это?!?!",
u"Что это?!?!",
)
def testEllipsis(self):
"""
Unit-test for ellipsis rule
"""
self.checkRule(
'ellipsis',
u"Быть или не быть, вот в чем вопрос...%(n)s%(n)sШекспир" % {'n': os.linesep},
u"Быть или не быть, вот в чем вопрос…%(n)s%(n)sШекспир" % {'n': os.linesep}
)
self.checkRule(
'ellipsis',
u"Мдя..... могло быть лучше",
u"Мдя..... могло быть лучше"
)
self.checkRule(
'ellipsis',
u"...Дааааа",
u"…Дааааа"
)
self.checkRule(
'ellipsis',
u"... Дааааа",
u"…Дааааа"
)
def testInitials(self):
"""
Unit-test for initials rule
"""
self.checkRule(
'initials',
u'Председатель В.И.Иванов выступил на собрании',
u'Председатель В.И.\u2009Иванов выступил на собрании',
)
self.checkRule(
'initials',
u'Председатель В.И. Иванов выступил на собрании',
u'Председатель В.И.\u2009Иванов выступил на собрании',
)
self.checkRule(
'initials',
u'1. В.И.Иванов%(n)s2. С.П.Васечкин'% {'n': os.linesep},
u'1. В.И.\u2009Иванов%(n)s2. С.П.\u2009Васечкин' % {'n': os.linesep}
)
self.checkRule(
'initials',
u'Комиссия в составе директора В.И.Иванова и главного бухгалтера С.П.Васечкина постановила',
u'Комиссия в составе директора В.И.\u2009Иванова и главного бухгалтера С.П.\u2009Васечкина постановила'
)
def testDashes(self):
"""
Unit-test for dashes rule
"""
self.checkRule(
'dashes',
u'- Я пошел домой... - Может останешься? - Нет, ухожу.',
u'\u2014 Я пошел домой... \u2014 Может останешься? \u2014 Нет, ухожу.'
)
self.checkRule(
'dashes',
u'-- Я пошел домой... -- Может останешься? -- Нет, ухожу.',
u'\u2014 Я пошел домой... \u2014 Может останешься? \u2014 Нет, ухожу.'
)
self.checkRule(
'dashes',
u'-- Я\u202fпошел домой…\u202f-- Может останешься?\u202f-- Нет,\u202fухожу.',
u'\u2014 Я\u202fпошел домой…\u202f\u2014 Может останешься?\u202f\u2014 Нет,\u202fухожу.'
)
self.checkRule(
'dashes',
u'Ползать по-пластунски',
u'Ползать по-пластунски',
)
self.checkRule(
'dashes',
u'Диапазон: 9-15',
u'Диапазон: 9\u201315',
)
def testWordglue(self):
"""
Unit-test for wordglue rule
"""
self.checkRule(
'wordglue',
u'Вроде бы он согласен',
u'Вроде\u202fбы\u202fон\u202fсогласен',
)
self.checkRule(
'wordglue',
u'Он не поверил своим глазам',
u'Он\u202fне\u202fповерил своим\u202fглазам',
)
self.checkRule(
'wordglue',
u'Это - великий и ужасный Гудвин',
u'Это\u202f- великий и\u202fужасный\u202fГудвин',
)
self.checkRule(
'wordglue',
u'Это \u2014 великий и ужасный Гудвин',
u'Это\u202f\u2014 великий и\u202fужасный\u202fГудвин',
)
self.checkRule(
'wordglue',
u'-- Я пошел домой… -- Может останешься? -- Нет, ухожу.',
u'-- Я\u202fпошел домой…\u202f-- Может останешься?\u202f-- Нет,\u202fухожу.'
)
self.checkRule(
'wordglue',
u'увидел в газете (это была "Сермяжная правда" № 45) рубрику Weather Forecast',
u'увидел в\u202fгазете (это\u202fбыла "Сермяжная правда" № 45) рубрику Weather\u202fForecast',
)
def testMarks(self):
"""
Unit-test for marks rule
"""
self.checkRule(
'marks',
u"Когда В. И. Пупкин увидел в газете рубрику Weather Forecast(r), он не поверил своим глазам \u2014 температуру обещали +-451F.",
u"Когда В. И. Пупкин увидел в газете рубрику Weather Forecast®, он не поверил своим глазам \u2014 температуру обещали ±451\u202f°F."
)
self.checkRule(
'marks',
u"14 Foo",
u"14 Foo"
)
self.checkRule(
'marks',
u"Coca-cola(tm)",
u"Coca-cola™"
)
self.checkRule(
'marks',
u'(c) 2008 Юрий Юревич',
u'©\u202f2008 Юрий Юревич'
)
self.checkRule(
'marks',
u"Microsoft (R) Windows (tm)",
u"Microsoft® Windows™"
)
self.checkRule(
'marks',
u"Школа-гимназия No 3",
u"Школа-гимназия №\u20093",
)
self.checkRule(
'marks',
u"Школа-гимназия No3",
u"Школа-гимназия №\u20093",
)
self.checkRule(
'marks',
u"Школа-гимназия №3",
u"Школа-гимназия №\u20093",
)
def testQuotes(self):
"""
Unit-test for quotes rule
"""
self.checkRule(
'quotes',
u"ООО \"МСК \"Аско-Забота\"",
u"ООО «МСК «Аско-Забота»"
)
self.checkRule(
'quotes',
u"ООО\u202f\"МСК\u202f\"Аско-Забота\"",
u"ООО\u202f«МСК\u202f«Аско-Забота»"
)
self.checkRule(
'quotes',
u"Двигатели 'Pratt&Whitney'",
u"Двигатели “Pratt&Whitney”"
)
self.checkRule(
'quotes',
u"\"Вложенные \"кавычки\" - бич всех типографик\", не правда ли",
u"«Вложенные «кавычки» - бич всех типографик», не правда ли",
)
self.checkRule(
'quotes',
u"Двигатели 'Pratt&Whitney' никогда не использовались на самолетах \"Аэрофлота\"",
u"Двигатели “Pratt&Whitney” никогда не использовались на самолетах «Аэрофлота»"
)
class TypographyTestCase(unittest.TestCase):
"""
Tests for pytils.typo.typography
"""
def checkTypo(self, input_value, expected_value):
"""
Helper for checking typo.typography
"""
self.assertEquals(expected_value, typo.typography(input_value))
def testPupkin(self):
"""
Unit-test on pupkin-text
"""
self.checkTypo(
u"""...Когда В. И. Пупкин увидел в газете ( это была "Сермяжная правда" № 45) рубрику Weather Forecast(r), он не поверил своим глазам - температуру обещали +-451F.""",
u"""…Когда В.И.\u2009Пупкин увидел в\u202fгазете (это\u202fбыла «Сермяжная правда» №\u200945) рубрику Weather Forecast®, он\u202fне\u202fповерил своим глазам\u202f\u2014 температуру обещали ±451\u202f°F.""")
if __name__ == '__main__':
unittest.main()
|