Mercurial > hg > pyloader
annotate tests/objects.py @ 22:b16d6a204ac1
stub a command line entry point
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 06 Jun 2011 07:41:23 -0700 |
parents | 0bea5297c156 |
children | 362912842985 |
rev | line source |
---|---|
11 | 1 """ |
2 test objects | |
3 """ | |
4 | |
5 def stringsort(*strings): | |
6 return ''.join(sorted(''.join(strings))) | |
13 | 7 |
15
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
8 class StringMunge(object): |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
9 def __init__(self, prefix, delimeter=':', callback=None): |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
10 self.delimeter = delimeter |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
11 self.prefix = prefix |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
12 self.callback = callback |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
13 def __call__(self, string): |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
14 if self.callback: |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
15 string = self.callback(string) |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
16 return self.prefix + self.delimeter + string |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
17 |
13 | 18 class Foo(object): |
19 def __init__(self, a, b): | |
20 self.factor = a*100 + b | |
21 def __call__(self, number): | |
22 return number * self.factor |