~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner-wo-source.txt

  • Committer: Thomas Hervé
  • Date: 2009-09-21 06:45:37 UTC
  • mfrom: (7.1.2 newer-zope-testing)
  • Revision ID: thomas@canonical.com-20090921064537-zcfyuv32hxj9eah0
Merge newer-zope-testing [a=sidnei] [f=429702] [r=therve,free.ekayanaka]

Update zope.testing to 3.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Running Without Source Code
2
 
===========================
3
 
 
4
 
The ``--usecompiled`` option allows running tests in a tree without .py
5
 
source code, provided compiled .pyc or .pyo files exist (without
6
 
``--usecompiled``, .py files are necessary).
7
 
 
8
 
We have a very simple directory tree, under ``usecompiled/``, to test
9
 
this.  Because we're going to delete its .py files, we want to work
10
 
in a copy of that:
11
 
 
12
 
    >>> import os.path, shutil, sys, tempfile
13
 
    >>> directory_with_tests = tempfile.mkdtemp()
14
 
 
15
 
    >>> NEWNAME = "unlikely_package_name"
16
 
    >>> src = os.path.join(this_directory, 'testrunner-ex', 'usecompiled')
17
 
    >>> os.path.isdir(src)
18
 
    True
19
 
    >>> dst = os.path.join(directory_with_tests, NEWNAME)
20
 
    >>> os.path.isdir(dst)
21
 
    False
22
 
 
23
 
Have to use our own copying code, to avoid copying read-only SVN files that
24
 
can't be deleted later.
25
 
 
26
 
    >>> n = len(src) + 1
27
 
    >>> for root, dirs, files in os.walk(src):
28
 
    ...     dirs[:] = [d for d in dirs if d == "package"] # prune cruft
29
 
    ...     os.mkdir(os.path.join(dst, root[n:]))
30
 
    ...     for f in files:
31
 
    ...         shutil.copy(os.path.join(root, f),
32
 
    ...                     os.path.join(dst, root[n:], f))
33
 
 
34
 
Now run the tests in the copy:
35
 
 
36
 
    >>> from zope.testing import testrunner
37
 
 
38
 
    >>> mydefaults = [
39
 
    ...     '--path', directory_with_tests,
40
 
    ...     '--tests-pattern', '^compiletest$',
41
 
    ...     '--package', NEWNAME,
42
 
    ...     '-vv',
43
 
    ...     ]
44
 
    >>> sys.argv = ['test']
45
 
    >>> testrunner.run(mydefaults)
46
 
    Running tests at level 1
47
 
    Running unit tests:
48
 
      Running:
49
 
        test1 (unlikely_package_name.compiletest.Test)
50
 
        test2 (unlikely_package_name.compiletest.Test)
51
 
        test1 (unlikely_package_name.package.compiletest.Test)
52
 
        test2 (unlikely_package_name.package.compiletest.Test)
53
 
      Ran 4 tests with 0 failures and 0 errors in N.NNN seconds.
54
 
    False
55
 
 
56
 
If we delete the source files, it's normally a disaster:  the test runner
57
 
doesn't believe any test files, or even packages, exist.  Note that we pass
58
 
``--keepbytecode`` this time, because otherwise the test runner would
59
 
delete the compiled Python files too:
60
 
 
61
 
    >>> for root, dirs, files in os.walk(dst):
62
 
    ...    for f in files:
63
 
    ...        if f.endswith(".py"):
64
 
    ...            os.remove(os.path.join(root, f))
65
 
    >>> testrunner.run(mydefaults, ["test", "--keepbytecode"])
66
 
    Running tests at level 1
67
 
    Total: 0 tests, 0 failures, 0 errors in N.NNN seconds.
68
 
    False
69
 
 
70
 
Finally, passing ``--usecompiled`` asks the test runner to treat .pyc
71
 
and .pyo files as adequate replacements for .py files.  Note that the
72
 
output is the same as when running with .py source above.  The absence
73
 
of "removing stale bytecode ..." messages shows that ``--usecompiled``
74
 
also implies ``--keepbytecode``:
75
 
 
76
 
    >>> testrunner.run(mydefaults, ["test", "--usecompiled"])
77
 
    Running tests at level 1
78
 
    Running unit tests:
79
 
      Running:
80
 
        test1 (unlikely_package_name.compiletest.Test)
81
 
        test2 (unlikely_package_name.compiletest.Test)
82
 
        test1 (unlikely_package_name.package.compiletest.Test)
83
 
        test2 (unlikely_package_name.package.compiletest.Test)
84
 
      Ran 4 tests with 0 failures and 0 errors in N.NNN seconds.
85
 
    False
86
 
 
87
 
Remove the temporary directory:
88
 
 
89
 
    >>> shutil.rmtree(directory_with_tests)