[Checkins] SVN: martian/branches/paw-manuel-fake-module/src/martian/ Updated doctests. Almost all tests pass.

Paul Wilson paulalexwilson at gmail.com
Mon Jan 4 11:56:04 EST 2010


Log message for revision 107635:
  Updated doctests. Almost all tests pass. 
  
  Done a fairly mechanical set of changes to the tests
  to use manuelpi.fakemodule. There are two outstanding
  failing tests that need investigating, but its almost
  there.
  
  Need also to review the tests to make sure the narrative
  still flows and makes sense.
  
  

Changed:
  U   martian/branches/paw-manuel-fake-module/src/martian/context.txt
  U   martian/branches/paw-manuel-fake-module/src/martian/core.txt
  U   martian/branches/paw-manuel-fake-module/src/martian/edgecase.txt

-=-
Modified: martian/branches/paw-manuel-fake-module/src/martian/context.txt
===================================================================
--- martian/branches/paw-manuel-fake-module/src/martian/context.txt	2010-01-04 15:28:58 UTC (rev 107634)
+++ martian/branches/paw-manuel-fake-module/src/martian/context.txt	2010-01-04 16:56:04 UTC (rev 107635)
@@ -35,40 +35,39 @@
 
   >>> class A(object):
   ...   pass
-  >>> class explicitclasscontext(FakeModule):
-  ...    class B(object):
-  ...      context(A)
-  >>> from martiantest.fake import explicitclasscontext
+
+.. module-block:: explicitclasscontext
+   class B(object):
+     context(A)
+
   >>> context.bind().get(explicitclasscontext.B)
   <class 'A'>
 
 Let's now use the directive on the module-level, explicitly::
 
-  >>> class explicitmodulecontext(FakeModule):
-  ...   context(A)
-  ...   class B(object):
-  ...     pass
-  >>> from martiantest.fake import explicitmodulecontext
+.. module-block:: explicitmodulecontext
+   context(A)
+   class B(object):
+     pass
+
   >>> context.bind().get(explicitmodulecontext.B)
-  <class 'martiantest.fake.explicitmodulecontext.A'>
+  <class 'A'>
 
-XXX why does this get this put into martiantest.fake.explicitmodule? A
-problem in FakeModule?
-
 Let's see a combination of the two, to check whether context on the class
 level overrides that on the module level::
 
   >>> class D(object):
   ...   pass
-  >>> class explicitcombo(FakeModule):
-  ...   context(A)
-  ...   class B(object):
-  ...     pass
-  ...   class C(object):
-  ...     context(D)
-  >>> from martiantest.fake import explicitcombo
+
+.. module-block:: explicitcombo
+   context(A)
+   class B(object):
+     pass
+   class C(object):
+     context(D)
+
   >>> context.bind().get(explicitcombo.B)
-  <class 'martiantest.fake.explicitcombo.A'>
+  <class 'A'>
   >>> context.bind().get(explicitcombo.C)
   <class 'D'>
 
@@ -91,91 +90,92 @@
 
 Let's experiment whether implicit context association works::
 
-  >>> class implicitcontext(FakeModule):
-  ...    class A(Context):
-  ...      pass
-  ...    class B(object):
-  ...      pass
-  >>> from martiantest.fake import implicitcontext
+.. module-block:: implicitcontext
+    class A(Context):
+      pass
+    class B(object):
+      pass
+
   >>> context.bind(get_default=get_default_context).get(implicitcontext.B)
-  <class 'martiantest.fake.implicitcontext.A'>
+  <class 'manueltest.fake.implicitcontext.A'>
 
 We now test the failure conditions.
 
 There is no implicit context to associate with::
 
-  >>> class noimplicitcontext(FakeModule):
-  ...    class B(object):
-  ...      pass
-  >>> from martiantest.fake import noimplicitcontext
+.. module-block:: noimplicitcontext
+    class B(object):
+      pass
+
+  >>> dir(noimplicitcontext)
+  >>> globals().keys()
   >>> context.bind(get_default=get_default_context).get(noimplicitcontext.B)
   Traceback (most recent call last):
     ...
-  GrokError: No module-level context for <class 'martiantest.fake.noimplicitcontext.B'>, please use the 'context' directive.
+  GrokError: No module-level context for <class 'manueltest.fake.noimplicitcontext.B'>, please use the 'context' directive.
 
 There are too many possible contexts::
 
-  >>> class ambiguouscontext(FakeModule):
-  ...   class A(Context):
-  ...     pass
-  ...   class B(Context):
-  ...     pass
-  ...   class C(object):
-  ...     pass
-  >>> from martiantest.fake import ambiguouscontext
+.. module-block:: ambiguouscontext
+   class A(Context):
+     pass
+   class B(Context):
+     pass
+   class C(object):
+     pass
+
   >>> context.bind(get_default=get_default_context).get(ambiguouscontext.B)
   Traceback (most recent call last):
     ... 
-  GrokError: Multiple possible contexts for <class 'martiantest.fake.ambiguouscontext.B'>, please use the 'context' directive.
+  GrokError: Multiple possible contexts for <class 'manueltest.fake.ambiguouscontext.B'>, please use the 'context' directive.
 
 Let's try this with inheritance, where an implicit context is provided
 by a base class defined in another module::
 
-  >>> class basemodule(FakeModule):
-  ...   class A(Context):
-  ...     pass
-  ...   class B(object):
-  ...     pass
-  >>> from martiantest.fake import basemodule
-  >>> class submodule(FakeModule):
-  ...   class C(basemodule.B):
-  ...     pass
-  >>> from martiantest.fake import submodule
+.. module-block:: basemodule
+   class A(Context):
+     pass
+   class B(object):
+     pass
+
+.. module-block:: submodule
+   class C(basemodule.B):
+     pass
+
   >>> context.bind(get_default=get_default_context).get(submodule.C)
-  <class 'martiantest.fake.basemodule.A'>
+  <class 'manueltest.fake.basemodule.A'>
 
 Let's try it again with an ambiguous context in this case, resolved because
 there is an unambiguous context for the base class ``B``::
 
-  >>> class basemodule2(FakeModule):
-  ...   class A(Context):
-  ...     pass
-  ...   class B(object):
-  ...     pass
-  >>> from martiantest.fake import basemodule2
-  >>> class submodule2(FakeModule):
-  ...   class Ambiguous1(Context):
-  ...     pass
-  ...   class Ambiguous2(Context):
-  ...     pass
-  ...   class C(basemodule2.B):
-  ...     pass
-  >>> from martiantest.fake import submodule2
+.. module-block:: basemodule2
+   class A(Context):
+     pass
+   class B(object):
+     pass
+
+.. module-block:: submodule2
+   class Ambiguous1(Context):
+     pass
+   class Ambiguous2(Context):
+     pass
+   class C(basemodule2.B):
+     pass
   >>> context.bind(get_default=get_default_context).get(submodule2.C)
-  <class 'martiantest.fake.basemodule2.A'>
+  <class 'manueltest.fake.basemodule2.A'>
 
 If the implicit context cannot be found in the base class either, the error
 will show up for the most specific class (``C``)::
 
-  >>> class basemodule3(FakeModule):
-  ...   class B(object):
-  ...     pass
-  >>> from martiantest.fake import basemodule3
-  >>> class submodule3(FakeModule):
-  ...   class C(basemodule3.B):
-  ...     pass
-  >>> from martiantest.fake import submodule3
+.. module-block:: basemodule3
+   class B(object):
+     pass
+
+.. module-block:: submodule3
+   class C(basemodule3.B):
+     pass
+
   >>> context.bind(get_default=get_default_context).get(submodule3.C)
   Traceback (most recent call last):
     ...
-  GrokError: No module-level context for <class 'martiantest.fake.submodule3.C'>, please use the 'context' directive.
+  GrokError: No module-level context for <class 'manueltest.fake.submodule3.C'>, please use the 'context' directive.

Modified: martian/branches/paw-manuel-fake-module/src/martian/core.txt
===================================================================
--- martian/branches/paw-manuel-fake-module/src/martian/core.txt	2010-01-04 15:28:58 UTC (rev 107634)
+++ martian/branches/paw-manuel-fake-module/src/martian/core.txt	2010-01-04 16:56:04 UTC (rev 107635)
@@ -7,22 +7,21 @@
 Let's look at a very simple framework where files are handled by their
 extensions::
 
-  >>> class filehandler(FakeModule):
-  ...   import os
-  ...
-  ...   def handle_txt(filepath):
-  ...     return "Text file"
-  ...
-  ...   def handle_xml(filepath):
-  ...     return "XML file"
-  ...
-  ...   extension_handlers = { '.txt': handle_txt, '.xml': handle_xml }
-  ...
-  ...   def handle(filepath):
-  ...      name, ext = os.path.splitext(filepath)
-  ...      return extension_handlers[ext](filepath)
-  >>> from martiantest.fake import filehandler
+.. module-block:: filehandler
+  import os
 
+  def handle_txt(filepath):
+    return "Text file"
+
+  def handle_xml(filepath):
+    return "XML file"
+
+  extension_handlers = { '.txt': handle_txt, '.xml': handle_xml }
+
+  def handle(filepath):
+     name, ext = os.path.splitext(filepath)
+     return extension_handlers[ext](filepath)
+
 Now let's try the ``handle`` function for a few file types::
 
   >>> filehandler.handle('test.txt')
@@ -41,13 +40,12 @@
 We now want to plug into this filehandler framework and provide a
 handler for ``.png`` files::
 
-  >>> class pnghandler(FakeModule):
-  ...    def handle_png(filepath):
-  ...        return "PNG file"
-  ...
-  ...    filehandler.extension_handlers['.png'] = handle_png
-  >>> from martiantest.fake import pnghandler
+.. module-block:: pnghandler
+   def handle_png(filepath):
+       return "PNG file"
 
+   filehandler.extension_handlers['.png'] = handle_png
+
 In the extension module, we manipulate the ``extension_handlers``
 dictionary of the ``filehandler`` module and plug in our own
 function. PNG handling works now::
@@ -144,17 +142,16 @@
 We now define a module that defines a few filetype handlers to be
 grokked::
 
-  >>> class lotsofhandlers(FakeModule):
-  ...   def handle_exe(filepath):
-  ...     return "EXE file"
-  ...
-  ...   def handle_ogg(filepath):
-  ...     return "OGG file"
-  ...
-  ...   def handle_svg(filepath):
-  ...     return "SVG file"
-  >>> from martiantest.fake import lotsofhandlers
+.. module-block:: lotsofhandlers
+  def handle_exe(filepath):
+    return "EXE file"
 
+  def handle_ogg(filepath):
+    return "OGG file"
+
+  def handle_svg(filepath):
+    return "SVG file"
+
 Let's grok it::
 
   >>> module_grokker.grok('lotsofhandlers', lotsofhandlers)
@@ -178,22 +175,21 @@
 having to register them manually. This allows us to rewrite our
 original module and take out the manual registrations completely::
 
-  >>> class filehandler(FakeModule):
-  ...   import os
-  ...
-  ...   def handle_txt(filepath):
-  ...     return "Text file"
-  ...
-  ...   def handle_xml(filepath):
-  ...     return "XML file"
-  ...
-  ...   extension_handlers = {}
-  ...
-  ...   def handle(filepath):
-  ...      name, ext = os.path.splitext(filepath)
-  ...      return extension_handlers[ext](filepath)
-  >>> from martiantest.fake import filehandler
+.. module-block:: filehandler
+  import os
 
+  def handle_txt(filepath):
+    return "Text file"
+
+  def handle_xml(filepath):
+    return "XML file"
+
+  extension_handlers = {}
+
+  def handle(filepath):
+     name, ext = os.path.splitext(filepath)
+     return extension_handlers[ext](filepath)
+
 Let's use martian to do the registrations for us::
 
   >>> module_grokker.grok('filehandler', filehandler)
@@ -207,16 +203,15 @@
 We have seen how to grok module-level functions. Let's now grok some
 other kind of instance, a ``Color``::
 
-  >>> class color(FakeModule):
-  ...   class Color(object):
-  ...     def __init__(self, r, g, b):
-  ...       self.r = r
-  ...       self.g = g
-  ...       self.b = b
-  ...     def __repr__(self):
-  ...       return '<Color %s %s %s>' % (self.r, self.g, self.b)
-  ...   all_colors = {}
-  >>> from martiantest.fake import color
+.. module-block:: color
+  class Color(object):
+    def __init__(self, r, g, b):
+      self.r = r
+      self.g = g
+      self.b = b
+    def __repr__(self):
+      return '<Color %s %s %s>' % (self.r, self.g, self.b)
+  all_colors = {}
 
 We now want a grokker that can recognize colors and put them in the
 ``all_colors`` dictionary, with the names as the keys, and the color
@@ -244,12 +239,14 @@
 multiple colors in a module::
 
   >>> Color = color.Color
-  >>> class colors(FakeModule):
-  ...   red = Color(255, 0, 0)
-  ...   green = Color(0, 255, 0)
-  ...   blue = Color(0, 0, 255)
-  ...   white = Color(255, 255, 255)
-  >>> from martiantest.fake import colors
+
+.. module-block:: colors
+
+  red = Color(255, 0, 0)
+  green = Color(0, 255, 0)
+  blue = Color(0, 0, 255)
+  white = Color(255, 255, 255)
+::
   >>> colors_grokker = martian.ModuleGrokker()
   >>> colors_grokker.register(color_grokker)
   >>> colors_grokker.grok('colors', colors)
@@ -263,11 +260,11 @@
 
 Subclasses of ``Color`` are also grokked::
 
-  >>> class subcolors(FakeModule):
-  ...   class SpecialColor(Color):
-  ...     pass
-  ...   octarine = SpecialColor(-255, 0, -255)
-  >>> from martiantest.fake import subcolors
+.. module-block:: subcolors
+  class SpecialColor(Color):
+    pass
+  octarine = SpecialColor(-255, 0, -255)
+::
   >>> colors_grokker.grok('subcolors', subcolors)
   True
   >>> 'octarine' in color.all_colors
@@ -281,14 +278,13 @@
 ``Color``. Let's introduce another ``InstanceGrokker`` that looks for
 instances of ``Sound``::
 
-  >>> class sound(FakeModule):
-  ...   class Sound(object):
-  ...     def __init__(self, desc):
-  ...       self.desc = desc
-  ...     def __repr__(self):
-  ...       return '<Sound %s>' % (self.desc)
-  ...   all_sounds = {}
-  >>> from martiantest.fake import sound
+.. module-block:: sound
+  class Sound(object):
+    def __init__(self, desc):
+      self.desc = desc
+    def __repr__(self):
+      return '<Sound %s>' % (self.desc)
+  all_sounds = {}
 
   >>> class SoundGrokker(martian.InstanceGrokker):
   ...   martian.component(sound.Sound)
@@ -337,12 +333,13 @@
 We can now grok a module for both ``Color`` and ``Sound`` instances::
 
   >>> Sound = sound.Sound
-  >>> class lightandsound(FakeModule):
-  ...   dark_red = Color(150, 0, 0)
-  ...   scream = Sound('scream')
-  ...   dark_green = Color(0, 150, 0)
-  ...   cheer = Sound('cheer')
-  >>> from martiantest.fake import lightandsound
+
+.. module-block:: lightandsound
+  dark_red = Color(150, 0, 0)
+  scream = Sound('scream')
+  dark_green = Color(0, 150, 0)
+  cheer = Sound('cheer')
+::
   >>> module_grokker.grok('lightandsound', lightandsound)
   True
   >>> 'dark_red' in color.all_colors
@@ -361,22 +358,21 @@
 application where we register classes representing animals.  Animals
 can be given names using the ``name`` directive::
 
-  >>> from martian.directive import Directive, CLASS, ONCE
+.. module-block:: animal
+  from martian.directive import Directive, CLASS, ONCE
+  class name(Directive):
+    scope = CLASS
+    store = ONCE
 
-  >>> class animal(FakeModule):
-  ...   class name(Directive):
-  ...     scope = CLASS
-  ...     store = ONCE
-  ...
-  ...   class Animal(object):
-  ...     def __repr__(self):
-  ...       return '<Animal %s>' % animal.name.bind().get(self)
-  ...
-  ...   all_animals = {}
-  ...   def create_animal(name):
-  ...     return all_animals[name]()
-  >>> from martiantest.fake import animal
+  class Animal(object):
+    def __repr__(self):
+      return '<Animal %s>' % name.bind().get(self)
 
+  all_animals = {}
+
+  def create_animal(name):
+    return all_animals[name]()
+
 Let's define a grokker that can grok an ``Animal``.  We could either
 implement the ``grok`` method as with ``InstanceGrokkers``, or we can
 rely on the implementation that the baseclass already provides.  In
@@ -560,16 +556,15 @@
 ``Animal`` subclasses (but not the ``Chair`` class, which is not an
 animal) automatically become available::
 
-  >>> class animals(FakeModule):
-  ...   class Elephant(animal.Animal):
-  ...     animal.name('elephant')
-  ...   class Tiger(animal.Animal):
-  ...     animal.name('tiger')
-  ...   class Lion(animal.Animal):
-  ...     animal.name('lion')
-  ...   class Chair(object):
-  ...     animal.name('chair')
-  >>> from martiantest.fake import animals
+.. module-block:: animals
+  class Elephant(animal.Animal):
+    animal.name('elephant')
+  class Tiger(animal.Animal):
+    animal.name('tiger')
+  class Lion(animal.Animal):
+    animal.name('lion')
+  class Chair(object):
+    animal.name('chair')
 
 First we need to wrap our ``AnimalGrokker`` into a ``MultiClassGrokker``::
 
@@ -688,39 +683,38 @@
 Let's make a module which has a mixture between classes and instances,
 some of which can be grokked::
 
-  >>> class mix(FakeModule):
-  ...   # grokked by AnimalGrokker
-  ...   class Whale(animal.Animal):
-  ...      animal.name('whale')
-  ...   # not grokked
-  ...   my_whale = Whale()
-  ...   # grokked by ColorGrokker
-  ...   dark_grey = Color(50, 50, 50)
-  ...   # grokked by SoundGrokker
-  ...   music = Sound('music')
-  ...   # not grokked
-  ...   class RockMusic(Sound):
-  ...      pass
-  ...   # grokked by SoundGrokker
-  ...   rocknroll = RockMusic('rock n roll')
-  ...   # grokked by AnimalGrokker
-  ...   class Dragon(animal.Animal):
-  ...     animal.name('dragon')
-  ...   # not grokked
-  ...   class Chair(object):
-  ...     pass
-  ...   # grokked by filetype_grokker
-  ...   def handle_py(filepath):
-  ...     return "Python file"
-  ...   # not grokked
-  ...   def foo():
-  ...     pass
-  ...   # grokked by AnimalGrokker
-  ...   class SpermWhale(Whale):
-  ...     animal.name('sperm whale')
-  ...   # not grokked
-  ...   another = object()
-  >>> from martiantest.fake import mix
+.. module-block:: mix
+  # grokked by AnimalGrokker
+  class Whale(animal.Animal):
+     animal.name('whale')
+  # not grokked
+  my_whale = Whale()
+  # grokked by ColorGrokker
+  dark_grey = Color(50, 50, 50)
+  # grokked by SoundGrokker
+  music = Sound('music')
+  # not grokked
+  class RockMusic(Sound):
+     pass
+  # grokked by SoundGrokker
+  rocknroll = RockMusic('rock n roll')
+  # grokked by AnimalGrokker
+  class Dragon(animal.Animal):
+    animal.name('dragon')
+  # not grokked
+  class Chair(object):
+    pass
+  # grokked by filetype_grokker
+  def handle_py(filepath):
+    return "Python file"
+  # not grokked
+  def foo():
+    pass
+  # grokked by AnimalGrokker
+  class SpermWhale(Whale):
+    animal.name('sperm whale')
+  # not grokked
+  another = object()
 
 Let's construct a ``ModuleGrokker`` that can grok this module::
 
@@ -759,9 +753,8 @@
 static files associated with the module by name. Let's create a module
 with some global value::
 
-  >>> class g(FakeModule):
-  ...   amount = 50
-  >>> from martiantest.fake import g
+.. module-block:: g
+   amount = 50
 
 Now let's create a ``GlobalGrokker`` that reads ``amount`` and stores
 it in the ``read_amount`` dictionary::
@@ -792,12 +785,11 @@
 new-style classes. It is also possible to grok old-style classes and
 their instances::
 
-  >>> class oldstyle(FakeModule):
-  ...   class Machine:
-  ...     pass
-  ...   all_machines = {}
-  ...   all_machine_instances = {}
-  >>> from martiantest.fake import oldstyle
+.. module-block:: oldstyle
+  class Machine:
+    pass
+  all_machines = {}
+  all_machine_instances = {}
 
 Let's make a grokker for the old style class::
 
@@ -894,11 +886,11 @@
 
 Let's try this with a module::
 
-  >>> class numbers(FakeModule):
-  ...   one = Number(1)
-  ...   two = Number(2)
-  ...   four = Number(4)
-  >>> from martiantest.fake import numbers
+.. module-block:: numbers
+  one = Number(1)
+  two = Number(2)
+  four = Number(4)
+::
   >>> module_grokker.grok('numbers', numbers)
   True
   >>> sorted(all_numbers.items())
@@ -1038,13 +1030,14 @@
   >>> class TestOnce(object):
   ...   pass
   >>> executed = []
-  >>> class somemodule(FakeModule):
-  ...   class TestGrokker(martian.ClassGrokker):
-  ...     martian.component(TestOnce)
-  ...     def grok(self, name, obj, **kw):
-  ...        executed.append(name)
-  ...        return True
-  >>> from martiantest.fake import somemodule
+
+.. module-block:: somemodule
+  class TestGrokker(martian.ClassGrokker):
+    martian.component(TestOnce)
+    def grok(self, name, obj, **kw):
+       executed.append(name)
+       return True
+::
   >>> module_grokker = martian.ModuleGrokker(MetaMultiGrokker())
 
 Let's grok the module once::
@@ -1060,10 +1053,10 @@
 Even though we have grokked it twice, it is still only registered once. We
 can show this by actually having it grok a ``TestOnce`` subclass::
 
-  >>> class anothermodule(FakeModule):
-  ...   class TestSub(TestOnce):
-  ...      pass
-  >>> from martiantest.fake import anothermodule
+.. module-block:: anothermodule
+  class TestSub(TestOnce):
+     pass
+::
   >>> module_grokker.grok('anothermodule', anothermodule)
   True
   >>> executed
@@ -1074,21 +1067,25 @@
   >>> class TestInstanceOnce(object):
   ...   pass
   >>> executed = []
-  >>> class somemodule(FakeModule):
-  ...   class TestGrokker(martian.InstanceGrokker):
-  ...     martian.component(TestInstanceOnce)
-  ...     def grok(self, name, obj, **kw):
-  ...        executed.append(name)
-  ...        return True
-  >>> from martiantest.fake import somemodule
+
+.. module-block:: somemodule
+
+  class TestGrokker(martian.InstanceGrokker):
+     martian.component(TestInstanceOnce)
+     def grok(self, name, obj, **kw):
+        executed.append(name)
+        return True
+::
   >>> module_grokker.clear()
   >>> module_grokker.grok('somemodule', somemodule) # once
   True
   >>> module_grokker.grok('somemodule', somemodule) # twice
   True
-  >>> class anothermodule(FakeModule):
-  ...   test = TestInstanceOnce()
-  >>> from martiantest.fake import anothermodule
+
+.. module-block:: anothermodule
+  test = TestInstanceOnce()
+
+::
   >>> module_grokker.grok('anothermodule', anothermodule)
   True
   >>> executed
@@ -1097,12 +1094,14 @@
 It also works for global grokkers::
 
   >>> executed = []
-  >>> class somemodule(FakeModule):
-  ...   class TestGrokker(GlobalGrokker):
-  ...     def grok(self, name, obj, **kw):
-  ...       executed.append(name)
-  ...       return True
-  >>> from martiantest.fake import somemodule
+
+.. module-block:: somemodule
+  class TestGrokker(GlobalGrokker):
+    def grok(self, name, obj, **kw):
+      executed.append(name)
+      return True
+
+::
   >>> module_grokker.clear()
   >>> module_grokker.grok('somemodule', somemodule) # once
   True
@@ -1116,9 +1115,10 @@
 
 Now let's grok another module::
 
-  >>> class anothermodule(FakeModule):
-  ...   pass
-  >>> from martiantest.fake import anothermodule
+.. module-block:: anothermodule
+   pass
+
+::
   >>> module_grokker.grok('anothermodule', anothermodule)
   True
   >>> executed
@@ -1166,12 +1166,11 @@
 
 Let's create a module containing ``A`` and ``B`` subclasses::
 
-  >>> class mymodule(FakeModule):
-  ...   class ASub(A):
-  ...     pass
-  ...   class BSub(B):
-  ...     pass
-  >>> from martiantest.fake import mymodule
+.. module-block:: mymodule
+  class ASub(A):
+    pass
+  class BSub(B):
+    pass
 
 We'll grok it::
 

Modified: martian/branches/paw-manuel-fake-module/src/martian/edgecase.txt
===================================================================
--- martian/branches/paw-manuel-fake-module/src/martian/edgecase.txt	2010-01-04 15:28:58 UTC (rev 107634)
+++ martian/branches/paw-manuel-fake-module/src/martian/edgecase.txt	2010-01-04 16:56:04 UTC (rev 107635)
@@ -16,16 +16,14 @@
 Now let's look at a module that contains a simple function and a call
 to the directive defined above:
 
-  >>> class module_with_directive(FakeModule):
-  ...     fake_module = True
-  ...
-  ...     def some_function():
-  ...         return 11
-  ...
-  ...     store(some_function)
-  ...
-  >>> from martiantest.fake import module_with_directive
+.. module-block:: module_with_directive
+    fake_module = True
 
+    def some_function():
+        return 11
+
+    store(some_function)
+
 Now imagine we have the following grokker for functions:
 
   >>> import types
@@ -57,9 +55,12 @@
   >>> class mydir(martian.Directive):
   ...     scope = MODULE
   ...     store = ONCE  
-  >>> class module_no_explicit_value(FakeModule):
-  ...     fake_module = True
-  >>> from martiantest.fake import module_no_explicit_value
+
+.. module-block:: module_no_explicit_value
+    fake_module = True
+
+::
+
   >>> mydir.bind().get(module_no_explicit_value) is None
   True
 
@@ -68,10 +69,12 @@
   >>> class mydir2(martian.Directive):
   ...     scope = MODULE
   ...     store = ONCE  
-  >>> class module_with_explicit_value(FakeModule):
-  ...     fake_module = True
-  ...     mydir2('the explicit value')
-  >>> from martiantest.fake import module_with_explicit_value
+
+.. module-block:: module_with_explicit_value
+    fake_module = True
+    mydir2('the explicit value')
+
+
   >>> mydir2.bind().get(module_with_explicit_value)
   'the explicit value'
 
@@ -80,9 +83,10 @@
   >>> class mydir(martian.Directive):
   ...     scope = MODULE
   ...     store = ONCE  
-  >>> class module_custom_default(FakeModule):
-  ...     fake_module = True
-  >>> from martiantest.fake import module_custom_default
+
+.. module-block:: module_custom_default
+    fake_module = True
+
   >>> def custom(component, module, **data):
   ...     return 'a custom default value'
   >>> mydir.bind(get_default=custom).get(module_custom_default)
@@ -93,10 +97,11 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS
   ...     store = ONCE  
-  >>> class module_get_from_class_no_explicit(FakeModule):
-  ...     class MyClass(object):
-  ...         pass
-  >>> from martiantest.fake import module_get_from_class_no_explicit
+
+.. module-block:: module_get_from_class_no_explicit
+    class MyClass(object):
+        pass
+
   >>> mydir.bind().get(module_get_from_class_no_explicit.MyClass) is None
   True
 
@@ -105,11 +110,12 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS
   ...     store = ONCE  
-  >>> class module_get_from_instance_no_explicit(FakeModule):
-  ...     class MyClass(object):
-  ...         pass
-  ...     obj = MyClass()
-  >>> from martiantest.fake import module_get_from_instance_no_explicit
+
+.. module-block:: module_get_from_instance_no_explicit
+    class MyClass(object):
+        pass
+    obj = MyClass()
+
   >>> mydir.bind().get(module_get_from_instance_no_explicit.obj) is None
   True
 
@@ -118,10 +124,11 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS
   ...     store = ONCE  
-  >>> class module_get_from_class_with_explicit(FakeModule):
-  ...     class MyClass(object):
-  ...         mydir('explicitly set')
-  >>> from martiantest.fake import module_get_from_class_with_explicit
+
+.. module-block:: module_get_from_class_with_explicit
+    class MyClass(object):
+        mydir('explicitly set')
+
   >>> mydir.bind().get(module_get_from_class_with_explicit.MyClass)
   'explicitly set'
 
@@ -130,11 +137,12 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS
   ...     store = ONCE  
-  >>> class module_get_from_instance_with_explicit(FakeModule):
-  ...     class MyClass(object):
-  ...         mydir('explicitly set')
-  ...     obj = MyClass()
-  >>> from martiantest.fake import module_get_from_instance_with_explicit
+
+.. module-block:: module_get_from_instance_with_explicit
+    class MyClass(object):
+        mydir('explicitly set')
+    obj = MyClass()
+
   >>> mydir.bind().get(module_get_from_instance_with_explicit.obj)
   'explicitly set'
 
@@ -143,10 +151,11 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS
   ...     store = ONCE  
-  >>> class module_get_from_class_with_custom(FakeModule):
-  ...     class MyClass(object):
-  ...         pass
-  >>> from martiantest.fake import module_get_from_class_with_custom
+
+.. module-block:: module_get_from_class_with_custom
+    class MyClass(object):
+        pass
+
   >>> def custom_get_default(component, module, **data):
   ...     return 'custom default'
   >>> mydir.bind(get_default=custom_get_default).get(
@@ -158,11 +167,13 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS
   ...     store = ONCE  
-  >>> class module_get_from_instance_with_custom(FakeModule):
-  ...     class MyClass(object):
-  ...         pass
-  ...     obj = MyClass()
-  >>> from martiantest.fake import module_get_from_instance_with_custom
+
+.. module-block:: module_get_from_instance_with_custom
+    class MyClass(object):
+        pass
+    obj = MyClass()
+
+
   >>> mydir.bind(get_default=custom_get_default).get(
   ...     module_get_from_instance_with_custom.obj)
   'custom default'
@@ -172,10 +183,11 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  ...     pass
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+    pass
+
   >>> mydir.bind().get(module) is None
   True
 
@@ -184,11 +196,12 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  ...     class MyClass(object):
-  ...         pass
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+    class MyClass(object):
+        pass
+
   >>> mydir.bind().get(module.MyClass) is None
   True
 
@@ -197,12 +210,13 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  ...     class MyClass(object):
-  ...         pass
-  ...     obj = MyClass()
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+    class MyClass(object):
+        pass
+    obj = MyClass()
+
   >>> mydir.bind().get(module.obj) is None
   True
 
@@ -211,10 +225,11 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  ...     mydir('explicitly set, see?')
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+    mydir('explicitly set, see?')
+
   >>> mydir.bind().get(module)
   'explicitly set, see?'
 
@@ -223,11 +238,12 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  ...     class MyClass(object):
-  ...         mydir('explicitly set, see?')
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+    class MyClass(object):
+        mydir('explicitly set, see?')
+
   >>> mydir.bind().get(module.MyClass)
   'explicitly set, see?'
 
@@ -236,12 +252,13 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  ...     class MyClass(object):
-  ...         mydir('explicitly set, see?')
-  ...     obj = MyClass()
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+    class MyClass(object):
+        mydir('explicitly set, see?')
+    obj = MyClass()
+
   >>> mydir.bind().get(module.obj)
   'explicitly set, see?'
 
@@ -250,9 +267,10 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+
   >>> mydir.bind(get_default=custom_get_default).get(module)
   'custom default'
 
@@ -261,11 +279,12 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  ...     class MyClass(object):
-  ...         pass
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+    class MyClass(object):
+        pass
+
   >>> mydir.bind(get_default=custom_get_default).get(module.MyClass)
   'custom default'
 
@@ -274,12 +293,13 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE  
-  >>> class module(FakeModule):
-  ...     fake_module = True
-  ...     class MyClass(object):
-  ...         pass
-  ...     obj = MyClass()
-  >>> from martiantest.fake import module
+
+.. module-block:: module
+    fake_module = True
+    class MyClass(object):
+        pass
+    obj = MyClass()
+
   >>> mydir.bind(get_default=custom_get_default).get(module.obj)
   'custom default'
   
@@ -288,17 +308,17 @@
   >>> class mydir(martian.Directive):
   ...     scope = CLASS_OR_MODULE
   ...     store = ONCE
-  >>> class module_b(FakeModule):
-  ...     fake_module = True
-  ...     mydir('a value')
-  ...     class B(object):
-  ...         pass
-  >>> from martiantest.fake import module_b  
-  >>> class module_a(FakeModule):
-  ...     fake_module = True
-  ...     class A(module_b.B):
-  ...         pass
-  >>> from martiantest.fake import module_a
+
+.. module-block:: module_b
+    fake_module = True
+    mydir('a value')
+    class B(object):
+        pass
+
+.. module-block:: module_a
+    fake_module = True
+    class A(module_b.B):
+        pass
+
   >>> mydir.bind(get_default=custom_get_default).get(module_a.A)
   'a value'
-



More information about the checkins mailing list