3 import os, sys, re, glob
5 if sys.platform == "win32":
6 # Buildbot depends on pywin32, but we don't want it to be available to the code under test.
7 def not_pywin32(entry):
8 dirs = os.path.normcase(entry).replace('/', '\\').split('\\')
9 return "win32" not in dirs and "pythonwin" not in dirs
12 sys.path = filter(not_pywin32, sys.path)
20 raise AssertionError("We were unable to expunge pywin32 from the sys.path.")
23 def read_version_py(infname):
25 verstrline = open(infname, "rt").read()
26 except EnvironmentError:
29 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
30 mo = re.search(VSRE, verstrline, re.M)
34 version = read_version_py(os.path.join('..', 'src', 'allmydata', '_version.py'))
37 raise AssertionError("We don't know which version we're supposed to be testing.")
39 APPNAME='allmydata-tahoe'
42 execfile(os.path.join('..', 'src', 'allmydata', '_auto_deps.py'), adglobals)
43 install_requires = adglobals['install_requires']
44 test_requires = adglobals.get('test_requires', ['mock'])
46 # setuptools/zetuptoolz looks in __main__.__requires__ for a list of
49 __requires__ = [APPNAME + '==' + version] + install_requires + test_requires
51 print "Requirements: %r" % (__requires__,)
53 eggz = glob.glob(os.path.join('..', 'setuptools-*.egg'))
55 egg = os.path.realpath(eggz[0])
56 print "Inserting egg on sys.path: %r" % (egg,)
57 sys.path.insert(0, egg)
60 pkg_resources # hush pyflakes
63 for i in xrange(1, len(sys.argv)):
64 if not sys.argv[i].startswith('-'):
65 modulename = sys.argv[i]
68 if modulename is None:
69 raise AssertionError("no test module specified")
71 __import__(modulename)
72 srcfile = sys.modules[modulename].__file__
73 srcdir = os.path.dirname(os.path.realpath(srcfile))
75 components = modulename.split('.')
76 leaf = os.path.normcase(components[-1])
77 if os.path.normcase(os.path.basename(srcfile)) in (leaf + '.py', leaf + '.pyc'):
78 # strip the leaf module name
79 components = components[:-1]
82 srcdir = os.path.dirname(srcdir)
84 if os.path.normcase(srcdir).endswith('.egg'):
85 srcdir = os.path.dirname(srcdir)
86 elif os.path.normcase(os.path.basename(srcdir)) == 'site-packages':
87 srcdir = os.path.dirname(srcdir)
88 if re.search(r'python.+\..+', os.path.normcase(os.path.basename(srcdir))):
89 srcdir = os.path.dirname(srcdir)
90 if os.path.normcase(os.path.basename(srcdir)) == 'lib':
91 srcdir = os.path.dirname(srcdir)
93 rootdir = os.path.normcase(os.path.normpath(srcdir))
94 if os.path.basename(rootdir) == 'src':
95 rootdir = os.path.dirname(rootdir)
97 root_from_cwd = os.path.normcase(os.path.normpath(os.getcwd()))
98 if os.path.basename(root_from_cwd) == 'src':
99 root_from_cwd = os.path.dirname(root_from_cwd)
101 same = (root_from_cwd == rootdir)
104 same = os.path.samefile(root_from_cwd, rootdir)
105 except AttributeError, e:
109 msg = ("We seem to be testing the code at %r\n"
110 "(according to the source filename %r),\n"
111 "but expected to be testing the code at %r.\n"
112 % (rootdir, srcfile, root_from_cwd))
114 root_from_cwdu = os.path.normcase(os.path.normpath(os.getcwdu()))
115 if os.path.basename(root_from_cwdu) == u'src':
116 root_from_cwdu = os.path.dirname(root_from_cwdu)
118 if not isinstance(root_from_cwd, unicode) and root_from_cwd.decode(sys.getfilesystemencoding(), 'replace') != root_from_cwdu:
119 msg += ("However, this may be a false alarm because the current directory path\n"
120 "is not representable in the filesystem encoding. This script needs to be\n"
121 "run from the source directory to be tested, at a non-Unicode path.")
123 msg += "This script needs to be run from the source directory to be tested."
125 raise AssertionError(msg)
127 from twisted.scripts.trial import run