Example #1
0
    def load(self, name: str):
        '''"Loads" a Shelf object by recreating the contents which has info stored in a shelf file'''
        shelf_sav = Path("SAV") / f"{name}.shelf"

        if not shelf_sav.exists():
            raise FileNotFoundError

        try:
            sav = shelf_sav.open("r")
            sav_info = sav.readlines()
        finally:
            sav.close()

        media_len = int(sav_info[0])
        sav_i = 1
        shelf_contents = {}

        for i in range(media_len):
            media_type = sav_info[sav_i][:-1]
            sav_i += 1
            backlog = media_sublist.Media_Sublist.make_items_from_str(
                sav_info[sav_i])
            sav_i += 1
            completed = media_sublist.Media_Sublist.make_items_from_str(
                sav_info[sav_i])
            shelf_contents[media_type] = (backlog, completed)
            sav_i += 1

        loaded_shelf = shelf.Shelf(name, shelf_contents)
        self._shelf = loaded_shelf
 def test_AddBook(self):
     """Tests that a book is successfully added to a shelf."""
     book1 = self.setUp()
     shelf1 = shelf.Shelf()
     shelf1.AddBook(book1)
     self.assertEqual(shelf1.GetBookCount(), 1)
     pass
Example #3
0
    def __init__(self, parent, title="Phone Directory.... TWO!"):
        wx.Frame.__init__(self, parent, title=title)
        self.SetMinSize((400, 300))

        #load any previous data
        self.shelf = shelf.Shelf('default phone directory')
        data = self.shelf.read()
        manager.SetInfo(data)

        panel = wx.Panel(self)
        self.panel = panel

        #add panes
        self.listpane = listpanel.ListPanel(panel)
        self.editpane = editpanel.EditPanel(panel)

        self.mgr = wx.aui.AuiManager()
        self.mgr.SetManagedWindow(panel)

        self.mgr.AddPane(
            self.listpane,
            wx.aui.AuiPaneInfo().Left().MinSize(
                (140, -1)).Name("list").CloseButton(False))
        self.mgr.AddPane(
            self.editpane,
            wx.aui.AuiPaneInfo().Center().MinSize(
                (200, -1)).Name("edit").Resizable(True).CloseButton(False))
        self.mgr.Update()

        self.AddMenuBar()
 def test_RemoveBook(self):
     """Tests that a book is successfully removed from a shelf."""
     book1 = self.setUp()
     shelf1 = shelf.Shelf()
     shelf1.AddBook(book1)
     shelf1.RemoveBook("Catcher in the Rye")
     self.assertEqual(shelf1.GetBookCount(), 0)
     pass
 def test_AddBook_reduces_shelf_capacity(self):
     """Tests that shelf capacity is reduced after adding a book."""
     book1 = self.setUp()
     shelf1 = shelf.Shelf()
     shelf1.AddBook(book1)
     self.assertEqual(shelf1.GetAvailableCapacity(),
                      72 - book1.GetThickness())
     pass
 def test_RemoveBook(self):
     """Tests that a book is successfully removed from a shelf, decreasing the book count from 2 to 1."""
     test_shelf = shelf.Shelf()
     little_women = book.Book("Little Women", ("Louisa", "May", "Alcott"))
     warriors = book.Book("Warriors", ("Erin", "", "Hunter"))
     test_shelf.AddBook(warriors)
     test_shelf.AddBook(little_women)
     test_shelf.RemoveBook("Little Women")
     self.assertTrue(test_shelf.GetBookCount(), 1)
    def test_shelf_space_exhausted(self):
        """Tests that an exception is raised when adding a book to a shelf with insufficient space."""
        book1 = self.setUp()
        shelf1 = shelf.Shelf()
        shelf1._ReduceCapacity(shelf1.GetInitialCapacity())
        with self.assertRaises(RuntimeError):
            shelf1.AddBook(book1)

        pass
 def test_RemoveBook_increases_shelf_capacity(self):
     """Tests that shelf capacity is increased after removing a book."""
     book1 = self.setUp()
     shelf1 = shelf.Shelf()
     shelf1.AddBook(book1)
     shelf1.RemoveBook("Catcher in the Rye")
     self.assertEqual(shelf1.GetAvailableCapacity(),
                      shelf1.GetInitialCapacity())
     pass
 def test_AddBook_reduces_shelf_capacity(self):
     """Tests that shelf capacity is reduced after adding a book,
     so the available capacity should be less than the initial capacity after adding a book."""
     test_shelf = shelf.Shelf()
     initial = test_shelf.GetInitialCapacity()
     warriors = book.Book("Warriors", ("Erin", "", "Hunter"))
     warriors.SetPages(20)
     warriors.SetCoverType(book.CoverType.HARDCOVER)
     test_shelf.AddBook(warriors)
     self.assertLess(test_shelf.GetAvailableCapacity(), initial)
Example #10
0
    def test_if_initializing_with_a_dict_whose_length_is_beyond_the_limits_of_the_shelf_makes_a_shortened_shelf(
            self):
        '''Tests if providing a dict whose length is larger than the capacity of a shelf properly recreates the shelf
        to have only the first items of the dict, after sorting, to fill up the capacity'''
        test = shelf.Shelf("test", {
            f"{i}": ([], [])
            for i in range(shelf.Shelf.get_media_limit(), -1, -1)
        })

        self.assertEqual(len(test.get_media()), shelf.Shelf.get_media_limit())
Example #11
0
    def test_if_adding_to_a_shelf_at_capacity_raises_an_overrflow_exception(
            self):
        '''Tests if attempting to add to an at capacity shelf causes it to raise a ShelfOverflowException'''
        test = shelf.Shelf(
            "test", {
                f"{i}": ([], [])
                for i in range(shelf.Shelf.get_media_limit() - 1, -1, -1)
            })

        with self.assertRaises(shelf.ShelfOverflowException):
            test.add_media("Movies")
Example #12
0
    def setUp(self):
        '''Sets up the variables needed for testing'''
        # Entry LIST VARIABLES
        self._backlog1 = []
        self._backlog2 = [
            entry.Entry("", "", "", i, 0, 1, "") for i in range(5)
        ]
        self._completed = [
            entry.Entry("", "", "", i, 0, 1, "") for i in range(5)
        ]
        for e in self._completed:
            e.set_completed()

        # Shelf VARIABLES
        self._shelf1 = shelf.Shelf("Empty")
        self._shelf2 = shelf.Shelf(
            "With-Items", {
                "3": ([], []),
                "1": (self._backlog2, []),
                "2": (self._backlog2, self._completed)
            })
 def test_shelf_space_exhausted(self):
     """Tests that an exception is raised and the book count does not change when
     adding a book to a shelf with insufficient space."""
     test_shelf = shelf.Shelf()
     little_women = book.Book("Little Women", ("Louisa", "May", "Alcott"))
     warriors = book.Book("Warriors", ("Erin", "", "Hunter"))
     warriors.SetPages(70)
     warriors.SetCoverType(book.CoverType.HARDCOVER)
     little_women.SetPages(20)
     little_women.SetCoverType(book.CoverType.HARDCOVER)
     test_shelf.AddBook(warriors)
     test_shelf.AddBook(little_women)
     self.assertRaises(RuntimeError)
     self.assertTrue(test_shelf.GetBookCount(), 1)
 def test_RemoveBook_increases_shelf_capacity(self):
     """Tests that shelf capacity is increased after removing a book,
     so the available capacity should be greater after removing a book should from a shelf containing 1 book,
     which should also be equal to the initial capacity since there are no longer books on the shelf."""
     test_shelf = shelf.Shelf()
     initial = test_shelf.GetInitialCapacity()
     warriors = book.Book("Warriors", ("Erin", "", "Hunter"))
     warriors.SetPages(20)
     warriors.SetCoverType(book.CoverType.HARDCOVER)
     test_shelf.AddBook(warriors)
     pass1 = test_shelf.GetAvailableCapacity()
     test_shelf.RemoveBook("Warriors")
     self.assertGreater(test_shelf.GetAvailableCapacity(), pass1)
     self.assertEqual(test_shelf.GetAvailableCapacity(), initial)
Example #15
0
 def make_new(self, name: str = "untitled"):
     '''Makes a new Shelf object for editing by the user'''
     self._shelf = shelf.Shelf(name)
Example #16
0
 def __init__(self):
     '''Initializes a Billy object to be essentially a blank Shelf object editor, starting off with an empty Shelf
     object which users can edit as they please'''
     self._shelf = shelf.Shelf("untitled")
 def test_AddBook(self):
     """Tests that a book is successfully added to a shelf, increasing the count of books by 1."""
     test_shelf = shelf.Shelf()
     little_women = book.Book("Little Women", ("Louisa", "May", "Alcott"))
     test_shelf.AddBook(little_women)
     self.assertTrue(test_shelf.GetBookCount(), 1)