scripthelper 23.4__tar.gz → 24.1__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 (25) hide show
  1. {scripthelper-23.4 → scripthelper-24.1}/CHANGELOG.md +8 -0
  2. {scripthelper-23.4 → scripthelper-24.1}/PKG-INFO +12 -12
  3. {scripthelper-23.4 → scripthelper-24.1}/README.compiled.md +10 -10
  4. {scripthelper-23.4 → scripthelper-24.1}/README.md +9 -9
  5. {scripthelper-23.4 → scripthelper-24.1}/example2b.py +1 -1
  6. {scripthelper-23.4 → scripthelper-24.1}/justfile +2 -2
  7. {scripthelper-23.4 → scripthelper-24.1}/pyproject.toml +2 -2
  8. {scripthelper-23.4 → scripthelper-24.1}/src/scripthelper/__init__.py +51 -24
  9. {scripthelper-23.4 → scripthelper-24.1}/test_examples.py +72 -72
  10. {scripthelper-23.4 → scripthelper-24.1}/.gitignore +0 -0
  11. {scripthelper-23.4 → scripthelper-24.1}/LICENSE +0 -0
  12. {scripthelper-23.4 → scripthelper-24.1}/compile-readme.py +0 -0
  13. {scripthelper-23.4 → scripthelper-24.1}/example1.py +0 -0
  14. {scripthelper-23.4 → scripthelper-24.1}/example10.py +0 -0
  15. {scripthelper-23.4 → scripthelper-24.1}/example2.py +0 -0
  16. {scripthelper-23.4 → scripthelper-24.1}/example3.py +0 -0
  17. {scripthelper-23.4 → scripthelper-24.1}/example4.py +0 -0
  18. {scripthelper-23.4 → scripthelper-24.1}/example4module.py +0 -0
  19. {scripthelper-23.4 → scripthelper-24.1}/example5.py +0 -0
  20. {scripthelper-23.4 → scripthelper-24.1}/example6.py +0 -0
  21. {scripthelper-23.4 → scripthelper-24.1}/example7.py +0 -0
  22. {scripthelper-23.4 → scripthelper-24.1}/example8.py +0 -0
  23. {scripthelper-23.4 → scripthelper-24.1}/example9.py +0 -0
  24. {scripthelper-23.4 → scripthelper-24.1}/mypy.ini +0 -0
  25. {scripthelper-23.4 → scripthelper-24.1}/src/scripthelper/py.typed +0 -0
@@ -1,3 +1,11 @@
1
+ ## 24.1
2
+
3
+ - Add Python 3.13 support
4
+
5
+ ## 23.5
6
+
7
+ - Show the name of the logger in the log messages (can be very helpful if you use libraries which logs too much)
8
+
1
9
  ## 23.4
2
10
 
3
11
  - Use `stackprinter` module instead of `traceback_with_variables` to have pretty stack traces for unhandled exceptions
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: scripthelper
3
- Version: 23.4
3
+ Version: 24.1
4
4
  Summary: Helper module for creating simple Python scripts
5
5
  Project-URL: Homepage, https://github.com/presidento/scripthelper
6
6
  Project-URL: Changelog, https://github.com/presidento/scripthelper/blob/main/CHANGELOG.md
@@ -17,6 +17,7 @@ Classifier: Programming Language :: Python :: 3.9
17
17
  Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
20
21
  Classifier: Topic :: Utilities
21
22
  Classifier: Typing :: Typed
22
23
  Requires-Dist: coloredlogs>=10.0
@@ -24,7 +25,6 @@ Requires-Dist: persistedstate>=23.6
24
25
  Requires-Dist: prettyprinter>=0.18.0
25
26
  Requires-Dist: stackprinter>=0.2.10
26
27
  Requires-Dist: tqdm>=4.31.1
27
- Requires-Dist: verboselogs>=1.7
28
28
  Provides-Extra: dev
29
29
  Requires-Dist: black; extra == 'dev'
30
30
  Requires-Dist: build; extra == 'dev'
@@ -86,7 +86,7 @@ For bigger scripts it is good idea to have the logger at the very beginning, and
86
86
  #!/usr/bin/env python3
87
87
  import scripthelper
88
88
 
89
- logger = scripthelper.getLogger(__name__)
89
+ logger = scripthelper.getLogger()
90
90
 
91
91
 
92
92
  def greet(name):
@@ -264,21 +264,21 @@ for item in state.to_remember:
264
264
 
265
265
  ```
266
266
  $ python3 example9.py
267
- INFO Processing item #1
268
- INFO - Element 1
267
+ INFO example9 Processing item #1
268
+ INFO example9 - Element 1
269
269
 
270
270
  $ python3 example9.py
271
- INFO Processing item #2
272
- INFO - Element 1
273
- INFO - Element 2
271
+ INFO example9 Processing item #2
272
+ INFO example9 - Element 1
273
+ INFO example9 - Element 2
274
274
 
275
275
  $ python3 example9.py
276
- INFO Processing item #3
277
- INFO - Element 2
278
- INFO - Element 3
276
+ INFO example9 Processing item #3
277
+ INFO example9 - Element 2
278
+ INFO example9 - Element 3
279
279
  ```
280
280
 
281
- ## Helps issue a warning only once
281
+ ## Helps issuing a warning only once
282
282
 
283
283
  [example10.py](https://github.com/presidento/scripthelper/blob/master/example10.py):
284
284
 
@@ -52,7 +52,7 @@ For bigger scripts it is good idea to have the logger at the very beginning, and
52
52
  #!/usr/bin/env python3
53
53
  import scripthelper
54
54
 
55
- logger = scripthelper.getLogger(__name__)
55
+ logger = scripthelper.getLogger()
56
56
 
57
57
 
58
58
  def greet(name):
@@ -230,21 +230,21 @@ for item in state.to_remember:
230
230
 
231
231
  ```
232
232
  $ python3 example9.py
233
- INFO Processing item #1
234
- INFO - Element 1
233
+ INFO example9 Processing item #1
234
+ INFO example9 - Element 1
235
235
 
236
236
  $ python3 example9.py
237
- INFO Processing item #2
238
- INFO - Element 1
239
- INFO - Element 2
237
+ INFO example9 Processing item #2
238
+ INFO example9 - Element 1
239
+ INFO example9 - Element 2
240
240
 
241
241
  $ python3 example9.py
242
- INFO Processing item #3
243
- INFO - Element 2
244
- INFO - Element 3
242
+ INFO example9 Processing item #3
243
+ INFO example9 - Element 2
244
+ INFO example9 - Element 3
245
245
  ```
246
246
 
247
- ## Helps issue a warning only once
247
+ ## Helps issuing a warning only once
248
248
 
249
249
  [example10.py](https://github.com/presidento/scripthelper/blob/master/example10.py):
250
250
 
@@ -71,21 +71,21 @@ See [example9.py](example9.py)
71
71
 
72
72
  ```
73
73
  $ python3 example9.py
74
- INFO Processing item #1
75
- INFO - Element 1
74
+ INFO example9 Processing item #1
75
+ INFO example9 - Element 1
76
76
 
77
77
  $ python3 example9.py
78
- INFO Processing item #2
79
- INFO - Element 1
80
- INFO - Element 2
78
+ INFO example9 Processing item #2
79
+ INFO example9 - Element 1
80
+ INFO example9 - Element 2
81
81
 
82
82
  $ python3 example9.py
83
- INFO Processing item #3
84
- INFO - Element 2
85
- INFO - Element 3
83
+ INFO example9 Processing item #3
84
+ INFO example9 - Element 2
85
+ INFO example9 - Element 3
86
86
  ```
87
87
 
88
- ## Helps issue a warning only once
88
+ ## Helps issuing a warning only once
89
89
 
90
90
  See [example10.py](example10.py)
91
91
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  import scripthelper
3
3
 
4
- logger = scripthelper.getLogger(__name__)
4
+ logger = scripthelper.getLogger()
5
5
 
6
6
 
7
7
  def greet(name):
@@ -1,7 +1,7 @@
1
1
  set shell := ["nu", "-c"]
2
2
 
3
3
  DEFAULT_VERSION := "3.8"
4
- SUPPORTED_VERSIONS := "['3.8' '3.9' '3.10' '3.11' '3.12']"
4
+ SUPPORTED_VERSIONS := "['3.8' '3.9' '3.10' '3.11' '3.12' '3.13']"
5
5
  PYTHON_EXECUTABLE := if os_family() == "windows" { "Scripts/python.exe" } else { "bin/python3" }
6
6
  SYSTEM_PYTHON_PREFIX := if os_family() == "windows" { "py -" } else { "python" }
7
7
 
@@ -23,7 +23,7 @@ compile-readme:
23
23
 
24
24
  # Run a specific Python interpreter
25
25
  python VERSION *ARGS:
26
- @^".{{ VERSION }}.{{ os() }}.venv/{{ PYTHON_EXECUTABLE }}" {{ ARGS }}
26
+ @^".{{ VERSION }}.{{ os() }}.venv/{{ PYTHON_EXECUTABLE }}" -X dev {{ ARGS }}
27
27
 
28
28
  # Run python command with the default Python version
29
29
  py *ARGS:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "scripthelper"
3
- version = "23.4"
3
+ version = "24.1"
4
4
  description = "Helper module for creating simple Python scripts"
5
5
  readme = "README.compiled.md"
6
6
  license = {text = "MIT License"}
@@ -15,13 +15,13 @@ classifiers = [
15
15
  "Programming Language :: Python :: 3.10",
16
16
  "Programming Language :: Python :: 3.11",
17
17
  "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
18
19
  "Topic :: Utilities",
19
20
  "Typing :: Typed",
20
21
  ]
21
22
  dependencies = [
22
23
  "tqdm >= 4.31.1",
23
24
  "coloredlogs >= 10.0",
24
- "verboselogs >= 1.7",
25
25
  "stackprinter >= 0.2.10",
26
26
  "prettyprinter >= 0.18.0",
27
27
  "persistedstate >= 23.6",
@@ -19,14 +19,11 @@ import persistedstate
19
19
  import prettyprinter
20
20
  import stackprinter
21
21
  import tqdm
22
- import verboselogs
23
22
  from colorful import colorful # type: ignore
24
23
 
25
24
  _with_colors = None
26
25
  _with_traceback_variables = True
27
26
 
28
- logger = logging.getLogger(__name__)
29
-
30
27
  __all__ = [
31
28
  # Logging
32
29
  "getLogger",
@@ -59,9 +56,9 @@ CRITICAL = logging.CRITICAL
59
56
  ERROR = logging.ERROR
60
57
  WARNING = logging.WARNING
61
58
  INFO = logging.INFO
62
- VERBOSE = verboselogs.VERBOSE
59
+ VERBOSE = (logging.INFO + logging.DEBUG) // 2
63
60
  DEBUG = logging.DEBUG
64
- SPAM = verboselogs.SPAM
61
+ SPAM = logging.DEBUG // 2
65
62
  warn = warnings.warn
66
63
 
67
64
 
@@ -100,7 +97,9 @@ class ConsoleLogHandler(logging.StreamHandler):
100
97
  def __init__(self):
101
98
  logging.StreamHandler.__init__(self)
102
99
  self.setFormatter(
103
- CustomLogFormatter("%(levelname)s %(message)s", colors=_with_colors)
100
+ CustomLogFormatter(
101
+ "%(levelname)s %(name)s %(message)s", colors=_with_colors
102
+ )
104
103
  )
105
104
 
106
105
  def emit(self, record):
@@ -114,17 +113,36 @@ def _exception_handler(exc_type, exc_value, exc_traceback):
114
113
  return
115
114
 
116
115
  message = f"Uncaught {exc_type.__name__}: {exc_value}"
117
- logger.critical(message, exc_info=exc_value)
116
+ getLogger().critical(message, exc_info=exc_value)
117
+
118
+
119
+ class MoreLevelsLogger(logging.getLoggerClass()): # type: ignore
120
+ def __init__(self, *args, **kw):
121
+ logging.Logger.__init__(self, *args, **kw)
122
+ self.parent = logging.getLogger()
123
+
124
+ def spam(self, msg, *args, **kw):
125
+ if self.isEnabledFor(SPAM):
126
+ self._log(SPAM, msg, args, **kw, stacklevel=2)
127
+
128
+ def verbose(self, msg, *args, **kw):
129
+ if self.isEnabledFor(VERBOSE):
130
+ self._log(VERBOSE, msg, args, **kw, stacklevel=2)
118
131
 
119
132
 
120
133
  def _setup_logger(console_log_level):
121
134
  with warnings.catch_warnings():
122
135
  warnings.simplefilter("ignore")
123
136
  prettyprinter.install_extras()
124
- verboselogs.install()
137
+
138
+ logging.setLoggerClass(MoreLevelsLogger)
139
+ logging.addLevelName(VERBOSE, "VERBOSE")
140
+ logging.addLevelName(SPAM, "SPAM")
141
+
125
142
  if sys.platform == "win32":
126
143
  # In Windows the default black is black, which is invisible on the default terminal.
127
144
  coloredlogs.DEFAULT_FIELD_STYLES["levelname"] = {"color": "blue"}
145
+ coloredlogs.DEFAULT_FIELD_STYLES["name"] = {"color": "cyan", "faint": True}
128
146
 
129
147
  root_logger = logging.getLogger()
130
148
  root_logger.setLevel(min(console_log_level, logging.DEBUG))
@@ -139,14 +157,14 @@ def _setup_logger(console_log_level):
139
157
 
140
158
  def _log_level_from_verbosity(console_verbosity):
141
159
  levels = [
142
- logging.ERROR,
143
- logging.WARNING,
144
- logging.INFO,
145
- verboselogs.VERBOSE,
146
- logging.DEBUG,
147
- verboselogs.SPAM,
160
+ ERROR,
161
+ WARNING,
162
+ INFO,
163
+ VERBOSE,
164
+ DEBUG,
165
+ SPAM,
148
166
  ]
149
- default_level = logging.INFO
167
+ default_level = INFO
150
168
 
151
169
  new_index = levels.index(default_level) + console_verbosity
152
170
  new_index = max(0, min(len(levels) - 1, new_index))
@@ -157,14 +175,23 @@ def _log_level_from_verbosity(console_verbosity):
157
175
  ########################################################################################v
158
176
 
159
177
 
160
- def getLogger(name: str = "__main__") -> verboselogs.VerboseLogger:
178
+ def getLogger(name: Optional[str] = None) -> MoreLevelsLogger:
161
179
  """Return a verbose logger for a module
162
180
 
163
- It is an alias for verboselogs.VerboseLogger.
181
+ It is an alias for MoreLevelsLogger.
164
182
  Can be used as the logging.getLogger() method.
165
183
  Extends built-in logger with levels: verbose, spam
166
184
  """
167
- return verboselogs.VerboseLogger(name)
185
+ logger = MoreLevelsLogger(name)
186
+ if name is None:
187
+ caller_file = None
188
+ this_file = pathlib.Path(__file__).absolute()
189
+ for frame in inspect.stack():
190
+ caller_file = pathlib.Path(frame.filename).absolute()
191
+ if caller_file != this_file:
192
+ logger.name = caller_file.stem
193
+ break
194
+ return logger
168
195
 
169
196
 
170
197
  _WARNING_ONCE_CACHE = set()
@@ -177,7 +204,7 @@ def warning_once(msg, *args, **kwargs):
177
204
  if msg in _WARNING_ONCE_CACHE:
178
205
  return
179
206
  _WARNING_ONCE_CACHE.add(msg)
180
- logger.warning(msg, *args, **kwargs)
207
+ getLogger().warning(msg, *args, **kwargs)
181
208
 
182
209
 
183
210
  args: argparse.Namespace # Parsed arguments, will be set during bootstrap
@@ -233,7 +260,7 @@ def setup_file_logging(*, level: str = "INFO", filename: Optional[str] = None) -
233
260
  filename, encoding="utf-8", maxBytes=10 * 1024 * 1024, backupCount=9
234
261
  )
235
262
  formatter = CustomLogFormatter(
236
- "%(asctime)s %(levelname)s %(message)s", colors=False
263
+ "%(asctime)s %(levelname)s %(name)s %(message)s", colors=False
237
264
  )
238
265
  file_log_handler.setFormatter(formatter)
239
266
  file_log_handler.setLevel(level)
@@ -272,7 +299,7 @@ class PersistedState(persistedstate.PersistedState):
272
299
  return super().__init__(filename, **kwargs)
273
300
 
274
301
 
275
- def bootstrap_args() -> Tuple[verboselogs.VerboseLogger, argparse.Namespace]:
302
+ def bootstrap_args() -> Tuple[MoreLevelsLogger, argparse.Namespace]:
276
303
  """Bootstraps the framework
277
304
 
278
305
  returns (logger, args)
@@ -297,12 +324,12 @@ def bootstrap_args() -> Tuple[verboselogs.VerboseLogger, argparse.Namespace]:
297
324
  console_log_level = _log_level_from_verbosity(console_verbosity)
298
325
  _setup_logger(console_log_level)
299
326
 
327
+ logger = getLogger()
300
328
  logger.debug(f"Arguments: {args}")
301
-
302
- return getLogger(), args
329
+ return logger, args
303
330
 
304
331
 
305
- def bootstrap() -> verboselogs.VerboseLogger:
332
+ def bootstrap() -> MoreLevelsLogger:
306
333
  """Bootstraps the framework
307
334
 
308
335
  returns logger - the logger for the main script"""
@@ -9,7 +9,7 @@ import sys
9
9
  class TestExamples(unittest.TestCase):
10
10
  def assert_output(self, command, expected, subprocess_check=True):
11
11
  output = self.run_command(command, subprocess_check)
12
- self.assertEqual(output.strip(), expected.strip())
12
+ self.assertEqual(expected.strip(), output.strip())
13
13
 
14
14
  def run_command(self, command, subprocess_check=True):
15
15
  # Workaround for bug with Nushell, see https://github.com/python/cpython/issues/102496
@@ -37,10 +37,10 @@ class TestExamples(unittest.TestCase):
37
37
  "example1.py",
38
38
  textwrap.dedent(
39
39
  """
40
- CRITICAL critical message
41
- ERROR error message
42
- WARNING warning message
43
- INFO info message
40
+ CRITICAL example1 critical message
41
+ ERROR example1 error message
42
+ WARNING example1 warning message
43
+ INFO example1 info message
44
44
  """
45
45
  ),
46
46
  )
@@ -71,9 +71,9 @@ class TestExamples(unittest.TestCase):
71
71
  "example1.py -q",
72
72
  textwrap.dedent(
73
73
  """
74
- CRITICAL critical message
75
- ERROR error message
76
- WARNING warning message
74
+ CRITICAL example1 critical message
75
+ ERROR example1 error message
76
+ WARNING example1 warning message
77
77
  """
78
78
  ),
79
79
  )
@@ -83,8 +83,8 @@ class TestExamples(unittest.TestCase):
83
83
  "example1.py -qq",
84
84
  textwrap.dedent(
85
85
  """
86
- CRITICAL critical message
87
- ERROR error message
86
+ CRITICAL example1 critical message
87
+ ERROR example1 error message
88
88
  """
89
89
  ),
90
90
  )
@@ -94,8 +94,8 @@ class TestExamples(unittest.TestCase):
94
94
  "example1.py --quiet --quiet",
95
95
  textwrap.dedent(
96
96
  """
97
- CRITICAL critical message
98
- ERROR error message
97
+ CRITICAL example1 critical message
98
+ ERROR example1 error message
99
99
  """
100
100
  ),
101
101
  )
@@ -105,11 +105,11 @@ class TestExamples(unittest.TestCase):
105
105
  "example1.py -v",
106
106
  textwrap.dedent(
107
107
  """
108
- CRITICAL critical message
109
- ERROR error message
110
- WARNING warning message
111
- INFO info message
112
- VERBOSE verbose message
108
+ CRITICAL example1 critical message
109
+ ERROR example1 error message
110
+ WARNING example1 warning message
111
+ INFO example1 info message
112
+ VERBOSE example1 verbose message
113
113
  """
114
114
  ),
115
115
  )
@@ -117,18 +117,18 @@ class TestExamples(unittest.TestCase):
117
117
  def test_example1_with_2_verbose(self):
118
118
  expected = textwrap.dedent(
119
119
  """
120
- DEBUG Arguments: Namespace(verbose=2, quiet=None, colors=None, disable_traceback_variables=False)
121
- CRITICAL critical message
122
- ERROR error message
123
- WARNING warning message
124
- INFO info message
125
- VERBOSE verbose message
126
- DEBUG debug message
120
+ DEBUG example1 Arguments: Namespace(verbose=2, quiet=None, colors=None, disable_traceback_variables=False)
121
+ CRITICAL example1 critical message
122
+ ERROR example1 error message
123
+ WARNING example1 warning message
124
+ INFO example1 info message
125
+ VERBOSE example1 verbose message
126
+ DEBUG example1 debug message
127
127
  """
128
128
  ).strip()
129
129
  expected = self.change_namespace_for_python_lte_38(
130
130
  expected,
131
- "DEBUG Arguments: Namespace(colors=None, disable_traceback_variables=False, quiet=None, verbose=2)",
131
+ "DEBUG example1 Arguments: Namespace(colors=None, disable_traceback_variables=False, quiet=None, verbose=2)",
132
132
  )
133
133
 
134
134
  self.assert_output("example1.py -vv", expected)
@@ -136,19 +136,19 @@ class TestExamples(unittest.TestCase):
136
136
  def test_example1_with_3_verbose(self):
137
137
  expected = textwrap.dedent(
138
138
  """
139
- DEBUG Arguments: Namespace(verbose=3, quiet=None, colors=None, disable_traceback_variables=False)
140
- CRITICAL critical message
141
- ERROR error message
142
- WARNING warning message
143
- INFO info message
144
- VERBOSE verbose message
145
- DEBUG debug message
146
- SPAM spam message
139
+ DEBUG example1 Arguments: Namespace(verbose=3, quiet=None, colors=None, disable_traceback_variables=False)
140
+ CRITICAL example1 critical message
141
+ ERROR example1 error message
142
+ WARNING example1 warning message
143
+ INFO example1 info message
144
+ VERBOSE example1 verbose message
145
+ DEBUG example1 debug message
146
+ SPAM example1 spam message
147
147
  """
148
148
  ).strip()
149
149
  expected = self.change_namespace_for_python_lte_38(
150
150
  expected,
151
- "DEBUG Arguments: Namespace(colors=None, disable_traceback_variables=False, quiet=None, verbose=3)",
151
+ "DEBUG example1 Arguments: Namespace(colors=None, disable_traceback_variables=False, quiet=None, verbose=3)",
152
152
  )
153
153
 
154
154
  self.assert_output("example1.py -vvv", expected)
@@ -156,49 +156,49 @@ class TestExamples(unittest.TestCase):
156
156
  def test_example1_with_3_long_verbose(self):
157
157
  expected = textwrap.dedent(
158
158
  """
159
- DEBUG Arguments: Namespace(verbose=3, quiet=None, colors=None, disable_traceback_variables=False)
160
- CRITICAL critical message
161
- ERROR error message
162
- WARNING warning message
163
- INFO info message
164
- VERBOSE verbose message
165
- DEBUG debug message
166
- SPAM spam message
159
+ DEBUG example1 Arguments: Namespace(verbose=3, quiet=None, colors=None, disable_traceback_variables=False)
160
+ CRITICAL example1 critical message
161
+ ERROR example1 error message
162
+ WARNING example1 warning message
163
+ INFO example1 info message
164
+ VERBOSE example1 verbose message
165
+ DEBUG example1 debug message
166
+ SPAM example1 spam message
167
167
  """
168
168
  ).strip()
169
169
  expected = self.change_namespace_for_python_lte_38(
170
170
  expected,
171
- "DEBUG Arguments: Namespace(colors=None, disable_traceback_variables=False, quiet=None, verbose=3)",
171
+ "DEBUG example1 Arguments: Namespace(colors=None, disable_traceback_variables=False, quiet=None, verbose=3)",
172
172
  )
173
173
  self.assert_output("example1.py --verbose --verbose --verbose", expected)
174
174
 
175
175
  def test_example2_without_arguments(self):
176
- self.assert_output("example2.py", "WARNING Name was not provided")
176
+ self.assert_output("example2.py", "WARNING example2 Name was not provided")
177
177
 
178
178
  def test_example2_with_name_provided(self):
179
- self.assert_output("example2.py --name World", "INFO Hello World")
179
+ self.assert_output("example2.py --name World", "INFO example2 Hello World")
180
180
 
181
181
  def test_example2b_with_name_provided(self):
182
- self.assert_output("example2b.py --name Nation", "INFO Hello Nation")
182
+ self.assert_output("example2b.py --name Nation", "INFO example2b Hello Nation")
183
183
 
184
184
  def test_example3(self):
185
185
  self.assert_output(
186
186
  "example3.py -v",
187
187
  textwrap.dedent(
188
188
  """
189
- INFO Doing the calculations...
190
- VERBOSE Iteration 0
191
- VERBOSE Iteration 20
192
- VERBOSE Iteration 40
193
- VERBOSE Iteration 60
194
- VERBOSE Iteration 80
195
- INFO Done
189
+ INFO example3 Doing the calculations...
190
+ VERBOSE example3 Iteration 0
191
+ VERBOSE example3 Iteration 20
192
+ VERBOSE example3 Iteration 40
193
+ VERBOSE example3 Iteration 60
194
+ VERBOSE example3 Iteration 80
195
+ INFO example3 Done
196
196
  """
197
197
  ),
198
198
  )
199
199
 
200
200
  def test_example4(self):
201
- self.assert_output("example4.py", "INFO Hello from a module.")
201
+ self.assert_output("example4.py", "INFO example4module Hello from a module.")
202
202
 
203
203
  def test_example5(self):
204
204
  log_file = pathlib.Path("example5.log")
@@ -221,10 +221,10 @@ class TestExamples(unittest.TestCase):
221
221
  dates_removed,
222
222
  textwrap.dedent(
223
223
  """
224
- CRITICAL critical message
225
- ERROR error message
226
- WARNING warning message
227
- INFO info message
224
+ CRITICAL example5 critical message
225
+ ERROR example5 error message
226
+ WARNING example5 warning message
227
+ INFO example5 info message
228
228
  """
229
229
  ).strip(),
230
230
  )
@@ -278,8 +278,8 @@ class TestExamples(unittest.TestCase):
278
278
  "example9.py",
279
279
  textwrap.dedent(
280
280
  """
281
- INFO Processing item #1
282
- INFO - Element 1
281
+ INFO example9 Processing item #1
282
+ INFO example9 - Element 1
283
283
  """
284
284
  ),
285
285
  )
@@ -287,9 +287,9 @@ class TestExamples(unittest.TestCase):
287
287
  "example9.py",
288
288
  textwrap.dedent(
289
289
  """
290
- INFO Processing item #2
291
- INFO - Element 1
292
- INFO - Element 2
290
+ INFO example9 Processing item #2
291
+ INFO example9 - Element 1
292
+ INFO example9 - Element 2
293
293
  """
294
294
  ),
295
295
  )
@@ -297,23 +297,23 @@ class TestExamples(unittest.TestCase):
297
297
  "example9.py",
298
298
  textwrap.dedent(
299
299
  """
300
- INFO Processing item #3
301
- INFO - Element 2
302
- INFO - Element 3
300
+ INFO example9 Processing item #3
301
+ INFO example9 - Element 2
302
+ INFO example9 - Element 3
303
303
  """
304
304
  ),
305
305
  )
306
306
 
307
307
  @staticmethod
308
308
  def change_namespace_for_python_lte_38(original, replacement):
309
- if sys.version_info.minor > 8:
310
- return original
311
- lines = original.splitlines()
312
- lines[0] = replacement
313
- return "\n".join(lines)
309
+ if sys.version_info.minor <= 8:
310
+ lines = original.splitlines()
311
+ lines[0] = replacement
312
+ return "\n".join(lines)
313
+ return original
314
314
 
315
315
  def test_example10(self):
316
- self.assert_output("example10.py", "WARNING Item #12 has some errors")
316
+ self.assert_output("example10.py", "WARNING example10 Item #12 has some errors")
317
317
 
318
318
 
319
319
  if __name__ == "__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