source: trunk/misc/build_helpers/run_trial.py

Last change on this file was 05bdeb3, checked in by zooko <zooko@…>, 14 years ago

setup: copy misc/build_helpers/run_trial.py from tahoe-lafs (ref: #52)

Ignore-this: 5e3ee2511f54fb857bb87dd5d9ad7c94

darcs-hash:c744372840befe040838072c53fc52521cb1f53d

  • Property mode set to 100755
File size: 1.9 KB
Line 
1#!/usr/bin/env python
2
3import os, sys, re
4
5modulename = None
6for i in xrange(1, len(sys.argv)):
7    if not sys.argv[i].startswith('-'):
8        modulename = sys.argv[i]
9        break
10
11if modulename is None:
12    raise AssertionError("no test module specified")
13
14__import__(modulename)
15srcfile = sys.modules[modulename].__file__
16srcdir = os.path.dirname(os.path.realpath(srcfile))
17for i in modulename.split('.'):
18    srcdir = os.path.dirname(srcdir)
19
20if os.path.normcase(srcdir).endswith('.egg'):
21    srcdir = os.path.dirname(srcdir)
22elif 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)
28
29srcdir = os.path.normcase(os.path.normpath(srcdir))
30cwd = os.path.normcase(os.path.normpath(os.getcwd()))
31
32same = (srcdir == cwd)
33if not same:
34    try:
35        same = os.path.samefile(srcdir, cwd)
36    except AttributeError, e:
37        e  # hush pyflakes
38
39if not same:
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.")
49    else:
50        msg += "This script needs to be run from the source directory to be tested."
51
52    raise AssertionError(msg)
53
54from twisted.scripts.trial import run
55run()
Note: See TracBrowser for help on using the repository browser.