3 import os, sys, re, glob
5 def read_version_py(infname):
7 verstrline = open(infname, "rt").read()
8 except EnvironmentError:
11 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
12 mo = re.search(VSRE, verstrline, re.M)
16 version = read_version_py(os.path.join('..', 'src', 'allmydata', '_version.py'))
19 raise AssertionError("We don't know which version we're supposed to be testing.")
21 APPNAME='allmydata-tahoe'
24 execfile(os.path.join('..', 'src', 'allmydata', '_auto_deps.py'), adglobals)
25 install_requires = adglobals['install_requires']
26 test_requires = adglobals.get('test_requires', ['mock'])
28 # setuptools/zetuptoolz looks in __main__.__requires__ for a list of
31 __requires__ = [APPNAME + '==' + version] + install_requires + test_requires
33 print "Requirements: %r" % (__requires__,)
35 eggz = glob.glob(os.path.join('..', 'setuptools-*.egg'))
37 egg = os.path.realpath(eggz[0])
38 print "Inserting egg on sys.path: %r" % (egg,)
39 sys.path.insert(0, egg)
44 for i in xrange(1, len(sys.argv)):
45 if not sys.argv[i].startswith('-'):
46 modulename = sys.argv[i]
49 if modulename is None:
50 raise AssertionError("no test module specified")
52 __import__(modulename)
53 srcfile = sys.modules[modulename].__file__
54 srcdir = os.path.dirname(os.path.realpath(srcfile))
56 components = modulename.split('.')
57 leaf = os.path.normcase(components[-1])
58 if os.path.normcase(os.path.basename(srcfile)) in (leaf + '.py', leaf + '.pyc'):
59 # strip the leaf module name
60 components = components[:-1]
63 srcdir = os.path.dirname(srcdir)
65 if os.path.normcase(srcdir).endswith('.egg'):
66 srcdir = os.path.dirname(srcdir)
67 elif os.path.normcase(os.path.basename(srcdir)) == 'site-packages':
68 srcdir = os.path.dirname(srcdir)
69 if re.search(r'python.+\..+', os.path.normcase(os.path.basename(srcdir))):
70 srcdir = os.path.dirname(srcdir)
71 if os.path.normcase(os.path.basename(srcdir)) == 'lib':
72 srcdir = os.path.dirname(srcdir)
74 rootdir = os.path.normcase(os.path.normpath(srcdir))
75 if os.path.basename(rootdir) == 'src':
76 rootdir = os.path.dirname(rootdir)
78 root_from_cwd = os.path.normcase(os.path.normpath(os.getcwd()))
79 if os.path.basename(root_from_cwd) == 'src':
80 root_from_cwd = os.path.dirname(root_from_cwd)
82 same = (root_from_cwd == rootdir)
85 same = os.path.samefile(root_from_cwd, rootdir)
86 except AttributeError, e:
90 msg = ("We seem to be testing the code at %r\n"
91 "(according to the source filename %r),\n"
92 "but expected to be testing the code at %r.\n"
93 % (rootdir, srcfile, root_from_cwd))
95 root_from_cwdu = os.path.normcase(os.path.normpath(os.getcwdu()))
96 if os.path.basename(root_from_cwdu) == u'src':
97 root_from_cwdu = os.path.dirname(root_from_cwdu)
99 if not isinstance(root_from_cwd, unicode) and root_from_cwd.decode(sys.getfilesystemencoding(), 'replace') != root_from_cwdu:
100 msg += ("However, this may be a false alarm because the current directory path\n"
101 "is not representable in the filesystem encoding. This script needs to be\n"
102 "run from the source directory to be tested, at a non-Unicode path.")
104 msg += "This script needs to be run from the source directory to be tested."
106 raise AssertionError(msg)
108 from twisted.scripts.trial import run