annotate tests/objects.py @ 84:daf3a05a05fe

STUB: tests/test.py
author Jeff Hammel <k0scist@gmail.com>
date Fri, 21 Mar 2014 21:29:24 -0700
parents 2449fb4a89c1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
ff272dcd5cd8 we have a passing test
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
ff272dcd5cd8 we have a passing test
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 test objects
ff272dcd5cd8 we have a passing test
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
ff272dcd5cd8 we have a passing test
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
ff272dcd5cd8 we have a passing test
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 def stringsort(*strings):
ff272dcd5cd8 we have a passing test
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 return ''.join(sorted(''.join(strings)))
13
eb81d6943f2e add another dummy object
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
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
eb81d6943f2e add another dummy object
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
18 class Foo(object):
eb81d6943f2e add another dummy object
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
19 def __init__(self, a, b):
eb81d6943f2e add another dummy object
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
20 self.factor = a*100 + b
eb81d6943f2e add another dummy object
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
21 def __call__(self, number):
eb81d6943f2e add another dummy object
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
22 return number * self.factor
36
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
23
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
24 class Wrapper(object):
55
49f88cde6219 make the test wrapper more interesting (and testable)
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
25 def __init__(self, app, **values):
36
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
26 self.app = app
75
20bdb8125817 inline wrapper arguments now seem to work....thats....uncanny
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
27 self.values = dict([(int(j), i) for i, j in values.items()]) # TODO: should be automagically converted ideally via pyloader
36
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
28 def __call__(self, *args, **kwargs):
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
29 retval = self.app(*args, **kwargs)
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
30 values = {1: 'one',
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
31 2: 'two',
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
32 3: 'three'} # etc
55
49f88cde6219 make the test wrapper more interesting (and testable)
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
33 values.update(self.values)
36
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
34 if retval in values:
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
35 return values[retval]
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
36 return retval
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
37
78
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
38 class ArgsPrinter(object):
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
39 def __init__(self, *args, **kwargs):
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
40 self.args = args
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
41 self.kwargs = kwargs
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
42 def __call__(self):
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
43 for arg in self.args:
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
44 print arg
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
45 for kwarg in sorted(self.kwargs):
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
46 print kwarg + ": " + self.kwargs[kwarg]
2449fb4a89c1 rearrange test.ini file to make more sense; write another test class
Jeff Hammel <jhammel@mozilla.com>
parents: 75
diff changeset
47
58
2a1648a53857 pass values via wrap wrapper
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
48 def wrap(app, **values):
2a1648a53857 pass values via wrap wrapper
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
49 return Wrapper(app, **values)
36
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
50
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
51 def fib(n):
362912842985 start stubbing out wrappers....i am somewhat perplexed
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
52 """return the nth fibonacci term"""
57
cb1898f8c72a * illustrate another pattern
Jeff Hammel <jhammel@mozilla.com>
parents: 55
diff changeset
53 n = int(n) # TODO: should be automagically converted ideally via pyloader
37
5268ab85fe1b stub a fibonacci sequence for testing
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
54 sequence = [1,1]
38
f6616a5f468f test fibonacci sequence
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
55 while len(sequence) - 1 < n:
f6616a5f468f test fibonacci sequence
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
56 sequence.append(sequence[len(sequence)-1] + sequence[len(sequence)-2])
37
5268ab85fe1b stub a fibonacci sequence for testing
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
57 return sequence[n]