rdkit.Logger.demo

Package rdkit :: Package Logger :: Module demo |
[hide private]
[frames] | no frames]

# Source Code for Module rdkit.Logger.demo

     1  # $Id: demo.py 997 2009-02-25 06:12:43Z glandrum $
     2  #
     3  #       Copyright (c) 2001-2006, Greg Landrum and Rational Discovery LLC,
     4  #
     5  #   @@ All Rights Reserved  @@
     6  #
     7
     8  # Demo code for the Logger class
     9  import Logger
    10
    11 -class Foo:
    12    """ a simple class
    13    """
    14 -  def __init__(self,aVal):
    15      self.a = aVal
    16
    17 -  def method1(self,a,b,c='foo'):
    18      print 'method1',a,b,c
    19      return 'method1'
    20 -  def method2(self):
    21      print 'method2'
    22      return 'method2'
    23
    24 -def demo1():
    25    l = Logger.Logger(Foo,7)
    26    l.method1(1,2)
    27    l.method1(1,2,c='grm')
    28    l.method2()
    29    l.method1(7,6,'pizza')
    30    l.b = 3
    31    l.method2()
    32
    33    print l._LoggerGetLog()
    34
    35    f = Foo(6)
    36    r = Logger.replay(l._LoggerGetLog(),f)
    37    print 'playback results:',r
    38    # f is now in more or less the same state as l... the only differences
    39    #  will arise because of different arguments passed to the underlying
    40    #  classes __init__ method
    41    print f.b
    42
    43 -def demo2():
    44    # create a Logger which will flush itself:
    45    l = Logger.Logger(Foo,7,loggerFlushCommand='method2')
    46    l.method1(23,42)
    47    l.method1(1,2,'foo')
    48    print l._LoggerGetLog()
    49    # this will blow out the log
    50    l.method2()
    51    print l._LoggerGetLog()
    52
    53  if __name__ == '__main__':
    54    demo1()
    55    demo2()
    56