本文整理汇总了Python中library.Library.add_book方法的典型用法代码示例。如果您正苦于以下问题:Python Library.add_book方法的具体用法?Python Library.add_book怎么用?Python Library.add_book使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类library.Library
的用法示例。
在下文中一共展示了Library.add_book方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_book
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_add_book(self):
Library(self.store, ["Fantasy"])
Library.add_book(self.books[0])
self.assertEqual([self.books[0]], Library.books)
self.add_books([self.books[0], self.books[1]], Library)
self.assertEqual([self.books[0], self.books[1]], Library.books)
os.remove(os.path.realpath(self.store))
示例2: test_duplicate_books
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_duplicate_books(self):
testlib = Library()
testlib.add_book(576.82, 'A New History of Life')
testlib.add_book(576.82, 'A New History of Life')
assert len(testlib.shelves[5].books) == 2
testlib.remove_book(576.82)
assert len(testlib.shelves[5].books) == 1
示例3: addBook
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def addBook(self):
"""
Use the entered information if it is valid in order to add the
book after the Add button is pushed.
"""
data = [
self.titleEdit.text(),
self.authorEdit.text(),
self.yearEdit.text(),
self.genre_options.currentText(),
self.ratingEdit.text(),
self.copiesEdit.text(),
]
invalid_data = Validations.check_all(*data)
if invalid_data == []:
new_book = Book(*data)
Library.add_book(new_book)
self.label.setText("You added the book successfully!")
else:
message = "Unsuccessful addition!Invalid:\n"
message += "\n".join(invalid_data)
self.label.setText(message)
for gadget in self.gadgets:
if gadget != self.genre_options:
gadget.clear()
示例4: test_sorting
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_sorting(self):
testlib = Library()
testlib.add_book(100.32, 'First Book')
testlib.add_book(199.3, 'Last Book')
testlib.add_book(150, 'Middle Book')
assert testlib.shelves[1].books[0].title == 'First Book'
assert testlib.shelves[1].books[1].title == 'Middle Book'
assert testlib.shelves[1].books[2].title == 'Last Book'
示例5: test_number_of_different_books
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_number_of_different_books(self):
Library(self.store, ["Fantasy", "Thriller"])
self.add_books([self.books[0], self.books[1], self.books[2]], Library)
self.assertEqual(3, Library.number_of_different_books())
Library.add_book(self.books[0])
self.assertEqual(3, Library.number_of_different_books())
Library.remove_book(self.books[1])
self.assertEqual(2, Library.number_of_different_books())
os.remove(os.path.realpath(self.store))
示例6: test_remove_book
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_remove_book(self):
testlib = Library()
testlib.add_book(576.82, 'A New History of Life')
testlib.add_book(575.01, 'An Old History of Life')
assert len(testlib.shelves[5].books) == 2
testlib.remove_book(576.82)
assert len(testlib.shelves[5].books) == 1
# remove nonexistent book
testlib.remove_book(501.2)
assert len(testlib.shelves[5].books) == 1
示例7: test_create_genre_dict
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_create_genre_dict(self):
Library(self.store, ["Fantasy", "Thriller"])
self.add_books([self.books[0], self.books[1], self.books[2]], Library)
Library.create_genre_dict()
expected_dict = {"Fantasy": [self.books[1], self.books[0]],
"Thriller": [self.books[2]]}
self.assertEqual(expected_dict, Library.genre_dict)
Library.add_book(self.books[3])
expected_dict["Thriller"].append(self.books[3])
self.assertEqual(expected_dict, Library.genre_dict)
os.remove(os.path.realpath(self.store))
示例8: test_get_authors
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
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())
示例9: main
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
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())
示例10: test_number_of_books_by_genres
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_number_of_books_by_genres(self):
Library(self.store, ["Fantasy", "Thriller"])
self.add_books([self.books[0], self.books[1], self.books[2]], Library)
actual_result = Library.number_of_books_by_genres()
self.assertEqual({'Fantasy': 2, 'Thriller': 1}, actual_result)
Library.add_book(self.books[3])
actual_result = Library.number_of_books_by_genres()
self.assertEqual({'Fantasy': 2, 'Thriller': 2}, actual_result)
Library.remove_book(self.books[1])
actual_result = Library.number_of_books_by_genres()
self.assertEqual({'Fantasy': 1, 'Thriller': 2}, actual_result)
Library.remove_book(self.books[0])
actual_result = Library.number_of_books_by_genres()
self.assertEqual({'Fantasy': 0, 'Thriller': 2}, actual_result)
os.remove(os.path.realpath(self.store))
示例11: test_add_book
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_add_book(self):
testlib = Library()
testlib.add_book(006.74, 'Teach Yourself HTML and CSS')
testlib.add_book(576.82, 'A New History of Life')
testlib.add_book(741.5942, 'The Thrilling Adventures of Lovelace and Babbage')
assert testlib.shelves[0].books[0].dewey == 006.74
assert testlib.shelves[0].books[0].title == 'Teach Yourself HTML and CSS'
assert testlib.shelves[5].books[0].dewey == 576.82
assert testlib.shelves[5].books[0].title == 'A New History of Life'
assert testlib.shelves[7].books[0].title == 'The Thrilling Adventures of Lovelace and Babbage'
示例12: test_report_inventory
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def test_report_inventory(self):
testlib = Library()
testlib.add_book(006.74, 'Teach Yourself HTML and CSS')
testlib.add_book(576.82, 'A New History of Life')
testlib.add_book(741.5942, 'The Thrilling Adventures of Lovelace and Babbage')
testlib.add_book(741.5942, 'The Thrilling Adventures of Lovelace and Babbage')
out = StringIO()
report = "The books in this library are:\n"
report += "6.74 - Teach Yourself HTML and CSS\n"
report += "576.82 - A New History of Life\n"
report += "741.5942 - The Thrilling Adventures of Lovelace and Babbage\n"
report += "741.5942 - The Thrilling Adventures of Lovelace and Babbage\n"
testlib.report_inventory(out)
assert out.getvalue() == report
示例13: put
# 需要导入模块: from library import Library [as 别名]
# 或者: from library.Library import add_book [as 别名]
def put(self):
params = decode(self.request.body)
Library.add_book(self, params["name"], params["qtd"])