def test_link_writer2manybooks_generated(): book1 = library.Book() book2 = library.Book() smith = library.Writer() smith.books.extend([book1, book2]) assert smith.books and book1 in smith.books and book2 in smith.books assert book1.authors assert book2.authors
def setUp(self): self.lib_fn = r'v:\workspace\PersistentStorage\src\lib.shelve' self.lib = library.Library(self.lib_fn) self.fixture_author1 = library.Author('Octavia', 'Estelle', 'Butler') self.fixture_book1 = library.Book('0807083100', 'Kindred', [self.fixture_author1]) self.fixture_author2 = library.Author('Robert', 'Anson', 'Heinlein') self.fixture_book2 = library.Book('0441790348', 'Stranger in a Strange Land', [self.fixture_author2]) self.lib.add(self.fixture_book1) self.lib.add(self.fixture_book2)
def setUp(self): self.lib_fn = r'/Users/chris/Documents/dev/oreilly/python/python2/lib' \ r'.shelve' self.lib = library.Library(self.lib_fn) self.fixture_author1 = library.Author('Octavia', 'Estelle', 'Butler') self.fixture_book1 = library.Book('0807083100', 'Kindred', [self.fixture_author1]) self.fixture_author2 = library.Author('Robert', 'Anson', 'Heinlein') self.fixture_book2 = library.Book('0441790348', 'Stranger in a ' 'Strange Land', [self.fixture_author2]) self.lib.add(self.fixture_book1) self.lib.add(self.fixture_book2)
def setUp(self): self.lib_fn = "/Users/Fadel/Dropbox/python/Code/Python2/05-PersistentStorage/LibraryExample/lib.shelve" self.lib = library.Library(self.lib_fn) self.fixture_author1 = library.Author("Octavia", "Estelle", "Butler") self.fixture_book1 = library.Book("0807083100", "Kindred", [self.fixture_author1]) self.fixture_author2 = library.Author("Robert‰a", "Anson", "Heinlein") self.fixture_book2 = library.Book("0441709348", "Stranger in a Strange Land", [self.fixture_author2]) self.lib.add(self.fixture_book1) self.lib.add(self.fixture_book2)
def enter_book_details_from_menu(): '''Enter details of a new book to be added to the library. Return (Book) - a new book with the entered details ''' title = read_input("Enter Book Title") author = read_input("Enter Book Author") while True: pages = read_input("Enter Book Pages (positive integer)") pages = get_int(pages, min=1) if pages is not None: break else: print("Pages must be a positive integer.") genre = read_input("Enter Book Genre") while True: width = read_input("Enter Book Width (positive integer)") width = get_int(width, min=1) if width is not None: break else: print("Width must be a positive integer.") book = l.Book(title, author, pages, genre, width) return book
def test_library_econtents_generated(): smith = library.Writer() book = library.Book() lib = library.Library() lib.writers.append(smith) lib.books.append(book) assert smith in lib.eContents assert book in lib.eContents
def test_notification_static_add(): smith = lib.Writer() b1 = lib.Book() o = LastNotification(smith) o2 = LastNotification(b1) b1.authors.append(smith) n1 = o.notification n2 = o2.notification assert n1.kind is Kind.ADD assert n1.new is b1 assert n1.feature is lib.Writer.books assert n2.kind is Kind.ADD assert n2.new is smith assert n2.feature is lib.Book.authors
def test_link_writer2book_generated(): book = library.Book() smith = library.Writer() smith.books.append(book) assert smith.books and smith.books[0] is book assert book.authors and book.authors[0] is smith
def test_book_defaultvalue_generated(): book = library.Book() assert book.category is library.BookCategory.ScienceFiction assert book.pages == 0 assert book.title is Ecore.EString.default_value
def test_create_book_generated(): book = library.Book() assert book and isinstance(book, Ecore.EObject) assert book.title is None assert book.category is library.BookCategory.ScienceFiction
def test_static_init_bad_argument(): with pytest.raises(AttributeError): library.Book(unknown=None)
def test_static_init_single_reference_bad_type(): with pytest.raises(BadValueError): library.Book(authors=[library.Book()])
def test_static_init_single_reference(): smith = library.Writer(name='Smith') book = library.Book(title='Python Roxx', pages=10, authors=[smith]) assert smith in book.authors assert book in smith.books
def test_static_init_many_attributes(): book = library.Book(pages=10, title='Python Roxx') assert book.title == 'Python Roxx' assert book.pages == 10