Add taggable-mixin to Melange repository.
[Melange.git] / tests / run.py
blobce081c8bf51cea24a1df8c9e4dda382b9c35f118
1 #!/usr/bin/env python2.5
2 import sys
3 import os
5 HERE = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
6 '..'))
7 appengine_location = os.path.join(HERE, 'thirdparty', 'google_appengine')
8 extra_paths = [HERE,
9 os.path.join(appengine_location, 'lib', 'django'),
10 os.path.join(appengine_location, 'lib', 'webob'),
11 os.path.join(appengine_location, 'lib', 'yaml', 'lib'),
12 os.path.join(appengine_location, 'lib', 'antlr3'),
13 appengine_location,
14 os.path.join(HERE, 'app'),
15 os.path.join(HERE, 'thirdparty', 'coverage'),
18 import nose
19 from nose import plugins
21 class AppEngineDatastoreClearPlugin(plugins.Plugin):
22 """Nose plugin to clear the AppEngine datastore between tests.
23 """
24 name = 'AppEngineDatastoreClearPlugin'
25 enabled = True
26 def options(self, parser, env):
27 return plugins.Plugin.options(self, parser, env)
29 def configure(self, parser, env):
30 plugins.Plugin.configure(self, parser, env)
31 self.enabled = True
33 def afterTest(self, test):
34 from google.appengine.api import apiproxy_stub_map
35 datastore = apiproxy_stub_map.apiproxy.GetStub('datastore')
36 # clear datastore iff one is available
37 if datastore is not None:
38 datastore.Clear()
41 def main():
42 sys.path = extra_paths + sys.path
43 os.environ['SERVER_SOFTWARE'] = 'Development via nose'
44 os.environ['SERVER_NAME'] = 'Foo'
45 os.environ['SERVER_PORT'] = '8080'
46 os.environ['APPLICATION_ID'] = 'test-app-run'
47 os.environ['USER_EMAIL'] = 'test@example.com'
48 os.environ['CURRENT_VERSION_ID'] = 'testing-version'
49 import main as app_main
50 from google.appengine.api import apiproxy_stub_map
51 from google.appengine.api import datastore_file_stub
52 from google.appengine.api import mail_stub
53 from google.appengine.api import user_service_stub
54 from google.appengine.api import urlfetch_stub
55 from google.appengine.api.memcache import memcache_stub
56 apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
57 apiproxy_stub_map.apiproxy.RegisterStub('urlfetch',
58 urlfetch_stub.URLFetchServiceStub())
59 apiproxy_stub_map.apiproxy.RegisterStub('user',
60 user_service_stub.UserServiceStub())
61 apiproxy_stub_map.apiproxy.RegisterStub('datastore',
62 datastore_file_stub.DatastoreFileStub('test-app-run', None, None))
63 apiproxy_stub_map.apiproxy.RegisterStub('memcache',
64 memcache_stub.MemcacheServiceStub())
65 apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub())
66 import django.test.utils
67 django.test.utils.setup_test_environment()
69 from nose.plugins import cover
70 plugin = cover.Coverage()
71 nose.main(plugins=[AppEngineDatastoreClearPlugin(), plugin])
74 if __name__ == '__main__':
75 main()