1
#################################### IMPORTS ###################################
3
import tempfile, sys, pygame, time, os
5
################################################################################
7
trunk_dir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
9
def trunk_relative_path(relative):
10
return os.path.normpath(os.path.join(trunk_dir, relative))
12
sys.path.insert(0, trunk_relative_path('.'))
14
import test.unittest as unittest
16
############################### INCOMPLETE TESTS ###############################
17
# TODO: PHASE THIS OUT
18
# Just prefix TODO test names with todo_.
19
# eg def todo_test_sanity__is_overrated(self): self.fail()
20
# Change test loader to load test_ and todo_ TestCase callables as tests
22
fail_incomplete_tests = 0
24
def test_not_implemented():
25
return not fail_incomplete_tests
27
################################## TEMP FILES ##################################
30
return tempfile.mkdtemp()
32
################################################################################
35
return raw_input('%s ' % q.rstrip(' ')).lower().strip() == 'y'
38
return raw_input('%s (and press enter to continue) ' % p.rstrip(' '))
40
#################################### HELPERS ###################################
42
def rgba_between(value, minimum=0, maximum=255):
43
if value < minimum: return minimum
44
elif value > maximum: return maximum
47
def combinations(seqs):
50
Recipe 496807 from ActiveState Python CookBook
52
Non recursive technique for getting all possible combinations of a sequence
59
r = [ i + [y] for y in x for i in r ]
62
def gradient(width, height):
65
Yields a pt and corresponding RGBA tuple, for every (width, height) combo.
66
Useful for generating gradients.
68
Actual gradient may be changed, no tests rely on specific values.
70
Used in transform.rotate lossless tests to generate a fixture.
74
for l in xrange(width):
75
for t in xrange(height):
76
yield (l,t), tuple(map(rgba_between, (l, t, l, l+t)))
78
def unordered_equality(seq1, seq2):
81
Tests to see if the contents of one sequence is contained in the other
82
and that they are of the same length.
86
if len(seq1) != len(seq2):
95
def rect_area_pts(rect):
96
for l in xrange(rect.left, rect.right):
97
for t in xrange(rect.top, rect.bottom):
100
def rect_perimeter_pts(rect):
103
Returns pts ((L, T) tuples) encompassing the perimeter of a rect.
105
The order is clockwise:
108
topright to bottomright
109
bottomright to bottomleft
110
bottomleft to topleft
112
Duplicate pts are not returned
115
clock_wise_from_top_left = (
116
((l, rect.top) for l in xrange(rect.left, rect.right) ),
117
((rect.right -1, t) for t in xrange(rect.top + 1, rect.bottom) ),
118
((l, rect.bottom -1) for l in xrange(rect.right -2, rect.left -1, -1)),
119
((rect.left, t) for t in xrange(rect.bottom -2, rect.top, -1))
122
for line in clock_wise_from_top_left:
123
for pt in line: yield pt
125
def rect_outer_bounds(rect):
128
Returns topleft outerbound if possible and then the other pts, that are
129
"exclusive" bounds of the rect
138
(rect.left is not 0 and [(rect.left-1, rect.top)] or []) +
147
Lightweight test for helpers
151
r = pygame.Rect(0, 0, 10, 10)
153
rect_outer_bounds ( r ) == [(10, 0), # tr
158
assert len(list(rect_area_pts(r))) == 100
161
r = pygame.Rect(0, 0, 3, 3)
162
assert list(rect_perimeter_pts(r)) == [
163
(0, 0), (1, 0), (2, 0), # tl -> tr
164
(2, 1), (2, 2), # tr -> br
165
(1, 2), (0, 2), # br -> bl
171
if __name__ == '__main__':
174
################################################################################