Skip to content

Commit c27ac59

Browse files
committed
Use Warning classes not ignored by default filters
This patch addresses a now-resolved curiosity where `DeprecationWarning`s were not being visibly raised when intentionally triggered in an application. They turn out to be ignored by default. `UserWarning`s were also not displaying by default, so this patch designates some of the erroneous behaviors not intended to cause halts as `RuntimeWarning`s. This patch also adds the expected environment variable name to a docstring visible in the command-line help() interface. References: * https://docs.python.org/3/library/warnings.html Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent 9b78310 commit c27ac59

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

case_utils/local_uuid.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def configure() -> None:
3838
if os.getenv("DEMO_UUID_REQUESTING_NONRANDOM") == "NONRANDOM_REQUESTED":
3939
warnings.warn(
4040
"Environment variable DEMO_UUID_REQUESTING_NONRANDOM is deprecated. See case_utils.local_uuid.demo_uuid for usage notes on its replacement, CASE_DEMO_NONRANDOM_UUID_BASE. Proceeding with random UUIDs.",
41-
DeprecationWarning,
41+
FutureWarning,
4242
)
4343
return
4444

@@ -49,12 +49,14 @@ def configure() -> None:
4949
base_dir_original_path = pathlib.Path(env_base_dir_name)
5050
if not base_dir_original_path.exists():
5151
warnings.warn(
52-
"Environment variable CASE_DEMO_NONRANDOM_UUID_BASE is expected to refer to an existing directory. Proceeding with random UUIDs."
52+
"Environment variable CASE_DEMO_NONRANDOM_UUID_BASE is expected to refer to an existing directory. Proceeding with random UUIDs.",
53+
RuntimeWarning,
5354
)
5455
return
5556
if not base_dir_original_path.is_dir():
5657
warnings.warn(
57-
"Environment variable CASE_DEMO_NONRANDOM_UUID_BASE is expected to refer to a directory. Proceeding with random UUIDs."
58+
"Environment variable CASE_DEMO_NONRANDOM_UUID_BASE is expected to refer to a directory. Proceeding with random UUIDs.",
59+
RuntimeWarning,
5860
)
5961
return
6062

@@ -108,9 +110,9 @@ def demo_uuid() -> str:
108110
"""
109111
This function generates a repeatable UUID, drawing on non-varying elements of the environment and process call for entropy.
110112
111-
WARNING: This function was developed for use ONLY for reducing (but not eliminating) version-control edits to identifiers in sample data. It creates UUIDs that are decidedly NOT random, and should remain consistent on repeated calls to the importing script.
113+
WARNING: This function was developed for use ONLY for reducing (but not eliminating) version-control edits to identifiers when generating sample data. It creates UUIDs that are decidedly NOT random, and should remain consistent on repeated calls to the importing script.
112114
113-
To prevent accidental non-random UUID usage, an environment variable must be set to a string provided by the caller. The variable's required value is the path to some directory. The variable's recommended value is the equivalent of the Make variable "top_srcdir" - that is, the root directory of the containing Git repository, some parent of the current process's current working directory.
115+
To prevent accidental non-random UUID usage, an environment variable, CASE_DEMO_NONRANDOM_UUID_BASE, must be set to a string provided by the caller. The variable's required value is the path to some directory. The variable's recommended value is the equivalent of the Make variable "top_srcdir" - that is, the root directory of the containing Git repository, some parent of the current process's current working directory.
114116
"""
115117
global DEMO_UUID_BASE
116118
global DEMO_UUID_COUNTER

0 commit comments

Comments
 (0)