python-ubercode-utils 2.0.6__tar.gz → 2.0.7__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 (27) hide show
  1. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/PKG-INFO +1 -1
  2. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/python_ubercode_utils.egg-info/PKG-INFO +1 -1
  3. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/setup.py +1 -1
  4. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/test/test_convert.py +3 -1
  5. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/test/test_environment.py +8 -2
  6. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/utils/environment.py +19 -9
  7. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/LICENSE +0 -0
  8. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/MANIFEST.in +0 -0
  9. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/README.md +0 -0
  10. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/python_ubercode_utils.egg-info/SOURCES.txt +0 -0
  11. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/python_ubercode_utils.egg-info/dependency_links.txt +0 -0
  12. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/python_ubercode_utils.egg-info/not-zip-safe +0 -0
  13. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/python_ubercode_utils.egg-info/top_level.txt +0 -0
  14. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/setup.cfg +0 -0
  15. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/test/test_cursor.py +0 -0
  16. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/test/test_data.py +0 -0
  17. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/test/test_dataframe.py +0 -0
  18. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/test/test_logging.py +0 -0
  19. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/test/test_urls.py +0 -0
  20. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/__init__.py +0 -0
  21. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/utils/__init__.py +0 -0
  22. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/utils/convert.py +0 -0
  23. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/utils/cursor.py +0 -0
  24. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/utils/data.py +0 -0
  25. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/utils/dataframe.py +0 -0
  26. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/utils/logging.py +0 -0
  27. {python_ubercode_utils-2.0.6 → python_ubercode_utils-2.0.7}/ubercode/utils/urls.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python_ubercode_utils
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: Core python utilities for all apps
5
5
  Home-page: https://github.com/sstacha/python-ubercode-utils
6
6
  Author: Steve Stacha
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-ubercode-utils
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: Core python utilities for all apps
5
5
  Home-page: https://github.com/sstacha/python-ubercode-utils
6
6
  Author: Steve Stacha
@@ -4,7 +4,7 @@ with open("README.md", "r") as fh:
4
4
  long_description = fh.read()
5
5
 
6
6
  setuptools.setup(name='python_ubercode_utils',
7
- version='2.0.6',
7
+ version='2.0.7',
8
8
  description='Core python utilities for all apps',
9
9
  long_description=long_description,
10
10
  long_description_content_type="text/markdown",
@@ -174,7 +174,9 @@ class TestConvert(unittest.TestCase):
174
174
  # None returns None if we have the none_to_now set to false instead of new datetime
175
175
  self.assertEqual(None, convert.to_date(None, none_to_now=False))
176
176
  # note: to_date always returns a datetime use the date() function to compare just the date parts
177
- self.assertEqual(now.date(), now_convert.date())
177
+ # todo: fix! this doesn't work late at night since the hours = the next day from america/chicago -> utc after 6pm.
178
+ # AssertionError: datetime.date(2026, 3, 3) != datetime.date(2026, 3, 4)
179
+ # self.assertEqual(now.date(), now_convert.date())
178
180
  # if we convert both to local timezone and ignore microseconds they should be the same
179
181
  now_local = now.astimezone()
180
182
  now_convert_local = now_convert.astimezone()
@@ -25,6 +25,12 @@ class TestEnvironment(unittest.TestCase):
25
25
  self.assertEqual(var, False)
26
26
  var = environment.override_variable("OVERRIDE_DEBUG", True)
27
27
  self.assertEqual(var, False)
28
+ # test implicit 'True', 'False' conversions with no default value; like we would get from os passed env
29
+ var = environment.override_variable("OVERRIDE_DEBUG")
30
+ self.assertEqual(var, False)
31
+ # test explict override
32
+ var = environment.override_variable("OVERRIDE_DEBUG", data_type='str')
33
+ self.assertEqual(var, 'False')
28
34
  # test int conversion
29
35
  var = environment.override_variable("TEST_INT", 0)
30
36
  self.assertEqual(var, 1)
@@ -53,14 +59,14 @@ class TestEnvironment(unittest.TestCase):
53
59
  with redirect_stdout(StringIO()) as sout:
54
60
  var = environment.override_variable("PW", "test_password")
55
61
  log_output = sout.getvalue()
56
- self.assertEqual(log_output, "\x1b[94moverriding PW: [tes*******ord] to [ab******ef]\x1b[0m\n")
62
+ self.assertEqual(log_output, "\x1b[94moverriding PW [<class 'str'>]: [tes*******ord] to [ab******ef]\x1b[0m\n")
57
63
  # ensure the return value is the full password
58
64
  self.assertEqual(var, "abc1234def")
59
65
  # test masked if we tell it to mask
60
66
  with redirect_stdout(StringIO()) as sout:
61
67
  environment.override_variable("TEST_STRING", None, mask_log=True)
62
68
  log_output = sout.getvalue()
63
- self.assertEqual(log_output, "\x1b[94moverriding TEST_STRING: [None] to [ab******ef]\x1b[0m\n")
69
+ self.assertEqual(log_output, "\x1b[94moverriding TEST_STRING [<class 'str'>]: [None] to [ab******ef]\x1b[0m\n")
64
70
 
65
71
  def test_override_database_variables(self):
66
72
  # we will start with the default dict for a new django install
@@ -71,16 +71,26 @@ class Environment:
71
71
  self._env_map = environment_variable_map
72
72
 
73
73
  @staticmethod
74
- def infer_data_type(value):
75
- if value is not None:
76
- if isinstance(value, bool):
74
+ def infer_data_type(default_value: Any, env_value: Any) -> str:
75
+ if default_value is not None:
76
+ if isinstance(default_value, bool):
77
77
  return 'bool'
78
- if isinstance(value, str):
79
- return 'str'
80
- if isinstance(value, int):
78
+ if isinstance(default_value, int):
81
79
  return 'int'
82
- if isinstance(value, datetime):
80
+ if isinstance(default_value, datetime):
83
81
  return 'date'
82
+ if isinstance(default_value, str):
83
+ return 'str'
84
+ else:
85
+ # NOTE: all env vals are sent as strings so 'True', 'False' with no settings var will be str not bool
86
+ # considering inferring that it is python boolean if True,False with caps. Will not do lower for
87
+ # js type true,false we want to pass through as strings lower case in a template; trying not to
88
+ # infer too much.
89
+ if env_value is not None and isinstance(env_value, str) and env_value.strip() in ('True', 'False'):
90
+ return 'bool'
91
+ # NOTE: we may want to look at some common date/time patters to infer date as well; but bool is
92
+ # important because things like DEBUG=False will evaluate as True if overridden right now without
93
+ # the variable being first initialized to something in the settings file.
84
94
  return 'str'
85
95
 
86
96
  def override_variable(self, variable_name: str, default_value: Any = None, environment_variable_name: str = None,
@@ -113,7 +123,7 @@ class Environment:
113
123
  if _env_value is not None:
114
124
  if data_type is None or data_type not in self.VARIABLE_DATA_TYPES:
115
125
  # infer type from default value
116
- data_type = self.infer_data_type(default_value)
126
+ data_type = self.infer_data_type(default_value, _env_value)
117
127
  # attempt to convert to datatype if not str
118
128
  if data_type == 'bool':
119
129
  _env_value = convert.to_bool(_env_value)
@@ -128,7 +138,7 @@ class Environment:
128
138
  _log_value = convert.to_mask(_env_value)
129
139
  if _log_from_value != "None":
130
140
  _log_from_value = convert.to_mask(_log_from_value)
131
- self._logger.info(f'overriding {variable_name}: [{str(_log_from_value)}] to [{str(_log_value)}]')
141
+ self._logger.info(f'overriding {variable_name} [{type(_env_value)}]: [{str(_log_from_value)}] to [{str(_log_value)}]')
132
142
  return _env_value
133
143
  return default_value
134
144