Permalink
Browse files

Adds test generator script

  • Loading branch information...
0 parents commit 9b3bf92d5a530bce75646fb98195344586bc73e0 @kumar303 kumar303 committed Mar 1, 2011
Showing with 70 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +63 −0 generate_tests.py
@@ -0,0 +1,7 @@
+*.py[co]
+*.sw[po]
+.tox
+pip-log.txt
+.DS_Store
+*.db
+settings_local.py
@@ -0,0 +1,63 @@
+"""wee! Code generation.
+
+FIXME: use templates, duh.
+"""
+
+import json
+import pprint
+import optparse
+import os
+import re
+import sys
+sys.path.append(os.getcwd())
+
+import manage
+from devhub.tasks import _validator
+
+
+nonchar = re.compile(r'[^a-zA-Z0-9]+')
+
+
+class gen:
+ cnt = 2
+ fn = set()
+
+
+def uniq(n):
+ if n in gen.fn:
+ n = "%s_%s" % (n, gen.cnt)
+ gen.cnt += 1
+ gen.fn.add(n)
+ return n
+
+
+def main():
+ p = optparse.OptionParser(usage='%prog addon_dir')
+ (options, args) = p.parse_args()
+ if len(args) != 1:
+ p.error('incorrect args')
+ addon_dir = args[0]
+ code = []
+ for name in os.listdir(addon_dir):
+ if name.startswith('.'):
+ continue
+ path = os.path.join(addon_dir, name)
+ short = '_'.join([nonchar.sub('_', f).lower() for f in name.split()[0:2]])
+ xpi = [os.path.join(path, x) for x in os.listdir(path)]
+ assert len(xpi) == 1, 'Unexpected: %r' % xpi
+ xpi = xpi[0]
+ res = json.loads(_validator(xpi))
+ code.extend(["",
+ " def test_%s(self):" % uniq(short),
+ ' """%s"""' % name,
+ " d = self.validate(%r)" % os.path.basename(xpi),
+ " eq_(d['errors'], %d)" % res['errors'],
+ " eq_(d['warnings'], %d)" % res['warnings'],
+ " eq_(d['notices'], %d)" % res['notices'],
+ " eq_(sorted([m['message'] for m in res['messages']]),",
+ " %s)" % pprint.pformat(list(sorted([m['message'] for m in res['messages']])), indent=17)])
+ print "\n".join(code)
+
+
+if __name__ == '__main__':
+ main()

0 comments on commit 9b3bf92

Please sign in to comment.