← Back to team overview

oship-dev team mailing list archive

Re: Should I instantiate all the objects in a doctest?

 

On Tue, 2009-12-01 at 16:36 -0200, Wagner Francisco wrote:
> Hi.
> 
> I'm doing a doctest for the GenericEntry class. GenericEntry inherits
> from ContentItem which inherits from Locatable. To instantiate objects
> that inherit from Locatable, it's necessary to pass a lot of arguments
> to the __init__ method. The first test I've made I just pass to the
> __init__method simple Strings, but I'd like to know how we will do it.
> Will we instantiante all the parameters and then pass to the
> "constructor"? Or will we instantiate just the required parameters? If
> I start instantiating all the necessary classes the test will be very
> large.

You need to instantiate all attributes with their correct types.  In
many cases where the attribute isn't required, I just assigned it None.
However, at some point we'll need to do better testing than this.  But
this at least tells us that the classes will instantiate and will be the
correct type.  So in an end-user application they can check for correct
types against the Interfaces.  I only did doctests for the concrete
classes though.

As in this doctest for ReferenceRange: (of course some lines will wrap
in the email, like txt = ....)

:Test-Layer: unit

>>> from oship.openehr.datatypes import ReferenceRange, DvText, IDvText,
CodePhrase, DvUri, TermMapping, DvInterval
>>> from oship.openehr.support import TerminologyId
>>> tid = TerminologyId(u"SNOMED-CT(2003)")
>>> tid1 = TerminologyId(u"ISO_639-1")
>>> tid2 = TerminologyId(u"10646-1:1993")
>>> cpm = CodePhrase(tid,u"abc123")
>>> tm = TermMapping(cpm,u"=",None)
>>> cplang = CodePhrase(tid1,u"en")
>>> cpenc = CodePhrase(tid2,u"utf-8")
>>> uri = DvUri(u"http://www.mlhim.org";)
>>> txt = DvText(u"Some really interesting
ReferenceRange.",[tm,],u"font-family:Arial",uri,cplang,cpenc)
>>> isinstance(txt,DvText)
True
>>> intvl = DvInterval(0, 10, 1, 1)
>>> rr = ReferenceRange(txt,intvl,None,None,None)
>>> isinstance(rr,ReferenceRange)
True


One thing you need to be aware of is that interfaces all inherit from
Interface.  So, in the subclasses you need to include those abstract
interfaces in the implements function, i.e.

class ItemList(ItemStructure):
     implements(IItemList, IItemStructure)

Because in some interfaces it simply says that the attribute must
provide IItemStructure.  It can be an ItemList or ItemTable, etc.



-- 
***************************************************************
Timothy Cook, MSc

LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook 
Skype ID == (upon request)
Academic.Edu Profile: http://uff.academia.edu/TimothyCook

You may get my Public GPG key from  popular keyservers or    
from this link http://timothywayne.cook.googlepages.com/home 

Attachment: signature.asc
Description: This is a digitally signed message part


Follow ups

References