From 57b757c0f03f4ee01e9d3b49038ab0c063e57a02 Mon Sep 17 00:00:00 2001 From: OleehyO Date: Sat, 19 Apr 2025 16:31:37 +0000 Subject: [PATCH] [test] Init --- tests/test_globals.py | 68 ++++++++++++++++++++++++++++++++++++++++++ tests/test_to_katex.py | 8 +++++ 2 files changed, 76 insertions(+) create mode 100644 tests/test_globals.py create mode 100644 tests/test_to_katex.py diff --git a/tests/test_globals.py b/tests/test_globals.py new file mode 100644 index 0000000..d4fd136 --- /dev/null +++ b/tests/test_globals.py @@ -0,0 +1,68 @@ +import pytest +import logging +from texteller.globals import Globals + + +def test_singleton_pattern(): + """Test that Globals uses the singleton pattern correctly.""" + # Create two instances + globals1 = Globals() + globals2 = Globals() + + # Both variables should reference the same object + assert globals1 is globals2 + + # Modifying one should affect the other + globals1.test_attr = "test_value" + assert globals2.test_attr == "test_value" + + # Clean up after test + delattr(globals1, "test_attr") + + +def test_predefined_attributes(): + """Test predefined attributes have correct default values.""" + globals_instance = Globals() + assert globals_instance.repo_name == "OleehyO/TexTeller" + assert globals_instance.logging_level == logging.INFO + + +def test_attribute_modification(): + """Test that attributes can be modified.""" + globals_instance = Globals() + + # Modify existing attribute + original_repo_name = globals_instance.repo_name + globals_instance.repo_name = "NewRepo/NewName" + assert globals_instance.repo_name == "NewRepo/NewName" + + assert Globals().logging_level == logging.INFO + Globals().logging_level = logging.DEBUG + assert Globals().logging_level == logging.DEBUG + + # Reset for other tests + globals_instance.repo_name = original_repo_name + globals_instance.logging_level = logging.INFO + + +def test_dynamic_attributes(): + """Test that new attributes can be added dynamically.""" + globals_instance = Globals() + + # Add new attribute + globals_instance.new_attribute = "new_value" + assert globals_instance.new_attribute == "new_value" + + # Clean up after test + delattr(globals_instance, "new_attribute") + + +def test_representation(): + """Test the string representation of Globals.""" + globals_instance = Globals() + repr_string = repr(globals_instance) + + # Check that repr contains class name and is formatted as expected + assert repr_string.startswith("