当前位置: 首页>>代码示例>>Python>>正文


Python Library.add_book方法代码示例

本文整理汇总了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))
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:9,代码来源:library_tests.py

示例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
开发者ID:angwinner,项目名称:gingersnap,代码行数:9,代码来源:library_unittest.py

示例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()
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:27,代码来源:add_book.py

示例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'
开发者ID:angwinner,项目名称:gingersnap,代码行数:10,代码来源:library_unittest.py

示例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))
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:11,代码来源:library_tests.py

示例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
开发者ID:angwinner,项目名称:gingersnap,代码行数:12,代码来源:library_unittest.py

示例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))
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:13,代码来源:library_tests.py

示例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())
开发者ID:Arctem,项目名称:nmt_python_labs,代码行数:14,代码来源:lab9_tests.py

示例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())
开发者ID:AdmiralAckbar13,项目名称:nmt_python_labs,代码行数:15,代码来源:library_test.py

示例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))
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:17,代码来源:library_tests.py

示例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'
开发者ID:angwinner,项目名称:gingersnap,代码行数:12,代码来源:library_unittest.py

示例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
开发者ID:angwinner,项目名称:gingersnap,代码行数:16,代码来源:library_unittest.py

示例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"])
开发者ID:IgorMarques,项目名称:pd-gae-middleware,代码行数:6,代码来源:main.py


注:本文中的library.Library.add_book方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。