comparison MoinMoin/_tests/test_wikiutil.py @ 2558:fb05ca2c0bdc

allow using complex datatype in macros
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 25 Jul 2007 10:49:49 +0200
parents cc5a81bda460
children b403a24f7c8f
comparison
equal deleted inserted replaced
2557:cc5a81bda460 2558:fb05ca2c0bdc
450 # any value not convertable to int raises ValueError 450 # any value not convertable to int raises ValueError
451 py.test.raises(ValueError, wikiutil.get_float, self.request, u'') 451 py.test.raises(ValueError, wikiutil.get_float, self.request, u'')
452 py.test.raises(ValueError, wikiutil.get_float, self.request, u'wrong') 452 py.test.raises(ValueError, wikiutil.get_float, self.request, u'wrong')
453 py.test.raises(ValueError, wikiutil.get_float, self.request, u'"47.11"') # must not be quoted! 453 py.test.raises(ValueError, wikiutil.get_float, self.request, u'"47.11"') # must not be quoted!
454 454
455 def testGetComplex(self):
456 tests = [
457 # default testing for None value
458 (None, None, None, None),
459 (None, None, -23.42, -23.42),
460 (None, None, 42.23, 42.23),
461
462 # some real values
463 (u'0', None, None, 0),
464 (u'42.23', None, None, 42.23),
465 (u'-23.42', None, None, -23.42),
466 (u'-23.42E3', None, None, -23.42E3),
467 (u'23.42E-3', None, None, 23.42E-3),
468 (u'23.42E-3+3.04j', None, None, 23.42E-3+3.04j),
469 (u'3.04j', None, None, 3.04j),
470 (u'-3.04j', None, None, -3.04j),
471 (u'23.42E-3+3.04i', None, None, 23.42E-3+3.04j),
472 (u'3.04i', None, None, 3.04j),
473 (u'-3.04i', None, None, -3.04j),
474 (u'-3', None, None, -3L),
475 (u'-300000000000000000000', None, None, -300000000000000000000L),
476 ]
477 for arg, name, default, expected in tests:
478 assert wikiutil.get_complex(self.request, arg, name, default) == expected
479
480 def testGetComplexRaising(self):
481 # wrong default type
482 py.test.raises(AssertionError, wikiutil.get_complex, self.request, None, None, u'42')
483
484 # anything except None or unicode raises TypeError
485 py.test.raises(TypeError, wikiutil.get_complex, self.request, True)
486 py.test.raises(TypeError, wikiutil.get_complex, self.request, 42)
487 py.test.raises(TypeError, wikiutil.get_complex, self.request, 42.0)
488 py.test.raises(TypeError, wikiutil.get_complex, self.request, 3j)
489 py.test.raises(TypeError, wikiutil.get_complex, self.request, '')
490 py.test.raises(TypeError, wikiutil.get_complex, self.request, tuple())
491 py.test.raises(TypeError, wikiutil.get_complex, self.request, [])
492 py.test.raises(TypeError, wikiutil.get_complex, self.request, {})
493
494 # any value not convertable to int raises ValueError
495 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'')
496 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'3jj')
497 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'3Ij')
498 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'3i-3i')
499 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'wrong')
500 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'"47.11"') # must not be quoted!
501
455 def testGetUnicode(self): 502 def testGetUnicode(self):
456 tests = [ 503 tests = [
457 # default testing for None value 504 # default testing for None value
458 (None, None, None, None), 505 (None, None, None, None),
459 (None, None, u'', u''), 506 (None, None, u'', u''),
653 assert ief(self.request, has_many_defaults, u'd=4,c=3,b=2,a=1') 700 assert ief(self.request, has_many_defaults, u'd=4,c=3,b=2,a=1')
654 assert ief(self.request, has_many_defaults, u'd=4,c=3,b=2', [1]) 701 assert ief(self.request, has_many_defaults, u'd=4,c=3,b=2', [1])
655 assert ief(self.request, has_many_defaults, u'd=4,c=3', [1, 2]) 702 assert ief(self.request, has_many_defaults, u'd=4,c=3', [1, 2])
656 assert ief(self.request, has_many_defaults, u'd=4', [1, 2, 3]) 703 assert ief(self.request, has_many_defaults, u'd=4', [1, 2, 3])
657 704
705 def testInvokeComplex(self):
706 ief = wikiutil.invoke_extension_function
707
708 def has_complex(a=complex, b=complex):
709 assert a == b
710 return True
711
712 assert ief(self.request, has_complex, u'3-3i, 3-3j')
713 assert ief(self.request, has_complex, u'2i, 2j')
714 assert ief(self.request, has_complex, u'b=2i, a=2j')
715 assert ief(self.request, has_complex, u'2.007, 2.007')
716 assert ief(self.request, has_complex, u'2.007', [2.007])
717 assert ief(self.request, has_complex, u'b=2.007', [2.007])
718
658 719
659 coverage_modules = ['MoinMoin.wikiutil'] 720 coverage_modules = ['MoinMoin.wikiutil']