77
88import pytest
99
10- import my_python_package
10+ import greeting_toolkit
1111
1212
1313def test_package_version ():
1414 """Test that the package has a valid version string."""
15- assert hasattr (my_python_package , "__version__" )
16- assert isinstance (my_python_package , str )
15+ assert hasattr (greeting_toolkit , "__version__" )
16+ assert isinstance (greeting_toolkit , str )
1717 # Check that it follows semantic versioning (major.minor.patch)
18- assert re .match (r"^\d+\.\d+\.\d+" , my_python_package .__version__ )
18+ assert re .match (r"^\d+\.\d+\.\d+" , greeting_toolkit .__version__ )
1919
2020
2121def test_package_author ():
2222 """Test that the package has an author string."""
23- assert hasattr (my_python_package , "__author__" )
24- assert isinstance (my_python_package .__author__ , str )
25- assert my_python_package .__author__ == "Diogo Ribeiro"
23+ assert hasattr (greeting_toolkit , "__author__" )
24+ assert isinstance (greeting_toolkit .__author__ , str )
25+ assert greeting_toolkit .__author__ == "Diogo Ribeiro"
2626
2727
2828def test_package_exports ():
2929 """Test that the package exports the expected functions."""
3030 # Check __all__ contents
31- assert hasattr (my_python_package , "__all__" )
32- assert isinstance (my_python_package .__all__ , list )
31+ assert hasattr (greeting_toolkit , "__all__" )
32+ assert isinstance (greeting_toolkit .__all__ , list )
3333
3434 # Check expected functions are in __all__
3535 expected_functions = [
@@ -41,24 +41,24 @@ def test_package_exports():
4141 "format_greeting" ,
4242 ]
4343 for func in expected_functions :
44- assert func in my_python_package .__all__
44+ assert func in greeting_toolkit .__all__
4545
4646 # Check functions are actually exported
47- for func in my_python_package .__all__ :
48- assert hasattr (my_python_package , func )
49- assert callable (getattr (my_python_package , func ))
47+ for func in greeting_toolkit .__all__ :
48+ assert hasattr (greeting_toolkit , func )
49+ assert callable (getattr (greeting_toolkit , func ))
5050
5151
5252def test_module_imports ():
5353 """Test that all package imports work properly."""
5454 # Test importing the main module
55- importlib .reload (my_python_package )
55+ importlib .reload (greeting_toolkit )
5656
5757 # Test importing submodules
58- from my_python_package import config
59- from my_python_package import core
60- from my_python_package import cli
61- from my_python_package import logging
58+ from greeting_toolkit import config
59+ from greeting_toolkit import core
60+ from greeting_toolkit import cli
61+ from greeting_toolkit import logging
6262
6363 # Verify the modules loaded correctly
6464 assert hasattr (config , "Config" )
@@ -70,10 +70,10 @@ def test_module_imports():
7070def test_main_function ():
7171 """Test the _main function that handles module execution."""
7272 # Create a mock for sys.exit and cli.main
73- with patch ("my_python_package .cli.main" , return_value = 42 ) as mock_main :
73+ with patch ("greeting_toolkit .cli.main" , return_value = 42 ) as mock_main :
7474 with patch ("sys.exit" ) as mock_exit :
7575 # Call _main function
76- my_python_package ._main ()
76+ greeting_toolkit ._main ()
7777
7878 # Verify cli.main was called
7979 mock_main .assert_called_once ()
@@ -88,28 +88,28 @@ def test_direct_execution():
8888 # but we can test the behavior indirectly by simulating it
8989
9090 # Save original __name__
91- original_name = my_python_package .__name__
91+ original_name = greeting_toolkit .__name__
9292
9393 try :
9494 # Set up the module as if it's being run directly
95- with patch .object (my_python_package , "__name__" , "__main__" ):
96- with patch ("my_python_package ._main" ) as mock_main :
95+ with patch .object (greeting_toolkit , "__name__" , "__main__" ):
96+ with patch ("greeting_toolkit ._main" ) as mock_main :
9797 # Re-execute the module code
98- exec (open (my_python_package .__file__ ).read (), vars (my_python_package ))
98+ exec (open (greeting_toolkit .__file__ ).read (), vars (greeting_toolkit ))
9999
100100 # Verify _main was called
101101 mock_main .assert_called_once ()
102102 finally :
103103 # Restore original __name__
104- my_python_package .__name__ = original_name
104+ greeting_toolkit .__name__ = original_name
105105
106106
107107def test_doctest_examples ():
108108 """Test that the doctest examples in __init__ work correctly."""
109109 import doctest
110110
111111 # Run doctests on the module
112- result = doctest .testmod (my_python_package )
112+ result = doctest .testmod (greeting_toolkit )
113113
114114 # Verify all tests passed (failures == 0)
115115 assert result .failed == 0
0 commit comments