2013-10-08 32 views
0

我需要使用doctest測試以下代碼。我必須做文檔測試,而不是其他任何方法。我一直得到「預期:沒有」。有沒有辦法做到這一點?使用doctest測試長字符串

import pickle 

#Loading lists from file using the pickle module 
with open('stocklist.txt', 'rb') as f:  #Reading the list of stock from a text file. "rb" or "read binary" is used 
     thelist = pickle.load(f) 


def showstocklist():  #Defining a function for viewing the all information about the current items in the list 
    """ This function displays complete information about every item in stock. 
     Each item is diplayed in the form: 
     Software Name  Sofware Medium  Copies Available  Supplier  Index Number of Item 

     >>> showstocklist() 

     This is the current list of software available in stock: 

     ---------------------------------------------------------------------------------------------------------- 
     Ms Office  Medium = CD  Copies Available = 7  Supplier = Microsoft  Index Number = 0 
     ---------------------------------------------------------------------------------------------------------- 
     Norton Antivirus  Medium = DVD  Copies Available = 24  Supplier = Symantec  Index Number = 1 
     ---------------------------------------------------------------------------------------------------------- 
     Paint  Medium = DVD  Copies Available = 12  Supplier = The Eagle Company  Index Number = 2 
     ---------------------------------------------------------------------------------------------------------- 
     """ 
    print("") 
    print("This is the current list of software available in stock:") 
    print("") 
    print("----------------------------------------------------------------------------------------------------------") 
    for (index,[item,medium,quantity,supplier]) in enumerate(thelist): #Displaying all item information from list along with their index number 
     print (str(item), " Medium = " + str(medium), " Copies Available = " + str(quantity), " Supplier = " + str(supplier), " Index Number = " + str(index)) 
     print("----------------------------------------------------------------------------------------------------------") 

if __name__ == "__main__": 
    import doctest 
    doctest.testmod(verbose = True) 

回答

0

對我來說,它看起來像第一print("") IST的問題。 我看到的所有示例都是在>>>行後立即開始的,但您沒有任何內容。

只是猜測,嘗試:

  1. 刪除print("")

  2. 添加...>>>行之後