~ubuntu-branches/debian/squeeze/nose/squeeze

« back to all changes in this revision

Viewing changes to unit_tests/test_config_defaults.rst

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Marek, Torsten Marek, Gustavo Noronha Silva
  • Date: 2008-06-12 13:39:43 UTC
  • mfrom: (1.2.1 upstream) (2.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080612133943-2q7syp67fwl4on13
Tags: 0.10.3-1

[Torsten Marek]
* New upstream release (Closes: #461994)
* debian/control
  - bump standards version to 3.8.0, no changes necessary
  - add suggestions for python-coverage (Closes: #457053)
  - change dependency on python-setuptools into 
    python-pkg-resources (Closes: #468719)
  - added myself to uploaders

[Gustavo Noronha Silva]
* debian/control:
  - remove -1 from build-dep on setuptools

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
    >>> from optparse import OptionParser
 
2
    >>> import os
 
3
    >>> from cStringIO import StringIO
 
4
 
 
5
    >>> import nose.config
 
6
 
 
7
All commandline options to fall back to values configured in
 
8
configuration files.  The configuration lives in a single section
 
9
("nosetests") in each configuration file.
 
10
 
 
11
    >>> support = os.path.join(os.path.dirname(__file__), "support",
 
12
    ...                        "config_defaults")
 
13
 
 
14
    >>> def error(msg):
 
15
    ...     print "error: %s" % msg
 
16
 
 
17
    >>> def get_parser():
 
18
    ...     parser = OptionParser()
 
19
    ...     parser.add_option(
 
20
    ...         "-v", "--verbose",
 
21
    ...         action="count", dest="verbosity",
 
22
    ...         default=1)
 
23
    ...     parser.add_option(
 
24
    ...         "--verbosity", action="store", dest="verbosity",
 
25
    ...         type="int")
 
26
    ...     return nose.config.ConfiguredDefaultsOptionParser(parser,
 
27
    ...                                                       "nosetests",
 
28
    ...                                                       error)
 
29
 
 
30
    >>> def parse(args, config_files):
 
31
    ...     argv = ["nosetests"] + list(args)
 
32
    ...     return get_parser().parseArgsAndConfigFiles(argv, config_files)
 
33
 
 
34
 
 
35
Options on the command line combine with the defaults from the config
 
36
files and the options' own defaults (here, -v adds 1 to verbosity of 3
 
37
from a.cfg).  Config file defaults take precedence over options'
 
38
defaults.
 
39
 
 
40
    >>> options, args = parse([], [])
 
41
    >>> options.verbosity
 
42
    1
 
43
    >>> options, args = parse([], os.path.join(support, "a.cfg"))
 
44
    >>> options.verbosity
 
45
    3
 
46
    >>> options, args = parse(["-v"], os.path.join(support, "a.cfg"))
 
47
    >>> options.verbosity
 
48
    4
 
49
 
 
50
Command line arguments take precedence
 
51
 
 
52
    >>> options, args = parse(["--verbosity=7"], os.path.join(support, "a.cfg"))
 
53
    >>> options.verbosity
 
54
    7
 
55
 
 
56
Where options appear in several config files, the last config file wins
 
57
 
 
58
    >>> files = [os.path.join(support, "b.cfg"), os.path.join(support, "a.cfg")]
 
59
    >>> options, args = parse([], files)
 
60
    >>> options.verbosity
 
61
    3
 
62
 
 
63
 
 
64
Invalid values should cause an error specifically about configuration
 
65
files (not about a commandline option)
 
66
 
 
67
    >>> options, arguments = parse([], StringIO("""\
 
68
    ... [nosetests]
 
69
    ... verbosity = spam
 
70
    ... """))
 
71
    error: Error reading config file '<???>': option 'verbosity': invalid integer value: 'spam'
 
72
 
 
73
Unrecognised option in nosetests config section
 
74
 
 
75
    >>> options, args = parse([], StringIO("[nosetests]\nspam=eggs\n"))
 
76
    error: Error reading config file '<???>': no such option 'spam'
 
77
 
 
78
If there were multiple config files, the error message tells us which
 
79
file contains the bad option name or value
 
80
 
 
81
    >>> options, args = parse([], [os.path.join(support, "a.cfg"),
 
82
    ...                            os.path.join(support, "invalid_value.cfg"),
 
83
    ...                            os.path.join(support, "b.cfg")])
 
84
    ... # doctest: +ELLIPSIS
 
85
    error: Error reading config file '.../invalid_value.cfg': option 'verbosity': invalid integer value: 'spam'
 
86
 
 
87
 
 
88
Invalid config files
 
89
 
 
90
(file-like object)
 
91
 
 
92
    >>> options, args = parse([], StringIO("spam"))
 
93
    error: Error reading config file '<???>': File contains no section headers.
 
94
    file: <???>, line: 1
 
95
    'spam'
 
96
 
 
97
(filename)
 
98
 
 
99
    >>> options, args = parse([], os.path.join(support, "invalid.cfg"))
 
100
    ... # doctest: +ELLIPSIS
 
101
    error: Error reading config file '.../invalid.cfg': File contains no section headers.
 
102
    file: .../invalid.cfg, line: 1
 
103
    'spam\n'
 
104
 
 
105
(filenames, length == 1)
 
106
 
 
107
    >>> options, args = parse([], [os.path.join(support, "invalid.cfg")])
 
108
    ... # doctest: +ELLIPSIS
 
109
    error: Error reading config file '.../invalid.cfg': File contains no section headers.
 
110
    file: .../invalid.cfg, line: 1
 
111
    'spam\n'
 
112
 
 
113
(filenames, length > 1)
 
114
 
 
115
If there were multiple config files, the error message tells us which
 
116
file is bad
 
117
 
 
118
    >>> options, args = parse([], [os.path.join(support, "a.cfg"),
 
119
    ...                            os.path.join(support, "invalid.cfg"),
 
120
    ...                            os.path.join(support, "b.cfg")])
 
121
    ... # doctest: +ELLIPSIS
 
122
    error: Error reading config file '.../invalid.cfg': File contains no section headers.
 
123
    file: .../invalid.cfg, line: 1
 
124
    'spam\n'
 
125
 
 
126
 
 
127
Missing config files don't deserve an error or warning
 
128
 
 
129
(filename)
 
130
 
 
131
    >>> options, args = parse([], os.path.join(support, "nonexistent.cfg"))
 
132
    >>> print options.__dict__
 
133
    {'verbosity': 1}
 
134
 
 
135
(filenames)
 
136
 
 
137
    >>> options, args = parse([], [os.path.join(support, "nonexistent.cfg")])
 
138
    >>> print options.__dict__
 
139
    {'verbosity': 1}
 
140
 
 
141
 
 
142
The same goes for missing config file section ("nosetests")
 
143
 
 
144
    >>> options, args = parse([], StringIO("[spam]\nfoo=bar\n"))
 
145
    >>> print options.__dict__
 
146
    {'verbosity': 1}