encommon 0.7.5__py3-none-any.whl → 0.8.0__py3-none-any.whl

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 (53) hide show
  1. encommon/config/__init__.py +4 -0
  2. encommon/config/common.py +18 -14
  3. encommon/config/config.py +8 -5
  4. encommon/config/files.py +13 -7
  5. encommon/config/logger.py +94 -88
  6. encommon/config/params.py +1 -1
  7. encommon/config/paths.py +16 -8
  8. encommon/config/test/test_common.py +27 -4
  9. encommon/config/test/test_config.py +48 -82
  10. encommon/config/test/test_files.py +58 -43
  11. encommon/config/test/test_logger.py +129 -82
  12. encommon/config/test/test_paths.py +70 -30
  13. encommon/conftest.py +52 -12
  14. encommon/crypts/__init__.py +2 -0
  15. encommon/crypts/crypts.py +3 -1
  16. encommon/crypts/hashes.py +2 -2
  17. encommon/crypts/test/test_crypts.py +50 -28
  18. encommon/crypts/test/test_hashes.py +20 -18
  19. encommon/times/__init__.py +2 -0
  20. encommon/times/common.py +99 -15
  21. encommon/times/duration.py +50 -36
  22. encommon/times/parse.py +13 -25
  23. encommon/times/test/test_common.py +47 -16
  24. encommon/times/test/test_duration.py +104 -79
  25. encommon/times/test/test_parse.py +53 -63
  26. encommon/times/test/test_timers.py +90 -36
  27. encommon/times/test/test_times.py +21 -30
  28. encommon/times/test/test_window.py +73 -21
  29. encommon/times/timers.py +91 -58
  30. encommon/times/times.py +36 -34
  31. encommon/times/window.py +4 -4
  32. encommon/types/dicts.py +10 -4
  33. encommon/types/empty.py +7 -2
  34. encommon/types/strings.py +10 -0
  35. encommon/types/test/test_dicts.py +5 -5
  36. encommon/types/test/test_empty.py +4 -1
  37. encommon/types/test/test_strings.py +1 -1
  38. encommon/utils/__init__.py +4 -0
  39. encommon/utils/common.py +51 -6
  40. encommon/utils/match.py +1 -0
  41. encommon/utils/paths.py +42 -23
  42. encommon/utils/sample.py +30 -26
  43. encommon/utils/stdout.py +28 -17
  44. encommon/utils/test/test_common.py +35 -0
  45. encommon/utils/test/test_paths.py +3 -2
  46. encommon/utils/test/test_sample.py +28 -12
  47. encommon/version.txt +1 -1
  48. {encommon-0.7.5.dist-info → encommon-0.8.0.dist-info}/METADATA +1 -1
  49. encommon-0.8.0.dist-info/RECORD +63 -0
  50. encommon-0.7.5.dist-info/RECORD +0 -62
  51. {encommon-0.7.5.dist-info → encommon-0.8.0.dist-info}/LICENSE +0 -0
  52. {encommon-0.7.5.dist-info → encommon-0.8.0.dist-info}/WHEEL +0 -0
  53. {encommon-0.7.5.dist-info → encommon-0.8.0.dist-info}/top_level.txt +0 -0
@@ -10,7 +10,6 @@ is permitted, for more information consult the project license file.
10
10
  from datetime import timedelta
11
11
 
12
12
  from pytest import mark
13
- from pytest import raises
14
13
 
15
14
  from ..common import utcdatetime
16
15
  from ..parse import parse_time
@@ -25,85 +24,67 @@ def test_parse_time() -> None:
25
24
  Perform various tests associated with relevant routines.
26
25
  """
27
26
 
28
- utcnow = utcdatetime()
27
+ dtime = utcdatetime()
29
28
  delta = timedelta(seconds=1)
30
29
 
31
30
 
32
- dtime = parse_time(
31
+ parsed = parse_time(
33
32
  '1/1/1970 6:00am')
34
33
 
35
- assert dtime.year == 1970
36
- assert dtime.month == 1
37
- assert dtime.day == 1
38
- assert dtime.hour == 6
34
+ assert parsed.year == 1970
35
+ assert parsed.month == 1
36
+ assert parsed.day == 1
37
+ assert parsed.hour == 6
39
38
 
40
39
 
41
- dtime = parse_time(
40
+ parsed = parse_time(
42
41
  '12/31/1969 6:00pm',
43
42
  tzname='US/Central')
44
43
 
45
- assert dtime.year == 1970
46
- assert dtime.month == 1
47
- assert dtime.day == 1
48
- assert dtime.hour == 0
44
+ assert parsed.year == 1970
45
+ assert parsed.month == 1
46
+ assert parsed.day == 1
47
+ assert parsed.hour == 0
49
48
 
50
49
 
51
- dtime = parse_time(0)
52
- assert dtime.year == 1970
50
+ parsed = parse_time(0)
51
+ assert parsed.year == 1970
53
52
 
54
- dtime = parse_time('0')
55
- assert dtime.year == 1970
53
+ parsed = parse_time('0')
54
+ assert parsed.year == 1970
56
55
 
57
56
 
58
- dtime = parse_time('max')
57
+ parsed = parse_time('max')
59
58
 
60
- assert dtime.year == 9999
61
- assert dtime.month == 12
62
- assert dtime.day == 31
63
- assert dtime.hour == 23
59
+ assert parsed.year == 9999
60
+ assert parsed.month == 12
61
+ assert parsed.day == 31
62
+ assert parsed.hour == 23
64
63
 
65
- dtime = parse_time('min')
64
+ parsed = parse_time('min')
66
65
 
67
- assert dtime.year == 1
68
- assert dtime.month == 1
69
- assert dtime.day == 1
70
- assert dtime.hour == 0
66
+ assert parsed.year == 1
67
+ assert parsed.month == 1
68
+ assert parsed.day == 1
69
+ assert parsed.hour == 0
71
70
 
72
71
 
73
- dtime = parse_time('now')
74
- assert dtime - utcnow <= delta
72
+ parsed = parse_time('now')
73
+ assert parsed - dtime <= delta
75
74
 
76
- dtime = parse_time(None)
77
- assert dtime - utcnow <= delta
75
+ parsed = parse_time(None)
76
+ assert parsed - dtime <= delta
78
77
 
79
- dtime = parse_time('None')
80
- assert dtime - utcnow <= delta
78
+ parsed = parse_time('None')
79
+ assert parsed - dtime <= delta
81
80
 
82
81
 
83
- dtime = parse_time('+1y')
84
- assert dtime - utcnow > delta
82
+ parsed = parse_time('+1y')
83
+ assert parsed - dtime > delta
85
84
 
86
85
 
87
- assert parse_time(dtime) == dtime
88
-
89
-
90
-
91
- def test_parse_time_raises() -> None:
92
- """
93
- Perform various tests associated with relevant routines.
94
- """
95
-
96
-
97
- with raises(ValueError) as reason:
98
- parse_time(0, tzname='foo/bar')
99
-
100
- assert str(reason.value) == 'tzname'
101
-
102
-
103
- with raises(ValueError) as reason:
104
- parse_time(parse_time) # type: ignore
105
-
106
- assert str(reason.value) == 'source'
86
+ _parsed = parse_time(parsed)
87
+ assert _parsed == parsed
107
88
 
108
89
 
109
90
 
@@ -145,10 +126,11 @@ def test_shift_time(
145
126
  """
146
127
 
147
128
  anchor = utcdatetime(1980, 1, 1)
129
+ dtime = utcdatetime(*expect)
148
130
 
149
131
  parsed = shift_time(notate, anchor)
150
132
 
151
- assert parsed == utcdatetime(*expect)
133
+ assert parsed == dtime
152
134
 
153
135
 
154
136
 
@@ -162,26 +144,32 @@ def test_string_time() -> None:
162
144
 
163
145
  strings = [
164
146
  '1980-01-01T00:00:00Z',
147
+ '1980-01-01T00:00:00 +0000',
165
148
  '1980-01-01T00:00:00',
166
149
  '1980-01-01 00:00:00 +0000',
167
150
  '1980-01-01 00:00:00']
168
151
 
169
152
  for string in strings:
170
- assert string_time(string) == expect
153
+
154
+ parsed = string_time(string)
155
+
156
+ assert parsed == expect
171
157
 
172
158
 
173
159
  parsed = string_time(
174
160
  '1980_01_01',
175
- formats=['%Y', '%Y_%m_%d'])
161
+ formats=['%Y_%m_%d'])
176
162
 
177
163
  assert parsed == expect
178
164
 
165
+
179
166
  parsed = string_time(
180
167
  '1980_01_01',
181
168
  formats='%Y_%m_%d')
182
169
 
183
170
  assert parsed == expect
184
171
 
172
+
185
173
  parsed = string_time(
186
174
  '1979-12-31 18:00:00',
187
175
  tzname='US/Central')
@@ -196,13 +184,15 @@ def test_since_time() -> None:
196
184
  """
197
185
 
198
186
 
199
- dtime = shift_time('-1s')
187
+ parsed = shift_time('-1s')
188
+ since = since_time(parsed)
200
189
 
201
- assert since_time(dtime) >= 1
202
- assert since_time(dtime) < 2
190
+ assert since >= 1
191
+ assert since < 2
203
192
 
204
193
 
205
- dtime = shift_time('+1s')
194
+ parsed = shift_time('+1s')
195
+ since = since_time(parsed)
206
196
 
207
- assert since_time(dtime) > 0
208
- assert since_time(dtime) < 2
197
+ assert since > 0
198
+ assert since < 2
@@ -10,110 +10,164 @@ is permitted, for more information consult the project license file.
10
10
  from pathlib import Path
11
11
  from time import sleep
12
12
 
13
+ from pytest import fixture
13
14
  from pytest import raises
14
15
 
15
16
  from ..timers import Timers
16
17
 
17
18
 
18
19
 
19
- def test_Timers() -> None:
20
+ @fixture
21
+ def timers(
22
+ tmp_path: Path,
23
+ ) -> Timers:
24
+ """
25
+ Construct the instance for use in the downstream tests.
26
+
27
+ :param tmp_path: pytest object for temporal filesystem.
28
+ :returns: Newly constructed instance of related class.
29
+ """
30
+
31
+ return Timers(
32
+ timers={'one': 1},
33
+ file=f'{tmp_path}/cache.db')
34
+
35
+
36
+
37
+ def test_Timers(
38
+ timers: Timers,
39
+ ) -> None:
20
40
  """
21
41
  Perform various tests associated with relevant routines.
42
+
43
+ :param timers: Primary class instance for timers object.
22
44
  """
23
45
 
24
- timers = Timers({'one': 1})
25
46
 
26
47
  attrs = list(timers.__dict__)
27
48
 
28
49
  assert attrs == [
29
- '_Timers__timers',
30
- '_Timers__cache_file',
31
- '_Timers__cache_name',
32
- '_Timers__cache_dict']
50
+ '_Timers__config',
51
+ '_Timers__sqlite',
52
+ '_Timers__file',
53
+ '_Timers__table',
54
+ '_Timers__cache']
55
+
56
+
57
+ assert repr(timers)[:22] == (
58
+ '<encommon.times.timers')
33
59
 
60
+ assert hash(timers) > 0
34
61
 
35
- assert repr(timers).startswith(
36
- '<encommon.times.timers.Timers')
37
- assert isinstance(hash(timers), int)
38
- assert str(timers).startswith(
39
- '<encommon.times.timers.Timers')
62
+ assert str(timers)[:22] == (
63
+ '<encommon.times.timers')
40
64
 
41
65
 
42
66
  assert timers.timers == {'one': 1}
43
- assert timers.cache_file is not None
44
- assert len(timers.cache_dict) == 1
45
- assert timers.cache_name is not None
67
+
68
+ assert timers.sqlite is not None
69
+
70
+ assert timers.file[-8:] == 'cache.db'
71
+
72
+ assert timers.table == 'timers'
73
+
74
+ assert list(timers.cache) == ['one']
75
+
76
+
77
+
78
+ def test_Timers_cover(
79
+ timers: Timers,
80
+ ) -> None:
81
+ """
82
+ Perform various tests associated with relevant routines.
83
+
84
+ :param timers: Primary class instance for timers object.
85
+ """
46
86
 
47
87
 
48
88
  assert not timers.ready('one')
89
+
49
90
  sleep(1.1)
91
+
50
92
  assert timers.ready('one')
51
93
 
52
94
 
53
95
  timers.create('two', 2, 0)
54
96
 
55
97
  assert timers.ready('two')
98
+
56
99
  assert not timers.ready('two')
57
100
 
58
101
 
59
102
 
60
103
  def test_Timers_cache(
61
- tmp_path: Path,
104
+ timers: Timers,
62
105
  ) -> None:
63
106
  """
64
107
  Perform various tests associated with relevant routines.
65
108
 
66
- :param tmp_path: pytest object for temporal filesystem.
109
+ :param timers: Primary class instance for timers object.
67
110
  """
68
111
 
69
- cache_file = (
70
- f'{tmp_path}/timers.db')
71
-
72
112
  timers1 = Timers(
73
- timers={'one': 1},
74
- cache_file=cache_file)
113
+ timers={'uno': 1},
114
+ file=timers.file)
75
115
 
76
- assert not timers1.ready('one')
116
+ assert not timers1.ready('uno')
77
117
 
78
118
  sleep(0.75)
79
119
 
80
120
  timers2 = Timers(
81
- timers={'one': 1},
82
- cache_file=cache_file)
121
+ timers={'uno': 1},
122
+ file=timers.file)
83
123
 
84
- assert not timers1.ready('one')
85
- assert not timers2.ready('one')
124
+ assert not timers1.ready('uno')
125
+ assert not timers2.ready('uno')
86
126
 
87
127
  sleep(0.25)
88
128
 
89
129
  timers2.load_cache()
90
130
 
91
- assert timers1.ready('one')
92
- assert timers2.ready('one')
131
+ assert timers1.ready('uno')
132
+ assert timers2.ready('uno')
93
133
 
94
134
 
95
135
 
96
- def test_Timers_raises() -> None:
136
+ def test_Timers_raises(
137
+ timers: Timers,
138
+ ) -> None:
97
139
  """
98
140
  Perform various tests associated with relevant routines.
141
+
142
+ :param timers: Primary class instance for timers object.
99
143
  """
100
144
 
101
- timers = Timers({'one': 1})
102
145
 
146
+ _raises = raises(ValueError)
103
147
 
104
- with raises(ValueError) as reason:
148
+ with _raises as reason:
105
149
  timers.ready('dne')
106
150
 
107
- assert str(reason.value) == 'unique'
151
+ _reason = str(reason.value)
108
152
 
153
+ assert _reason == 'unique'
109
154
 
110
- with raises(ValueError) as reason:
155
+
156
+ _raises = raises(ValueError)
157
+
158
+ with _raises as reason:
111
159
  timers.update('dne')
112
160
 
113
- assert str(reason.value) == 'unique'
161
+ _reason = str(reason.value)
162
+
163
+ assert _reason == 'unique'
114
164
 
115
165
 
116
- with raises(ValueError) as reason:
166
+ _raises = raises(ValueError)
167
+
168
+ with _raises as reason:
117
169
  timers.create('one', 1)
118
170
 
119
- assert str(reason.value) == 'unique'
171
+ _reason = str(reason.value)
172
+
173
+ assert _reason == 'unique'
@@ -7,8 +7,6 @@ is permitted, for more information consult the project license file.
7
7
 
8
8
 
9
9
 
10
- from pytest import raises
11
-
12
10
  from ..common import STAMP_SIMPLE
13
11
  from ..common import UNIXEPOCH
14
12
  from ..common import UNIXHPOCH
@@ -22,21 +20,25 @@ def test_Times() -> None:
22
20
  Perform various tests associated with relevant routines.
23
21
  """
24
22
 
25
- times = Times(0, format=STAMP_SIMPLE)
23
+ times = Times(
24
+ UNIXEPOCH,
25
+ format=STAMP_SIMPLE)
26
+
26
27
 
27
28
  attrs = list(times.__dict__)
28
29
 
29
30
  assert attrs == [
30
- '_Times__source']
31
+ '_Times__source',
32
+ '_Times__hashed']
33
+
31
34
 
35
+ assert repr(times)[:23] == (
36
+ "Times('1970-01-01T00:00")
32
37
 
33
- assert repr(times) == (
34
- "Times('1970-01-01T"
35
- "00:00:00.000000+0000')")
36
- assert isinstance(hash(times), int)
37
- assert str(times) == (
38
- '1970-01-01T00:00:00'
39
- '.000000+0000')
38
+ assert hash(times) > 0
39
+
40
+ assert str(times)[:23] == (
41
+ '1970-01-01T00:00:00.000')
40
42
 
41
43
 
42
44
  assert int(times) == 0
@@ -58,37 +60,26 @@ def test_Times() -> None:
58
60
  assert times.source.year == 1970
59
61
 
60
62
  assert times.epoch == 0.0
63
+
61
64
  assert times.mpoch == 0.0
65
+
62
66
  assert times.simple == UNIXEPOCH
67
+
63
68
  assert times.subsec == UNIXMPOCH
69
+
64
70
  assert times.human == UNIXHPOCH
71
+
65
72
  assert times.elapsed >= 1672531200
73
+
66
74
  assert times.since >= 1672531200
67
75
 
68
76
  assert times.before == (
69
77
  '1969-12-31T23:59:59.999999Z')
78
+
70
79
  assert times.after == (
71
80
  '1970-01-01T00:00:00.000001Z')
72
81
 
73
- stamp = times.stamp(
74
- tzname='US/Central')
75
-
76
- assert stamp[:4] == '1969'
77
- assert stamp[11:][:2] == '18'
78
-
82
+ assert times.stamp() == UNIXMPOCH
79
83
 
80
84
  times = times.shift('+1y')
81
-
82
85
  assert times == '1971-01-01'
83
-
84
-
85
-
86
- def test_Times_raises() -> None:
87
- """
88
- Perform various tests associated with relevant routines.
89
- """
90
-
91
- with raises(ValueError) as reason:
92
- Times(0).stamp(tzname='foo')
93
-
94
- assert str(reason.value) == 'tzname'
@@ -7,21 +7,43 @@ is permitted, for more information consult the project license file.
7
7
 
8
8
 
9
9
 
10
+ from typing import TYPE_CHECKING
11
+
12
+ from pytest import fixture
10
13
  from pytest import mark
11
14
 
12
- from ..common import PARSABLE
13
15
  from ..window import Window
14
16
  from ..window import window_croniter
15
17
  from ..window import window_interval
16
18
 
19
+ if TYPE_CHECKING:
20
+ from ..common import PARSABLE
21
+
22
+
23
+
24
+ @fixture
25
+ def window() -> Window:
26
+ """
27
+ Construct the instance for use in the downstream tests.
28
+
29
+ :returns: Newly constructed instance of related class.
30
+ """
31
+
32
+ return Window(
33
+ schedule='* * * * *',
34
+ start=330, stop=630)
17
35
 
18
36
 
19
- def test_Window() -> None:
37
+
38
+ def test_Window(
39
+ window: Window,
40
+ ) -> None:
20
41
  """
21
42
  Perform various tests associated with relevant routines.
43
+
44
+ :param window: Primary class instance for window object.
22
45
  """
23
46
 
24
- window = Window('* * * * *', 330, 630)
25
47
 
26
48
  attrs = list(window.__dict__)
27
49
 
@@ -36,23 +58,52 @@ def test_Window() -> None:
36
58
  '_Window__walked']
37
59
 
38
60
 
39
- assert repr(window).startswith(
40
- '<encommon.times.window.Window')
41
- assert isinstance(hash(window), int)
42
- assert str(window).startswith(
43
- '<encommon.times.window.Window')
61
+ assert repr(window)[:22] == (
62
+ '<encommon.times.window')
63
+
64
+ assert hash(window) > 0
65
+
66
+ assert str(window)[:22] == (
67
+ '<encommon.times.window')
44
68
 
45
69
 
46
70
  assert window.schedule == '* * * * *'
71
+
47
72
  assert window.start == '1970-01-01T00:05:30Z'
73
+
48
74
  assert window.stop == '1970-01-01T00:10:30Z'
75
+
49
76
  assert window.anchor == window.start
77
+
50
78
  assert window.delay == 0.0
79
+
51
80
  assert window.last == '1970-01-01T00:05:00Z'
81
+
52
82
  assert window.next == '1970-01-01T00:06:00Z'
83
+
53
84
  assert window.walked is False
54
85
 
55
86
 
87
+
88
+ def test_Window_cover(
89
+ window: Window,
90
+ ) -> None:
91
+ """
92
+ Perform various tests associated with relevant routines.
93
+
94
+ :param window: Primary class instance for window object.
95
+ """
96
+
97
+
98
+ window = Window(
99
+ schedule='* * * * *',
100
+ start=window.start,
101
+ stop=window.stop)
102
+
103
+ assert window.last == '1970-01-01T00:05:00Z'
104
+ assert window.next == '1970-01-01T00:06:00Z'
105
+ assert window.walked is False
106
+
56
107
  for count in range(100):
57
108
  if window.walk() is False:
58
109
  break
@@ -66,15 +117,13 @@ def test_Window() -> None:
66
117
  assert window.walked is True
67
118
 
68
119
 
69
- window = Window({'minutes': 1}, 300, 600)
120
+ window = Window(
121
+ schedule={'minutes': 1},
122
+ start=window.start,
123
+ stop=window.stop)
70
124
 
71
- assert window.schedule == {'minutes': 1}
72
- assert window.start == '1970-01-01T00:05:00Z'
73
- assert window.stop == '1970-01-01T00:10:00Z'
74
- assert window.anchor == window.start
75
- assert window.delay == 0.0
76
- assert window.last == '1970-01-01T00:04:00Z'
77
- assert window.next == '1970-01-01T00:05:00Z'
125
+ assert window.last == '1970-01-01T00:04:30Z'
126
+ assert window.next == '1970-01-01T00:05:30Z'
78
127
  assert window.walked is False
79
128
 
80
129
  for count in range(100):
@@ -85,12 +134,15 @@ def test_Window() -> None:
85
134
  assert count == 5
86
135
  assert not window.walk()
87
136
 
88
- assert window.last == '1970-01-01T00:10:00Z'
89
- assert window.next == '1970-01-01T00:10:00Z'
137
+ assert window.last == '1970-01-01T00:10:30Z'
138
+ assert window.next == '1970-01-01T00:10:30Z'
90
139
  assert window.walked is True
91
140
 
92
141
 
93
- window = Window('* * * * *', '+5m', '+10m')
142
+ window = Window(
143
+ schedule='* * * * *',
144
+ start='+5m', stop='+10m')
145
+
94
146
  assert not window.walk(False)
95
147
 
96
148
 
@@ -110,7 +162,7 @@ def test_Window() -> None:
110
162
  ('0 * * * *', 3661, False, (3600, 7200))])
111
163
  def test_window_croniter(
112
164
  schedule: str,
113
- anchor: PARSABLE,
165
+ anchor: 'PARSABLE',
114
166
  backward: bool,
115
167
  expect: tuple[int, int],
116
168
  ) -> None:
@@ -146,7 +198,7 @@ def test_window_croniter(
146
198
  ({'hours': 1}, 3661, False, (3661, 7261))])
147
199
  def test_window_interval(
148
200
  schedule: dict[str, int],
149
- anchor: PARSABLE,
201
+ anchor: 'PARSABLE',
150
202
  backward: bool,
151
203
  expect: tuple[int, int],
152
204
  ) -> None: