#!/usr/bin/env python from trunc import trunc stars = '********************************************************' orwell = 'When we are omnipotent we shall have no more need of science. \ There will be no distinction between beauty and ugliness. There will \ be no curiosity, no enjoyment of the process of life. All competing \ pleasures will be destroyed. But always - do not forget this, Winston \ - always there will be the intoxication of power, constantly increasing \ and constantly growing subtler. Always, at every moment, there will be \ the thrill of victory, the sensation of trampling on an enemy who is \ helpless. If you want a picture of the future, imagine a boot stamping \ on a human face - for ever."' print 'Trunc tester' print 'This script tests the trunc function' print "Quote from Orwell's 1984" print 'String used (ch.42): %s' % orwell print stars print print 'Test: Truncate a long string using default settings' print 'Truncated output: %s' % trunc(orwell) print 'Length (should be 63): %i' % len(trunc(orwell)) print print 'Test: Truncate using increased upper limit' print 'Truncated output: %s' % trunc(orwell,max_pos=160) print 'Length (should be 121): %i' % len(trunc(orwell,max_pos=160)) print print 'Test: Truncate using increased upper limit without ellipsis' print 'Truncated output: %s' % trunc(orwell,max_pos=160,ellipsis=False) print 'Length (should be 118): %i' % len(trunc(orwell,max_pos=160,ellipsis=False)) print print 'Test: Truncate using decreased upper limit (no period characters)' print 'Truncated output: %s' % trunc(orwell,max_pos=55) print 'Length (should be 55): %i' % len(trunc(orwell,max_pos=55)) print print 'Test: Truncate when string passed is shorter than limit' print 'Using substring as test: %s' % trunc(orwell,max_pos=25,ellipsis=False) print 'Truncated output: %s' % trunc(trunc(orwell,max_pos=25,ellipsis=False)) print 'Length (should be 25): %i' % len(trunc(trunc(orwell,max_pos=25,ellipsis=False))) print print 'Test: Truncate between minimum and maximum values (force size)' print 'Truncated output: %s' % trunc(orwell,min_pos=68,max_pos=74) print 'Length (should be 75): %i' % len(trunc(orwell,min_pos=68,max_pos=74)) print print 'Test: Force error condition (max value less than min value)' try: print 'Truncated output: %s' % trunc(orwell,min_pos=75,max_pos=70) print 'Length: %i' % len(trunc(orwell,min_pos=75,max_pos=70)) except ValueError,e: print 'Pass. Caught exception ValueError: %s' % e print print 'Test: Force specific truncation (max==min)' print 'Truncated output: %s' % trunc(orwell,min_pos=31,max_pos=31) print 'Length (should be 34): %i' % len(trunc(orwell,min_pos=31,max_pos=31)) print