6 for i in xrange(1, len(sys.argv)):
7 if not sys.argv[i].startswith('-'):
8 modulename = sys.argv[i]
11 if modulename is None:
12 raise AssertionError("no test module specified")
14 __import__(modulename)
15 srcfile = sys.modules[modulename].__file__
16 srcdir = os.path.dirname(os.path.realpath(srcfile))
17 for i in modulename.split('.'):
18 srcdir = os.path.dirname(srcdir)
20 if os.path.normcase(srcdir).endswith('.egg'):
21 srcdir = os.path.dirname(srcdir)
22 elif os.path.normcase(os.path.basename(srcdir)) == 'site-packages':
23 srcdir = os.path.dirname(srcdir)
24 if re.search(r'python.+\..+', os.path.normcase(os.path.basename(srcdir))):
25 srcdir = os.path.dirname(srcdir)
26 if os.path.normcase(os.path.basename(srcdir)) == 'lib':
27 srcdir = os.path.dirname(srcdir)
29 srcdir = os.path.normcase(os.path.normpath(srcdir))
30 cwd = os.path.normcase(os.path.normpath(os.getcwd()))
32 same = (srcdir == cwd)
35 same = os.path.samefile(srcdir, cwd)
36 except AttributeError, e:
40 msg = ("We seem to be testing the code at %r\n"
41 "(according to the source filename %r),\n"
42 "but expected to be testing the code at %r.\n"
43 % (srcdir, srcfile, cwd))
44 if (not isinstance(cwd, unicode) and
45 cwd.decode(sys.getfilesystemencoding(), 'replace') != os.path.normcase(os.path.normpath(os.getcwdu()))):
46 msg += ("However, this may be a false alarm because the current directory path\n"
47 "is not representable in the filesystem encoding. This script needs to be\n"
48 "run from the source directory to be tested, at a non-Unicode path.")
50 msg += "This script needs to be run from the source directory to be tested."
52 raise AssertionError(msg)
54 from twisted.scripts.trial import run