Exemplo n.º 1
0
 def test_get_authors(self):
     from library import Book, Library
     tests = [Book('The Life and Lies of Albus Dumbledore', 'Rita Skeeter'),
         ('Some Other Book by Someone'),
         Book('Lab 9', 'The Best TA'),
         Book('Yet Another Book', 'Someone')]
     lib = Library()
     for test in tests:
         lib.add_book(test)
     self.assertEquals(len(lib.get_authors()), 3)
     self.assertIn('Someone', lib.get_authors())
     self.assertNotIn('', lib.get_authors())
def main():
    lib = Library()
    lib.add_book(Book('The Life and Lies of Albus Dumbledore', 'Rita Skeeter'))

    with open('library.txt', 'r') as lib_data:
        for line in lib_data:
            lib.add_book(line)

    print(lib)
    print(lib.get_authors())
    assert len(set(lib.get_authors())) == len(lib.get_authors())
    print(lib.get_books_per_author())
    assert len(lib.get_books_per_author()) == len(lib.get_authors())