rite 0.0.2__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. {rite-0.0.2 → rite-0.0.3}/PKG-INFO +1 -1
  2. {rite-0.0.2 → rite-0.0.3}/pyproject.toml +7 -7
  3. rite-0.0.2/src/rite/__main__.py → rite-0.0.3/src/rite/--__main__.py +1 -1
  4. {rite-0.0.2 → rite-0.0.3}/src/rite/__init__.py +10 -10
  5. rite-0.0.2/src/main.py +0 -0
  6. rite-0.0.2/src/rite/folder/__init__.py +0 -0
  7. rite-0.0.2/src/tests/__init__.py +0 -0
  8. rite-0.0.2/src/tests/data/test_buffer_circular.py +0 -213
  9. rite-0.0.2/src/tests/data/test_singleton.py +0 -145
  10. rite-0.0.2/src/tests/log/logger.py +0 -137
  11. {rite-0.0.2 → rite-0.0.3}/LICENSE +0 -0
  12. {rite-0.0.2 → rite-0.0.3}/README.md +0 -0
  13. {rite-0.0.2 → rite-0.0.3}/docs/CNAME +0 -0
  14. {rite-0.0.2 → rite-0.0.3}/docs/about/authors.md +0 -0
  15. {rite-0.0.2 → rite-0.0.3}/docs/assets/favicon/android-chrome-192x192.png +0 -0
  16. {rite-0.0.2 → rite-0.0.3}/docs/assets/favicon/android-chrome-512x512.png +0 -0
  17. {rite-0.0.2 → rite-0.0.3}/docs/assets/favicon/apple-touch-icon.png +0 -0
  18. {rite-0.0.2 → rite-0.0.3}/docs/assets/favicon/favicon-16x16.png +0 -0
  19. {rite-0.0.2 → rite-0.0.3}/docs/assets/favicon/favicon-32x32.png +0 -0
  20. {rite-0.0.2 → rite-0.0.3}/docs/assets/favicon/favicon.ico +0 -0
  21. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-bold.otf +0 -0
  22. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-bold.ttf +0 -0
  23. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-bold.woff2 +0 -0
  24. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-extrabold.otf +0 -0
  25. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-extrabold.ttf +0 -0
  26. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-extrabold.woff2 +0 -0
  27. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-extralight.otf +0 -0
  28. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-extralight.ttf +0 -0
  29. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-extralight.woff2 +0 -0
  30. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-light.otf +0 -0
  31. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-light.ttf +0 -0
  32. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-light.woff2 +0 -0
  33. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-medium.otf +0 -0
  34. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-medium.ttf +0 -0
  35. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-medium.woff2 +0 -0
  36. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-regular.otf +0 -0
  37. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-regular.ttf +0 -0
  38. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-regular.woff2 +0 -0
  39. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-semibold.otf +0 -0
  40. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-semibold.ttf +0 -0
  41. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-semibold.woff2 +0 -0
  42. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-variable.ttf +0 -0
  43. {rite-0.0.2 → rite-0.0.3}/docs/assets/font/manrope/manrope-variable.woff2 +0 -0
  44. {rite-0.0.2 → rite-0.0.3}/docs/assets/image/rite_logo_dark.png +0 -0
  45. {rite-0.0.2 → rite-0.0.3}/docs/assets/image/rite_logo_light.png +0 -0
  46. {rite-0.0.2 → rite-0.0.3}/docs/assets/script/extra.js +0 -0
  47. {rite-0.0.2 → rite-0.0.3}/docs/assets/style/extra.css +0 -0
  48. {rite-0.0.2 → rite-0.0.3}/docs/development/build.md +0 -0
  49. {rite-0.0.2 → rite-0.0.3}/docs/index.md +0 -0
  50. {rite-0.0.2 → rite-0.0.3}/docs/legal/disclaimer.md +0 -0
  51. {rite-0.0.2 → rite-0.0.3}/docs/legal/license.md +0 -0
  52. {rite-0.0.2 → rite-0.0.3}/docs/legal/privacy_policy.md +0 -0
  53. {rite-0.0.2 → rite-0.0.3}/docs/overrides/_main.html +0 -0
  54. {rite-0.0.2 → rite-0.0.3}/docs/quick_start.md +0 -0
  55. {rite-0.0.2 → rite-0.0.3}/docs/resources/glossary.md +0 -0
  56. {rite-0.0.2 → rite-0.0.3}/docs/resources/links.md +0 -0
  57. {rite-0.0.2 → rite-0.0.3}/docs/robots.txt +0 -0
  58. {rite-0.0.2 → rite-0.0.3}/docs/security.txt +0 -0
  59. {rite-0.0.2 → rite-0.0.3}/docs/site.webmanifest +0 -0
  60. {rite-0.0.2/src → rite-0.0.3/src/rite/data}/__init__.py +0 -0
  61. {rite-0.0.2 → rite-0.0.3}/src/rite/data/buffer_circular.py +0 -0
  62. {rite-0.0.2 → rite-0.0.3}/src/rite/data/colour.py +0 -0
  63. {rite-0.0.2 → rite-0.0.3}/src/rite/data/date.py +0 -0
  64. {rite-0.0.2 → rite-0.0.3}/src/rite/data/image_raster.py +0 -0
  65. {rite-0.0.2 → rite-0.0.3}/src/rite/data/pixel.py +0 -0
  66. {rite-0.0.2 → rite-0.0.3}/src/rite/data/singleton.py +0 -0
  67. {rite-0.0.2 → rite-0.0.3}/src/rite/data/utils.py +0 -0
  68. {rite-0.0.2 → rite-0.0.3}/src/rite/file/__init__.py +0 -0
  69. {rite-0.0.2 → rite-0.0.3}/src/rite/file/geojson.py +0 -0
  70. {rite-0.0.2 → rite-0.0.3}/src/rite/file/ini.py +0 -0
  71. {rite-0.0.2 → rite-0.0.3}/src/rite/file/json.py +0 -0
  72. {rite-0.0.2 → rite-0.0.3}/src/rite/file/obj.py +0 -0
  73. {rite-0.0.2 → rite-0.0.3}/src/rite/file/utils.py +0 -0
  74. {rite-0.0.2/src/rite/data → rite-0.0.3/src/rite/folder}/__init__.py +0 -0
  75. {rite-0.0.2 → rite-0.0.3}/src/rite/folder/file.py +0 -0
  76. {rite-0.0.2 → rite-0.0.3}/src/rite/folder/folder.py +0 -0
  77. {rite-0.0.2 → rite-0.0.3}/src/rite/folder/path.py +0 -0
  78. {rite-0.0.2 → rite-0.0.3}/src/rite/log/__init__.py +0 -0
  79. {rite-0.0.2 → rite-0.0.3}/src/rite/log/logger.py +0 -0
  80. {rite-0.0.2 → rite-0.0.3}/src/rite/server/__init__.py +0 -0
  81. {rite-0.0.2 → rite-0.0.3}/src/rite/server/http.py +0 -0
  82. {rite-0.0.2 → rite-0.0.3}/src/rite/server/sqlite.py +0 -0
  83. {rite-0.0.2 → rite-0.0.3}/src/rite/text/__init__.py +0 -0
  84. {rite-0.0.2 → rite-0.0.3}/src/rite/text/case.py +0 -0
  85. {rite-0.0.2 → rite-0.0.3}/src/rite/text/cipher.py +0 -0
  86. {rite-0.0.2 → rite-0.0.3}/src/rite/text/morse.py +0 -0
  87. {rite-0.0.2 → rite-0.0.3}/src/rite/text/slug.py +0 -0
  88. {rite-0.0.2 → rite-0.0.3}/src/rite/text/url.py +0 -0
  89. {rite-0.0.2 → rite-0.0.3}/src/rite/text/uuid.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rite
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Python Utility Package
5
5
  Home-page: https://www.pyrites.dev
6
6
  License: MIT
@@ -7,7 +7,7 @@
7
7
 
8
8
  [tool.poetry]
9
9
  name = "rite"
10
- version = "0.0.2"
10
+ version = "0.0.3"
11
11
  description = "Python Utility Package"
12
12
  authors = ["Scape Agency <info@scape.agency>"]
13
13
  license = "MIT License"
@@ -28,7 +28,7 @@ classifiers = [
28
28
  "Topic :: Software Development :: Libraries :: Python Modules",
29
29
  ]
30
30
  include = [
31
- "src/**",
31
+ "src/rite/**",
32
32
  "README.md",
33
33
  "LICENSE",
34
34
  "docs/**", # Include documentation in the package
@@ -76,11 +76,11 @@ build-backend = "poetry.core.masonry.api"
76
76
  # =============================================================================
77
77
 
78
78
  [tool.poetry.scripts]
79
- rite = "rite.__main__:main" # Entry point for the package
80
- test = "pytest --cov=rite tests/:main" # Run tests with coverage
81
- lint = "flake8 src/rite/:main" # Run linter on source files
82
- format = "black src/rite/:main" # Format source files
83
- type-check = "mypy src/rite/:main" # Type-check source files
79
+ rite = "rite.__main__:main" # Entry point for the package
80
+ # test = "pytest --cov=rite tests/:main" # Run tests with coverage
81
+ # lint = "flake8 src/rite/:main" # Run linter on source files
82
+ # format = "black src/rite/:main" # Format source files
83
+ # type-check = "mypy src/rite/:main" # Type-check source files
84
84
 
85
85
 
86
86
  # =============================================================================
@@ -47,7 +47,7 @@ if __name__ == "__main__":
47
47
  print()
48
48
  print("rite is set!")
49
49
  print()
50
- print("tite: {}".format(rite.__version__))
50
+ print("rite: {}".format(rite.__version__))
51
51
  print(
52
52
  "Python: {} ({})".format(
53
53
  platform.python_version(), platform.python_implementation()
@@ -33,13 +33,13 @@ Links:
33
33
  # Information
34
34
  # =============================================================================
35
35
 
36
- __author__ = "Lars van Vianen"
37
- __copyright__ = "Copyright 2022, Scape Agency"
38
- __credits__ = [
39
- "Lars van Vianen",
40
- ]
41
- __license__ = "MIT License"
42
- __version__ = "0.0.1"
43
- __maintainer__ = "Scape Agency"
44
- __email__ = "info@scape.agency"
45
- __status__ = "Alpha"
36
+ __author__ = "Lars van Vianen"
37
+ __copyright__ = "Copyright 2022, Scape Agency"
38
+ __credits__ = [
39
+ "Lars van Vianen",
40
+ ]
41
+ __license__ = "MIT License"
42
+ __version__ = "0.0.3"
43
+ __maintainer__ = "Scape Agency"
44
+ __email__ = "info@scape.agency"
45
+ __status__ = "Alpha"
rite-0.0.2/src/main.py DELETED
File without changes
File without changes
File without changes
@@ -1,213 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # =============================================================================
4
- # Docstring
5
- # =============================================================================
6
-
7
- """
8
- Tests for CircularBuffer Module
9
- ===============================
10
-
11
- This test suite verifies the functionality of the `CircularBuffer` class,
12
- which implements a fixed-size ring buffer with overwriting behavior when full.
13
-
14
- Tested Features:
15
- ----------------
16
- - Append elements and verify correct order.
17
- - Check the full and empty state of the buffer.
18
- - Handle overwriting of oldest elements.
19
- - Proper handling of edge cases like zero or negative size.
20
- - Validate `__repr__` output.
21
-
22
- Dependencies:
23
- -------------
24
- - `pytest` for writing and executing tests.
25
- """
26
-
27
- # =============================================================================
28
- # Imports
29
- # =============================================================================
30
-
31
- import pytest
32
-
33
- from rite.data.buffer_circular import CircularBuffer
34
-
35
- # =============================================================================
36
- # Test Cases
37
- # =============================================================================
38
-
39
-
40
- def test_initialization():
41
- """
42
- Test initialization of the CircularBuffer.
43
- """
44
- buffer = CircularBuffer(size=3)
45
- assert buffer.is_empty(), "Buffer should be empty upon initialization."
46
- assert (
47
- not buffer.is_full()
48
- ), "Buffer should not be full upon initialization."
49
- assert buffer.get_all() == [], "Buffer contents should be empty."
50
-
51
- with pytest.raises(
52
- ValueError, match="Buffer size must be a positive integer."
53
- ):
54
- CircularBuffer(size=0)
55
-
56
- with pytest.raises(
57
- ValueError, match="Buffer size must be a positive integer."
58
- ):
59
- CircularBuffer(size=-1)
60
-
61
-
62
- def test_append_and_get_all():
63
- """
64
- Test appending elements to the buffer and retrieving them.
65
- """
66
- buffer = CircularBuffer(size=3)
67
- buffer.append(1)
68
- buffer.append(2)
69
-
70
- assert buffer.get_all() == [
71
- 1,
72
- 2,
73
- ], "Buffer should return appended elements in correct order."
74
- assert (
75
- not buffer.is_full()
76
- ), "Buffer should not be full after partial appending."
77
- assert (
78
- not buffer.is_empty()
79
- ), "Buffer should not be empty after appending elements."
80
-
81
- buffer.append(3)
82
- assert buffer.is_full(), "Buffer should be full after reaching its size."
83
- assert buffer.get_all() == [
84
- 1,
85
- 2,
86
- 3,
87
- ], "Buffer should contain all appended elements."
88
-
89
-
90
- def test_overwrite_behavior():
91
- """
92
- Test overwriting behavior when the buffer is full.
93
- """
94
- buffer = CircularBuffer(size=3)
95
- buffer.append(1)
96
- buffer.append(2)
97
- buffer.append(3)
98
- buffer.append(4) # Overwrites 1
99
- buffer.append(5) # Overwrites 2
100
-
101
- assert buffer.is_full(), "Buffer should remain full after overwriting."
102
- assert buffer.get_all() == [
103
- 3,
104
- 4,
105
- 5,
106
- ], "Buffer should overwrite the oldest elements correctly."
107
-
108
-
109
- def test_edge_case_single_element_buffer():
110
- """
111
- Test behavior with a buffer size of 1.
112
- """
113
- buffer = CircularBuffer(size=1)
114
- buffer.append(1)
115
- assert buffer.get_all() == [
116
- 1
117
- ], "Buffer should store a single element correctly."
118
- buffer.append(2) # Overwrites 1
119
- assert buffer.get_all() == [
120
- 2
121
- ], "Buffer should overwrite the single element correctly."
122
-
123
-
124
- def test_is_empty():
125
- """
126
- Test the is_empty() method of the CircularBuffer.
127
- """
128
- buffer = CircularBuffer(size=3)
129
- assert buffer.is_empty(), "Buffer should be empty initially."
130
-
131
- buffer.append(1)
132
- assert (
133
- not buffer.is_empty()
134
- ), "Buffer should not be empty after appending an element."
135
-
136
- buffer.append(2)
137
- buffer.append(3)
138
- assert not buffer.is_empty(), "Buffer should not be empty when full."
139
-
140
-
141
- def test_is_full():
142
- """
143
- Test the is_full() method of the CircularBuffer.
144
- """
145
- buffer = CircularBuffer(size=3)
146
- assert not buffer.is_full(), "Buffer should not be full initially."
147
-
148
- buffer.append(1)
149
- buffer.append(2)
150
- assert (
151
- not buffer.is_full()
152
- ), "Buffer should not be full after partial appending."
153
-
154
- buffer.append(3)
155
- assert (
156
- buffer.is_full()
157
- ), "Buffer should be full after appending maximum elements."
158
-
159
-
160
- def test_repr():
161
- """
162
- Test the __repr__ method of the CircularBuffer.
163
- """
164
- buffer = CircularBuffer(size=3)
165
- buffer.append(1)
166
- buffer.append(2)
167
- repr_output = repr(buffer)
168
-
169
- expected_output = (
170
- "CircularBuffer(\n"
171
- " size=3,\n"
172
- " buffer=[1, 2],\n"
173
- " full=False\n"
174
- ")"
175
- )
176
- assert (
177
- repr_output == expected_output
178
- ), "The __repr__ output should match the expected format."
179
-
180
-
181
- def test_large_buffer():
182
- """
183
- Test the behavior of a large buffer.
184
- """
185
- buffer = CircularBuffer(size=1000)
186
- for i in range(1000):
187
- buffer.append(i)
188
-
189
- assert (
190
- len(buffer.get_all()) == 1000
191
- ), "Buffer should hold the maximum number of elements."
192
- buffer.append(1001)
193
- assert (
194
- buffer.get_all()[0] == 1
195
- ), "Buffer should overwrite the oldest element correctly."
196
-
197
-
198
- def test_get_all_empty():
199
- """
200
- Test get_all() on an empty buffer.
201
- """
202
- buffer = CircularBuffer(size=3)
203
- assert (
204
- buffer.get_all() == []
205
- ), "Buffer should return an empty list when no elements are appended."
206
-
207
-
208
- # =============================================================================
209
- # Run Tests
210
- # =============================================================================
211
-
212
- if __name__ == "__main__":
213
- pytest.main()
@@ -1,145 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # =============================================================================
4
- # Docstring
5
- # =============================================================================
6
-
7
- """
8
- Tests for SingletonMeta Module
9
- ==============================
10
-
11
- This test suite verifies the behavior of the `SingletonMeta` metaclass, which
12
- implements the Singleton design pattern. It ensures that only one instance of
13
- a class is created, regardless of how many times it is instantiated.
14
-
15
- Tested Features:
16
- ----------------
17
- - Ensures a single instance of a class using `SingletonMeta`.
18
- - Validates that multiple instantiations return the same object.
19
- - Confirms thread-safety for Singleton creation.
20
- - Verifies instance reset behavior for testing purposes.
21
-
22
- Dependencies:
23
- -------------
24
- - `pytest` for writing and executing tests.
25
- - `threading` for testing thread-safe Singleton behavior.
26
-
27
- """
28
-
29
- # =============================================================================
30
- # Imports
31
- # =============================================================================
32
-
33
- import threading
34
-
35
- import pytest
36
-
37
- from rite.data.singleton import SingletonMeta
38
-
39
- # =============================================================================
40
- # Test Classes
41
- # =============================================================================
42
-
43
-
44
- class SingletonTestClass(metaclass=SingletonMeta):
45
- """
46
- A test class to verify the Singleton behavior of `SingletonMeta`.
47
- """
48
-
49
- def __init__(self, value: str) -> None:
50
- self.value = value
51
-
52
- def __repr__(self) -> str:
53
- return f"<{self.__class__.__module__}.{self.__class__.__name__} object at {hex(id(self))}>"
54
-
55
- @classmethod
56
- def reset_instance(cls):
57
- """
58
- Reset the Singleton instance for testing purposes.
59
- """
60
- if cls in SingletonMeta._instances:
61
- del SingletonMeta._instances[cls]
62
-
63
-
64
- # =============================================================================
65
- # Test Cases
66
- # =============================================================================
67
-
68
-
69
- def test_singleton_instance():
70
- """
71
- Test that `SingletonMeta` ensures only one instance is created.
72
- """
73
- instance1 = SingletonTestClass("value1")
74
- instance2 = SingletonTestClass("value2")
75
-
76
- assert (
77
- instance1 is instance2
78
- ), "SingletonMeta should ensure a single instance."
79
- assert (
80
- instance1.value == "value2"
81
- ), "The value should reflect the latest initialization."
82
-
83
-
84
- def test_singleton_thread_safety():
85
- """
86
- Test the thread-safety of `SingletonMeta`.
87
-
88
- Ensures that even when multiple threads attempt to create an instance, only
89
- one instance is created.
90
- """
91
- instances = []
92
-
93
- def create_instance():
94
- instance = SingletonTestClass("thread-safe")
95
- instances.append(instance)
96
-
97
- threads = [threading.Thread(target=create_instance) for _ in range(10)]
98
-
99
- for thread in threads:
100
- thread.start()
101
-
102
- for thread in threads:
103
- thread.join()
104
-
105
- assert all(
106
- instance is instances[0] for instance in instances
107
- ), "All instances should be the same due to SingletonMeta."
108
-
109
-
110
- def test_singleton_reset():
111
- """
112
- Test resetting the Singleton instance for testing purposes.
113
- """
114
- instance1 = SingletonTestClass("value1")
115
- SingletonTestClass.reset_instance() # Reset the Singleton instance
116
- instance2 = SingletonTestClass("value2")
117
-
118
- assert (
119
- instance1 is not instance2
120
- ), "Resetting should allow the creation of a new instance."
121
- assert (
122
- instance2.value == "value2"
123
- ), "The new instance should have the updated value."
124
-
125
-
126
- def test_singleton_repr():
127
- """
128
- Test the `repr` output for Singleton instances.
129
-
130
- Ensures that the `repr` method provides the expected output for debugging
131
- and introspection.
132
- """
133
- instance = SingletonTestClass("repr-test")
134
- expected_repr = f"<{SingletonTestClass.__module__}.{SingletonTestClass.__name__} object at {hex(id(instance))}>"
135
- assert (
136
- repr(instance) == expected_repr
137
- ), "The `repr` method should match the expected format."
138
-
139
-
140
- # =============================================================================
141
- # Run Tests
142
- # =============================================================================
143
-
144
- if __name__ == "__main__":
145
- pytest.main()
@@ -1,137 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # =============================================================================
4
- # Docstring
5
- # =============================================================================
6
-
7
- """
8
- Tests for Logger Module
9
- =======================
10
-
11
- This test suite verifies the functionality of the `Logger` class, a configurable
12
- logging utility for applications.
13
-
14
- Tested Features:
15
- ----------------
16
- - Log messages to console and file.
17
- - Verify correct log levels for debug, info, warning, error, and critical.
18
- - Clear the log file content.
19
- - Handle invalid log levels.
20
-
21
- Dependencies:
22
- -------------
23
- - `pytest` for writing and executing tests.
24
- - `os` and `tempfile` for temporary file handling.
25
-
26
- """
27
-
28
- # =============================================================================
29
- # Imports
30
- # =============================================================================
31
-
32
- import os
33
- import tempfile
34
-
35
- import pytest
36
-
37
- from rite.log import Logger
38
-
39
- # =============================================================================
40
- # Test Cases
41
- # =============================================================================
42
-
43
-
44
- def test_logger_initialization():
45
- """
46
- Test initialization of the Logger with console and file logging.
47
- """
48
- with tempfile.NamedTemporaryFile(delete=False) as temp_log:
49
- logger = Logger(name="TestLogger", log_file=temp_log.name)
50
- assert logger.log_file == temp_log.name, "Log file path should match."
51
-
52
- os.remove(temp_log.name)
53
-
54
-
55
- def test_logging_levels():
56
- """
57
- Test logging at various levels (debug, info, warning, error, critical).
58
- """
59
- with tempfile.NamedTemporaryFile(delete=False) as temp_log:
60
- logger = Logger(name="TestLogger", log_file=temp_log.name)
61
-
62
- logger.debug("Debug message")
63
- logger.info("Info message")
64
- logger.warning("Warning message")
65
- logger.error("Error message")
66
- logger.critical("Critical message")
67
-
68
- with open(temp_log.name, "r") as log_file:
69
- log_content = log_file.read()
70
-
71
- assert (
72
- "Debug message" in log_content
73
- ), "Debug message should be logged."
74
- assert "Info message" in log_content, "Info message should be logged."
75
- assert (
76
- "Warning message" in log_content
77
- ), "Warning message should be logged."
78
- assert (
79
- "Error message" in log_content
80
- ), "Error message should be logged."
81
- assert (
82
- "Critical message" in log_content
83
- ), "Critical message should be logged."
84
-
85
- os.remove(temp_log.name)
86
-
87
-
88
- def test_invalid_log_level():
89
- """
90
- Test logging with an invalid log level.
91
- """
92
- logger = Logger(name="TestLogger")
93
-
94
- with pytest.raises(ValueError, match="Invalid log level: invalid"):
95
- logger.log("invalid", "This should raise an error")
96
-
97
-
98
- def test_clear_log():
99
- """
100
- Test clearing the log file content.
101
- """
102
- with tempfile.NamedTemporaryFile(delete=False) as temp_log:
103
- logger = Logger(name="TestLogger", log_file=temp_log.name)
104
-
105
- logger.info("Test message")
106
- logger.clear_log()
107
-
108
- with open(temp_log.name, "r") as log_file:
109
- log_content = log_file.read()
110
-
111
- assert (
112
- log_content == ""
113
- ), "Log file should be cleared after calling clear_log."
114
-
115
- os.remove(temp_log.name)
116
-
117
-
118
- def test_console_logging(capsys):
119
- """
120
- Test console logging output.
121
- """
122
- logger = Logger(name="TestLogger")
123
-
124
- logger.info("Console info message")
125
- captured = capsys.readouterr()
126
-
127
- assert (
128
- "Console info message" in captured.out
129
- ), "Console logging should capture messages."
130
-
131
-
132
- # =============================================================================
133
- # Run Tests
134
- # =============================================================================
135
-
136
- if __name__ == "__main__":
137
- pytest.main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes