3 import os, sys, re, glob
6 def read_version_py(infname):
8 verstrline = open(infname, "rt").read()
9 except EnvironmentError:
12 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
13 mo = re.search(VSRE, verstrline, re.M)
17 version = read_version_py(os.path.join('..', 'src', 'allmydata', '_version.py'))
20 raise AssertionError("We don't know which version we're supposed to be testing.")
22 APPNAME='allmydata-tahoe'
25 execfile(os.path.join('..', 'src', 'allmydata', '_auto_deps.py'), adglobals)
26 install_requires = adglobals['install_requires']
27 test_requires = adglobals.get('test_requires', ['mock'])
29 # setuptools/zetuptoolz looks in __main__.__requires__ for a list of
32 __requires__ = [APPNAME + '==' + version] + install_requires + test_requires
34 print "Requirements: %r" % (__requires__,)
36 eggz = glob.glob(os.path.join('..', 'setuptools-*.egg'))
38 egg = os.path.realpath(eggz[0])
39 print "Inserting egg on sys.path: %r" % (egg,)
40 sys.path.insert(0, egg)
43 pkg_resources # hush pyflakes
46 for i in xrange(1, len(sys.argv)):
47 if not sys.argv[i].startswith('-'):
48 modulename = sys.argv[i]
51 if modulename is None:
52 raise AssertionError("no test module specified")
54 __import__(modulename)
55 srcfile = sys.modules[modulename].__file__
56 srcdir = os.path.dirname(os.path.realpath(srcfile))
58 components = modulename.split('.')
59 leaf = os.path.normcase(components[-1])
60 if os.path.normcase(os.path.basename(srcfile)) in (leaf + '.py', leaf + '.pyc'):
61 # strip the leaf module name
62 components = components[:-1]
65 srcdir = os.path.dirname(srcdir)
67 if os.path.normcase(srcdir).endswith('.egg'):
68 srcdir = os.path.dirname(srcdir)
69 elif os.path.normcase(os.path.basename(srcdir)) == 'site-packages':
70 srcdir = os.path.dirname(srcdir)
71 if re.search(r'python.+\..+', os.path.normcase(os.path.basename(srcdir))):
72 srcdir = os.path.dirname(srcdir)
73 if os.path.normcase(os.path.basename(srcdir)) == 'lib':
74 srcdir = os.path.dirname(srcdir)
76 rootdir = os.path.normcase(os.path.normpath(srcdir))
77 if os.path.basename(rootdir) == 'src':
78 rootdir = os.path.dirname(rootdir)
80 root_from_cwd = os.path.normcase(os.path.normpath(os.getcwd()))
81 if os.path.basename(root_from_cwd) == 'src':
82 root_from_cwd = os.path.dirname(root_from_cwd)
84 same = (root_from_cwd == rootdir)
87 same = os.path.samefile(root_from_cwd, rootdir)
88 except AttributeError, e:
92 msg = ("We seem to be testing the code at %r\n"
93 "(according to the source filename %r),\n"
94 "but expected to be testing the code at %r.\n"
95 % (rootdir, srcfile, root_from_cwd))
97 root_from_cwdu = os.path.normcase(os.path.normpath(os.getcwdu()))
98 if os.path.basename(root_from_cwdu) == u'src':
99 root_from_cwdu = os.path.dirname(root_from_cwdu)
101 if not isinstance(root_from_cwd, unicode) and root_from_cwd.decode(sys.getfilesystemencoding(), 'replace') != root_from_cwdu:
102 msg += ("However, this may be a false alarm because the current directory path\n"
103 "is not representable in the filesystem encoding. This script needs to be\n"
104 "run from the source directory to be tested, at a non-Unicode path.")
106 msg += "This script needs to be run from the source directory to be tested."
108 raise AssertionError(msg)
110 from twisted.scripts.trial import run