call site 0 for compat.doctest.Example.__init__
doc/test_conftest.py - line 87
79
80
81
82
83
84
85
86
87
88
89
90
91
92
   def test_doctest_indentation():
       # XXX get rid of the next line: 
       py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
   
       txt = tmpdir.join('foo.txt')
       txt.write('..\n  >>> print "foo\\n  bar"\n  foo\n    bar\n')
       config = py.test.config._reparse([txt])
       session = config.initsession()
->     session.main()
       l = session.getitemoutcomepairs(Failed)
       assert len(l) == 0
       l = session.getitemoutcomepairs(Passed)
       l2 = session.getitemoutcomepairs(Skipped)
       assert len(l+l2) == 2
test/session.py - line 63
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
   def main(self): 
       """ main loop for running tests. """
       colitems = self.config.getcolitems()
       try:
           self.header(colitems) 
           try:
               try:
                   for colitem in colitems: 
->                     self.runtraced(colitem)
               except KeyboardInterrupt: 
                   raise 
           finally: 
               self.footer(colitems) 
       except Exit, ex:
           pass
       return self.getitemoutcomepairs(Failed)
test/session.py - line 84
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
   def runtraced(self, colitem):
       if self.shouldclose(): 
           raise Exit, "received external close signal" 
   
       outcome = None 
       colitem.startcapture() 
       try: 
           self.start(colitem)
           try: 
               try:
                   if colitem._stickyfailure: 
                       raise colitem._stickyfailure 
->                 outcome = self.run(colitem) 
               except (KeyboardInterrupt, Exit): 
                   raise 
               except Outcome, outcome: 
                   if outcome.excinfo is None: 
                       outcome.excinfo = py.code.ExceptionInfo() 
               except: 
                   excinfo = py.code.ExceptionInfo() 
                   outcome = Failed(excinfo=excinfo) 
               assert (outcome is None or 
                       isinstance(outcome, (list, Outcome)))
           finally: 
               self.finish(colitem, outcome) 
           if isinstance(outcome, Failed) and self.config.option.exitfirst:
               py.test.exit("exit on first problem configured.", item=colitem)
       finally: 
           colitem.finishcapture()
test/session.py - line 119
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
   def run(self, colitem): 
       if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): 
           return 
       if isinstance(colitem, py.test.collect.Item): 
           colitem._skipbykeyword(self.config.option.keyword)
       res = colitem.run() 
       if res is None: 
           return Passed() 
       elif not isinstance(res, (list, tuple)): 
           raise TypeError("%r.run() returned neither "
                           "list, tuple nor None: %r" % (colitem, res))
       else: 
           finish = self.startiteration(colitem, res)
           try: 
               for name in res: 
                   obj = colitem.join(name) 
                   assert obj is not None 
->                 self.runtraced(obj) 
           finally: 
               if finish: 
                   finish() 
       return res 
test/session.py - line 84
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
   def runtraced(self, colitem):
       if self.shouldclose(): 
           raise Exit, "received external close signal" 
   
       outcome = None 
       colitem.startcapture() 
       try: 
           self.start(colitem)
           try: 
               try:
                   if colitem._stickyfailure: 
                       raise colitem._stickyfailure 
->                 outcome = self.run(colitem) 
               except (KeyboardInterrupt, Exit): 
                   raise 
               except Outcome, outcome: 
                   if outcome.excinfo is None: 
                       outcome.excinfo = py.code.ExceptionInfo() 
               except: 
                   excinfo = py.code.ExceptionInfo() 
                   outcome = Failed(excinfo=excinfo) 
               assert (outcome is None or 
                       isinstance(outcome, (list, Outcome)))
           finally: 
               self.finish(colitem, outcome) 
           if isinstance(outcome, Failed) and self.config.option.exitfirst:
               py.test.exit("exit on first problem configured.", item=colitem)
       finally: 
           colitem.finishcapture()
test/session.py - line 107
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
   def run(self, colitem): 
       if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): 
           return 
       if isinstance(colitem, py.test.collect.Item): 
           colitem._skipbykeyword(self.config.option.keyword)
->     res = colitem.run() 
       if res is None: 
           return Passed() 
       elif not isinstance(res, (list, tuple)): 
           raise TypeError("%r.run() returned neither "
                           "list, tuple nor None: %r" % (colitem, res))
       else: 
           finish = self.startiteration(colitem, res)
           try: 
               for name in res: 
                   obj = colitem.join(name) 
                   assert obj is not None 
                   self.runtraced(obj) 
           finally: 
               if finish: 
                   finish() 
       return res 
/tmp/pytest-2/docdoctest/conftest.py - line 131
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
   def run(self): 
       # XXX quite nasty... but it works (fixes win32 issues)
       s = self._normalize_linesep()
       l = []
       prefix = '.. >>> '
       mod = py.std.types.ModuleType(self.fspath.purebasename) 
       for line in deindent(s).split('\n'):
           stripped = line.strip()
           if stripped.startswith(prefix):
               exec py.code.Source(stripped[len(prefix):]).compile() in \
                    mod.__dict__
               line = ""
           else:
               l.append(line)
       docstring = "\n".join(l)
->     self.execute(mod, docstring)
/tmp/pytest-2/docdoctest/conftest.py - line 135
133
134
135
136
137
138
   def execute(self, mod, docstring): 
       mod.__doc__ = docstring 
->     failed, tot = py.compat.doctest.testmod(mod, verbose=1)
       if failed: 
           py.test.fail("doctest %s: %s failed out of %s" %(
                        self.fspath, failed, tot))
compat/doctest.py - line 1846
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
   def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None,
               report=True, optionflags=0, extraglobs=None,
               raise_on_error=False, exclude_empty=False):
       """m=None, name=None, globs=None, verbose=None, isprivate=None,
          report=True, optionflags=0, extraglobs=None, raise_on_error=False,
          exclude_empty=False
   
       Test examples in docstrings in functions and classes reachable
       from module m (or the current module if m is not supplied), starting
       with m.__doc__.  Unless isprivate is specified, private names
       are not skipped.
   
       Also test examples reachable from dict m.__test__ if it exists and is
       not None.  m.__test__ maps names to functions, classes and strings;
       function and class docstrings are tested even if the name is private;
       strings are tested directly, as if they were docstrings.
   
       Return (#failures, #tests).
   
       See doctest.__doc__ for an overview.
   
       Optional keyword arg "name" gives the name of the module; by default
       use m.__name__.
   
       Optional keyword arg "globs" gives a dict to be used as the globals
       when executing examples; by default, use m.__dict__.  A copy of this
       dict is actually used for each docstring, so that each docstring's
       examples start with a clean slate.
   
       Optional keyword arg "extraglobs" gives a dictionary that should be
       merged into the globals that are used to execute examples.  By
       default, no extra globals are used.  This is new in 2.4.
   
       Optional keyword arg "verbose" prints lots of stuff if true, prints
       only failures if false; by default, it's true iff "-v" is in sys.argv.
   
       Optional keyword arg "report" prints a summary at the end when true,
       else prints nothing at the end.  In verbose mode, the summary is
       detailed, else very brief (in fact, empty if all tests passed).
   
       Optional keyword arg "optionflags" or's together module constants,
       and defaults to 0.  This is new in 2.3.  Possible values (see the
       docs for details):
   
           DONT_ACCEPT_TRUE_FOR_1
           DONT_ACCEPT_BLANKLINE
           NORMALIZE_WHITESPACE
           ELLIPSIS
           IGNORE_EXCEPTION_DETAIL
           REPORT_UDIFF
           REPORT_CDIFF
           REPORT_NDIFF
           REPORT_ONLY_FIRST_FAILURE
   
       Optional keyword arg "raise_on_error" raises an exception on the
       first unexpected exception or failure. This allows failures to be
       post-mortem debugged.
   
       Deprecated in Python 2.4:
       Optional keyword arg "isprivate" specifies a function used to
       determine whether a name is private.  The default function is
       treat all functions as public.  Optionally, "isprivate" can be
       set to doctest.is_private to skip over functions marked as private
       using the underscore naming convention; see its docs for details.
   
       Advanced tomfoolery:  testmod runs methods of a local instance of
       class doctest.Tester, then merges the results into (or creates)
       global Tester instance doctest.master.  Methods of doctest.master
       can be called directly too, if you want to do something unusual.
       Passing report=0 to testmod is especially useful then, to delay
       displaying a summary.  Invoke doctest.master.summarize(verbose)
       when you're done fiddling.
       """
       global master
   
       if isprivate is not None:
           warnings.warn("the isprivate argument is deprecated; "
                         "examine DocTestFinder.find() lists instead",
                         DeprecationWarning)
   
       # If no module was given, then use __main__.
       if m is None:
           # DWA - m will still be None if this wasn't invoked from the command
           # line, in which case the following TypeError is about as good an error
           # as we should expect
           m = sys.modules.get('__main__')
   
       # Check that we were actually given a module.
       if not inspect.ismodule(m):
           raise TypeError("testmod: module required; %r" % (m,))
   
       # If no name was given, then use the module's name.
       if name is None:
           name = m.__name__
   
       # Find, parse, and run all tests in the given module.
       finder = DocTestFinder(_namefilter=isprivate, exclude_empty=exclude_empty)
   
       if raise_on_error:
           runner = DebugRunner(verbose=verbose, optionflags=optionflags)
       else:
           runner = DocTestRunner(verbose=verbose, optionflags=optionflags)
   
->     for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
           runner.run(test)
   
       if report:
           runner.summarize()
   
       if master is None:
           master = runner
       else:
           master.merge(runner)
   
       return runner.failures, runner.tries
compat/doctest.py - line 850
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
   def find(self, obj, name=None, module=None, globs=None,
            extraglobs=None):
       """
           Return a list of the DocTests that are defined by the given
           object's docstring, or by any of its contained objects'
           docstrings.
   
           The optional parameter `module` is the module that contains
           the given object.  If the module is not specified or is None, then
           the test finder will attempt to automatically determine the
           correct module.  The object's module is used:
   
               - As a default namespace, if `globs` is not specified.
               - To prevent the DocTestFinder from extracting DocTests
                 from objects that are imported from other modules.
               - To find the name of the file containing the object.
               - To help find the line number of the object within its
                 file.
   
           Contained objects whose module does not match `module` are ignored.
   
           If `module` is False, no attempt to find the module will be made.
           This is obscure, of use mostly in tests:  if `module` is False, or
           is None but cannot be found automatically, then all objects are
           considered to belong to the (non-existent) module, so all contained
           objects will (recursively) be searched for doctests.
   
           The globals for each DocTest is formed by combining `globs`
           and `extraglobs` (bindings in `extraglobs` override bindings
           in `globs`).  A new copy of the globals dictionary is created
           for each DocTest.  If `globs` is not specified, then it
           defaults to the module's `__dict__`, if specified, or {}
           otherwise.  If `extraglobs` is not specified, then it defaults
           to {}.
   
           """
       # If name was not specified, then extract it from the object.
       if name is None:
           name = getattr(obj, '__name__', None)
           if name is None:
               raise ValueError("DocTestFinder.find: name must be given "
                       "when obj.__name__ doesn't exist: %r" %
                                (type(obj),))
   
       # Find the module that contains the given object (if obj is
       # a module, then module=obj.).  Note: this may fail, in which
       # case module will be None.
       if module is False:
           module = None
       elif module is None:
           module = inspect.getmodule(obj)
   
       # Read the module's source code.  This is used by
       # DocTestFinder._find_lineno to find the line number for a
       # given object's docstring.
       try:
           file = inspect.getsourcefile(obj) or inspect.getfile(obj)
           source_lines = linecache.getlines(file)
           if not source_lines:
               source_lines = None
       except TypeError:
           source_lines = None
   
       # Initialize globals, and merge in extraglobs.
       if globs is None:
           if module is None:
               globs = {}
           else:
               globs = module.__dict__.copy()
       else:
           globs = globs.copy()
       if extraglobs is not None:
           globs.update(extraglobs)
   
       # Recursively expore `obj`, extracting DocTests.
       tests = []
->     self._find(tests, obj, name, module, source_lines, globs, {})
       # Sort the tests by alpha order of names, for consistency in
       # verbose-mode output.  This was a feature of doctest in Pythons
       # <= 2.3 that got lost by accident in 2.4.  It was repaired in
       # 2.4.4 and 2.5.
       tests.sort()
       return tests
compat/doctest.py - line 899
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
   def _find(self, tests, obj, name, module, source_lines, globs, seen):
       """
           Find tests for the given object and any contained objects, and
           add them to `tests`.
           """
       if self._verbose:
           print 'Finding tests in %s' % name
   
       # If we've already processed this object, then ignore it.
       if id(obj) in seen:
           return
       seen[id(obj)] = 1
   
       # Find a test for this object, and add it to the list of tests.
->     test = self._get_test(obj, name, module, globs, source_lines)
       if test is not None:
           tests.append(test)
   
       # Look for tests in a module's contained objects.
       if inspect.ismodule(obj) and self._recurse:
           for valname, val in obj.__dict__.items():
               # Check if this contained object should be ignored.
               if self._filter(val, name, valname):
                   continue
               valname = '%s.%s' % (name, valname)
               # Recurse to functions & classes.
               if ((inspect.isfunction(val) or inspect.isclass(val)) and
                   self._from_module(module, val)):
                   self._find(tests, val, valname, module, source_lines,
                              globs, seen)
   
       # Look for tests in a module's __test__ dictionary.
       if inspect.ismodule(obj) and self._recurse:
           for valname, val in getattr(obj, '__test__', {}).items():
               if not isinstance(valname, basestring):
                   raise ValueError("DocTestFinder.find: __test__ keys "
                                    "must be strings: %r" %
                                    (type(valname),))
               if not (inspect.isfunction(val) or inspect.isclass(val) or
                       inspect.ismethod(val) or inspect.ismodule(val) or
                       isinstance(val, basestring)):
                   raise ValueError("DocTestFinder.find: __test__ values "
                                    "must be strings, functions, methods, "
                                    "classes, or modules: %r" %
                                    (type(val),))
               valname = '%s.__test__.%s' % (name, valname)
               self._find(tests, val, valname, module, source_lines,
                          globs, seen)
   
       # Look for tests in a class's contained objects.
       if inspect.isclass(obj) and self._recurse:
           for valname, val in obj.__dict__.items():
               # Check if this contained object should be ignored.
               if self._filter(val, name, valname):
                   continue
               # Special handling for staticmethod/classmethod.
               if isinstance(val, staticmethod):
                   val = getattr(obj, valname)
               if isinstance(val, classmethod):
                   val = getattr(obj, valname).im_func
   
               # Recurse to methods, properties, and nested classes.
               if ((inspect.isfunction(val) or inspect.isclass(val) or
                     isinstance(val, property)) and
                     self._from_module(module, val)):
                   valname = '%s.%s' % (name, valname)
                   self._find(tests, val, valname, module, source_lines,
                              globs, seen)
compat/doctest.py - line 989
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
   def _get_test(self, obj, name, module, globs, source_lines):
       """
           Return a DocTest for the given object, if it defines a docstring;
           otherwise, return None.
           """
       # Extract the object's docstring.  If it doesn't have one,
       # then return None (no test for this object).
       if isinstance(obj, basestring):
           docstring = obj
       else:
           try:
               if obj.__doc__ is None:
                   docstring = ''
               else:
                   docstring = obj.__doc__
                   if not isinstance(docstring, basestring):
                       docstring = str(docstring)
           except (TypeError, AttributeError):
               docstring = ''
   
       # Find the docstring's location in the file.
       lineno = self._find_lineno(obj, source_lines)
   
       # Don't bother if the docstring is empty.
       if self._exclude_empty and not docstring:
           return None
   
       # Return a DocTest for this object.
       if module is None:
           filename = None
       else:
           filename = getattr(module, '__file__', module.__name__)
           if filename[-4:] in (".pyc", ".pyo"):
               filename = filename[:-1]
       return self._parser.get_doctest(docstring, globs, name,
->                                     filename, lineno)
compat/doctest.py - line 601
592
593
594
595
596
597
598
599
600
601
602
   def get_doctest(self, string, globs, name, filename, lineno):
       """
           Extract all doctest examples from the given string, and
           collect them into a `DocTest` object.
   
           `globs`, `name`, `filename`, and `lineno` are attributes for
           the new `DocTest` object.  See the documentation for `DocTest`
           for more information.
           """
->     return DocTest(self.get_examples(string, name), globs,
                      name, filename, lineno, string)
compat/doctest.py - line 615
604
605
606
607
608
609
610
611
612
613
614
615
616
   def get_examples(self, string, name='<string>'):
       """
           Extract all doctest examples from the given string, and return
           them as a list of `Example` objects.  Line numbers are
           0-based, because it's most common in doctests that nothing
           interesting appears on the same line as opening triple-quote,
           and so the first interesting line is called \"line 1\" then.
   
           The optional argument `name` is a name identifying this
           string, and is only used for error messages.
           """
->     return [x for x in self.parse(string, name)
               if isinstance(x, Example)]
compat/doctest.py - line 583
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
   def parse(self, string, name='<string>'):
       """
           Divide the given string into examples and intervening text,
           and return them as a list of alternating Examples and strings.
           Line numbers for the Examples are 0-based.  The optional
           argument `name` is a name identifying this string, and is only
           used for error messages.
           """
       string = string.expandtabs()
       # If all lines begin with the same indentation, then strip it.
       min_indent = self._min_indent(string)
       if min_indent > 0:
           string = '\n'.join([l[min_indent:] for l in string.split('\n')])
   
       output = []
       charno, lineno = 0, 0
       # Find all doctest examples in the string:
       for m in self._EXAMPLE_RE.finditer(string):
           # Add the pre-example text to `output`.
           output.append(string[charno:m.start()])
           # Update lineno (lines before this example)
           lineno += string.count('\n', charno, m.start())
           # Extract info from the regexp match.
           (source, options, want, exc_msg) = \
                    self._parse_example(m, name, lineno)
           # Create an Example, and add it to the list.
           if not self._IS_BLANK_OR_COMMENT(source):
               output.append( Example(source, want, exc_msg,
                                   lineno=lineno,
                                   indent=min_indent+len(m.group('indent')),
->                                 options=options) )
           # Update lineno (lines inside this example)
           lineno += string.count('\n', m.start(), m.end())
           # Update charno.
           charno = m.end()
       # Add any remaining post-example text to `output`.
       output.append(string[charno:])
       return output