-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add unit tests for TerminalDisplay class
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import unittest | ||
from src.xiwen.utils.terminal_display import ( | ||
get_TerminalDisplay_instance, | ||
TerminalDisplay, | ||
) | ||
|
||
|
||
class TestTerminalDisplay(unittest.TestCase): | ||
def test_references_to_TerminalDisplay(self): | ||
"""Test separate references are equal""" | ||
A = TerminalDisplay() | ||
B = TerminalDisplay() | ||
self.assertEqual(A, B) | ||
|
||
def test_one_TerminalDisplay_exists(self): | ||
"""Test just one instance exists despite multiple calls""" | ||
A = TerminalDisplay() | ||
B = TerminalDisplay() | ||
self.assertIs(A, B._instance) | ||
|
||
def test_TerminalDisplay_attributes_exist(self): | ||
"""Test TerminalDisplay has expected attributes""" | ||
A = TerminalDisplay() | ||
self.assertTrue(hasattr(A, "WELCOME_MESSAGE")) | ||
self.assertTrue(hasattr(A, "MAIN_MENU_OPTIONS")) | ||
self.assertTrue(hasattr(A, "DEMO_MESSAGE")) | ||
self.assertTrue(hasattr(A, "EXPORT_OPTIONS")) | ||
self.assertTrue(hasattr(A, "EXPORT_OPTIONS_FOR_CUSTOM_GRADES")) | ||
self.assertTrue(hasattr(A, "UNKNOWN_CHARACTER_VARIANT")) | ||
|
||
|
||
class TestGetTerminalDisplayInstance(unittest.TestCase): | ||
def test_instance_returned(self): | ||
"""Test function returns an TerminalDisplay instance""" | ||
A = get_TerminalDisplay_instance() | ||
self.assertTrue(isinstance(A, TerminalDisplay)) | ||
|
||
def test_returns_same_instance(self): | ||
"""Test multiple calls return same TerminalDisplay instance""" | ||
A = get_TerminalDisplay_instance() | ||
B = get_TerminalDisplay_instance() | ||
self.assertIs(A, B._instance) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |