<commit_before># coding=utf-8

import unittest
import sys

sys.path.append ("../UI")
import UI
import time


# Things to test:
#   Creating a window
#   
#
#
#
#   Closing the window

class OpenUITestCase (unittest.TestCase):
    def runTest (self):
        display = UI.UI ()
        assert display.gui_thread.is_alive ()

# Create Display Object
# Add Books
# Display Library

# Create Display Object
# Display Library
# Add Books

class LibraryScreenTestCase (unittest.TestCase):
    def _ABADL_Book (self, id, display):
        callback = lambda: -1
        
        display.add_book_to_library (callback, "res/test_bookcover.png")
        
        time.sleep (0.1)
        
        children = display.libraryscreen.sizer.GetChildren ()
        
        assert (len (children) == id + 1)
        
        children[id].Window.enqueue_callback ()
        with display.callback_queue_lock:
            assert (callback in display.callback_queue)
        
        assert (children[id].Window.IsShown ())
    
    def testAddBooksAndDisplayLibrary (self):
        display = UI.UI ()
        
        self._ABADL_Book (0, display)
        
        assert (not display.libraryscreen.IsShown ())
        display.display_library ()
        time.sleep (0.1)
        assert (display.libraryscreen.IsShown ())
        
        self._ABADL_Book(1, display)


def suite ():
    suite = unittest.TestSuite ()
    suite.addTest (OpenUITestCase ())
    suite.addTest (LibraryScreenTestCase ())
    return suite
    
    
if __name__ == "__main__":
    unittest.main()<commit_msg>Added check to ensure GUI thread is alive when testing adding books and displaying the library.<commit_after># coding=utf-8

import unittest
import sys

sys.path.append ("../UI")
import UI
import time


# Things to test:
#   Creating a window
#
#
#
#
#   Closing the window

class OpenUITestCase (unittest.TestCase):
    def runTest (self):
        display = UI.UI ()
        assert display.gui_thread.is_alive ()

# Create Display Object
# Add Books
# Display Library

# Create Display Object
# Display Library
# Add Books

class LibraryScreenTestCase (unittest.TestCase):
    def _ABADL_Book (self, id, display):
        callback = lambda: -1
        
        display.add_book_to_library (callback, "res/test_bookcover.png")
        
        time.sleep (0.1)
        
        children = display.libraryscreen.sizer.GetChildren ()
        
        assert (len (children) == id + 1)
        
        children[id].Window.enqueue_callback ()
        with display.callback_queue_lock:
            assert (callback in display.callback_queue)
        
        assert (children[id].Window.IsShown ())
    
    def testAddBooksAndDisplayLibrary (self):
        display = UI.UI ()
        
        self._ABADL_Book (0, display)
        
        assert (not display.libraryscreen.IsShown ())
        display.display_library ()
        time.sleep (0.1)
        assert (display.libraryscreen.IsShown ())
        
        self._ABADL_Book(1, display)
        
        assert display.gui_thread.is_alive ()


def suite ():
    suite = unittest.TestSuite ()
    suite.addTest (OpenUITestCase ())
    suite.addTest (LibraryScreenTestCase ())
    return suite


if __name__ == "__main__":
    unittest.main()
{'fraction_non_alphanumeric': 0.09914057704112952, 'fraction_numerical': 0.0055248618784530384, 'mean_word_length': 2.3323108384458076, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2837714', 'n_tokens_mistral': 983, 'n_tokens_neox': 967, 'n_words': 234}