1 """helpers for tests"""
2
3 __all__=['assert_sorted_equals', 'assert_sorted_not_equals', 'loadFixtures']
4
5 from nose.tools import *
6 import os.path
7 import tarfile
8 import simplejson
9
11 """assert that two iterables are equal when sorted"""
12 x=sorted(x)
13 y=sorted(y)
14 assert x == y, msg or "%r != %r" %(x, y)
15 return True
16
18 """assert that two iterables are unequal when sorted"""
19 x=sorted(x)
20 y=sorted(y)
21 assert x != y, msg or "%r == %r" %(x, y)
22 return True
23
24
33
34
36 """Generate filenames and json data from directory or tarball
37
38 @arg name: the name of the thing to load from. If a directory, use that,
39 otherwise use name.tar.gz
40 @type arg: string
41 """
42 if os.path.isdir(name): return walk(name)
43 else: return extract(name)
44
46 "Generate filenames and json data from directory."
47 for root, dirs, files in os.walk(name):
48 for filename in files:
49 rootname, ext = os.path.splitext(filename)
50 if ext == '.json':
51 yield rootname, simplejson.load(open(os.path.join(root, filename)))
52
54 "Generate filenames and json data from tarfile."
55 tf = tarfile.open(name + '.tar.gz')
56 for member in tf:
57 rootname, ext = os.path.splitext(os.path.basename(member.name))
58 if member.isfile() and not rootname.startswith('.') and ext == '.json':
59 yield rootname, simplejson.load(tf.extractfile(member))
60