コード例 #1
0
 def __init__(self, filename):
     """
     Constructor method
     Opens the file and loads the entries in memory
     filename is a string, the path to the file used for storage
     O(n)
     """
     BookList.__init__(self)
     self.__filename = filename
     try:
         self.__bookFile = open(self.__filename, "r")
     except IOError:
         # File does not exist. Create it.
         self.__bookFile = open(self.__filename, "w")
         self.__bookFile.close()
         self.__bookFile = open(self.__filename, "r")
     line = "Nonempty String"
     while (line != ""):
         line = self.__bookFile.readline()
         if (line == "" or line == "\n"):
             break
         details = line.split("|")
         book = Book(details[0].strip(), details[1].strip(),
                     details[2].strip())
         if details[3] == "True":
             book.setBorrowed(True)
         book.setPopularity(int(details[4]))
         self.bookList.append(book)
     self.__bookFile.close()
コード例 #2
0
ファイル: RepositoryInFiles.py プロジェクト: VladutZzZ/Labs
 def __init__(self, filename):
     """
     Constructor method
     Opens the file and loads the entries in memory
     filename is a string, the path to the file used for storage
     O(n)
     """
     BookList.__init__(self)
     self.__filename = filename
     try:
         self.__bookFile = open(self.__filename, "r")
     except IOError:
         # File does not exist. Create it.
         self.__bookFile = open(self.__filename, "w")
         self.__bookFile.close()
         self.__bookFile = open(self.__filename, "r")
     line = "Nonempty String"
     while (line != ""):
         line = self.__bookFile.readline()
         if (line == "" or line == "\n"):
             break
         details = line.split("|")
         book = Book(details[0].strip(), details[1].strip(), details[2].strip())
         if details[3] == "True":
             book.setBorrowed(True)
         book.setPopularity(int(details[4]))
         self.bookList.append(book)
     self.__bookFile.close()
コード例 #3
0
ファイル: Library.py プロジェクト: tudorgergely/Labs
'''
Created on Nov 1, 2012

@author: Mihai Costea
'''
from blackBox import blackBoxTest_updateBook
from controller.Controller import LibraryController
from controller.tests import test_controller
from repository.RepositoryInFiles import BookListInFile, ClientListInFile
from repository.Storage import BookList, ClientList
from ui.Console import Console

if __name__ == '__main__':

    #bookList = BookList()
    #clientList = ClientList()
    bookList = BookListInFile("books.dat")
    clientList = ClientListInFile("clients.dat")
    testBookList = BookList()
    testClientList = ClientList()
    test_controller(testBookList, testClientList)
    blackBoxTest_updateBook()
    libraryController = LibraryController(bookList, clientList)
    console = Console(libraryController)
コード例 #4
0
ファイル: tests.py プロジェクト: tudorgergely/Labs
def test_BookList():
    bookList = BookList()
    bookList.addNewBook("title", "author", "description")
    assert bookList.numberOfBooks() == 1
    assert bookList.lastAddedBook().getTitle() == "title"
    assert bookList.lastAddedBook().getAuthor() == "author"
    assert bookList.lastAddedBook().getDescription() == "description"
    bookList.addNewBook("a", "a", "a")
    bookList.updateBook("a", "a", "a", "b", "b", "b")
    assert bookList.lastAddedBook().getTitle() == "b"
    assert bookList.lastAddedBook().getAuthor() == "b"
    assert bookList.lastAddedBook().getDescription() == "b"
    """
コード例 #5
0
ファイル: blackBox.py プロジェクト: VladutZzZ/Labs
def blackBoxTest_updateBook():
    bookList = BookList()
    bookList.addNewBook("a", "a", "a")
    assert bookList.updateBook("a", "a", "a", "b", "b", "b") == True
    assert bookList.updateBook("a", "a", "a", "b", "b", "b") == False