ParUtils 1.2.5__py3-none-any.whl → 1.2.6__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.
parutils/__init__.py CHANGED
@@ -52,3 +52,4 @@ from .dq import del_dup_list
52
52
  from .dq import find_dup_list
53
53
 
54
54
  from .testing import ttry
55
+ from .testing import Wtry
parutils/changelog.py CHANGED
@@ -1,6 +1,11 @@
1
- __VERSION__ = '1.2.5'
2
- # Faster file.load_txt
3
- # Corrected comment typos
1
+ __VERSION__ = '1.2.6'
2
+ # Wtry context manager
3
+ # truncate middle by default
4
+
5
+ # __VERSION__ = '1.2.5'
6
+ # # Faster file.load_txt
7
+ # # Corrected comment typos
8
+ # # pyproject.toml
4
9
 
5
10
  # __VERSION__ = '1.2.4'
6
11
  # # !dir -> log_dir
parutils/strg.py CHANGED
@@ -166,6 +166,15 @@ def big_number(int_in):
166
166
  return (out)
167
167
 
168
168
 
169
- def truncate(s, length=100):
170
- out = s[0:length - 3] + '...' if len(s) > length else s
171
- return out
169
+ def truncate(in_str: str, max_length=100, middle=True) -> str:
170
+ s = str(in_str)
171
+ if len(s) <= max(max_length, 5):
172
+ return s
173
+ if not middle:
174
+ return s[0:max_length - 3] + '...'
175
+
176
+ part_length = (max_length - 5) // 2
177
+ # If max_length - 3 is odd, the front will be longer
178
+ front = s[:part_length + (max_length - 5) % 2]
179
+ back = s[-part_length:]
180
+ return front + '[...]' + back
parutils/testing.py CHANGED
@@ -2,6 +2,27 @@ from .strg import like
2
2
  from .logging import log
3
3
 
4
4
 
5
+ class Wtry:
6
+ def __init__(self, e_ref):
7
+ self.e_ref = e_ref
8
+
9
+ def __enter__(self):
10
+ return self
11
+
12
+ def __exit__(self, exc_type, exc_val, exc_tb):
13
+ if not exc_type:
14
+ s = "[Wtry] No exception was caught"
15
+ log(s)
16
+ raise Exception(s)
17
+ if like(str(exc_val), self.e_ref):
18
+ log(f"[Wtry] Exception caught match expected ('{self.e_ref}')")
19
+ return True
20
+ else:
21
+ s = f"[Wtry] Exception caught ('{exc_val}') don't match expected ('{self.e_ref}')"
22
+ log(s)
23
+ raise Exception(s)
24
+
25
+
5
26
  def ttry(f, e_ref, *args, **kwargs):
6
27
 
7
28
  exception_occured = False
@@ -61,7 +61,9 @@ def test_string():
61
61
 
62
62
  u.Logger('TEST_STRING', True)
63
63
  assert u.big_number(1000) == '1 000'
64
- assert u.truncate('test_test', 4) == 't...'
64
+ assert u.truncate('test_test', 10) == 'test_test'
65
+ assert u.truncate('test_test', 7) == 't[...]t'
66
+ assert u.truncate('test_test', 7, False) == 'test...'
65
67
  get_duration()
66
68
  like()
67
69
  u.check_log(CL)
@@ -16,6 +16,16 @@ def test_msc():
16
16
  u.ttry(u.ttry, err, nok_func, 'test_error_1')
17
17
  u.ttry(u.ttry, "[ttry] No exception was caught", ok_func, 'test_error')
18
18
 
19
+ with u.Wtry('test_error'):
20
+ nok_func()
21
+ with u.Wtry("[Wtry] No exception was caught"):
22
+ with u.Wtry('test_error'):
23
+ ok_func()
24
+ err = "[Wtry] Exception caught ('test_error') don't match expected ('test_error_1')"
25
+ with u.Wtry(err):
26
+ with u.Wtry('test_error_1'):
27
+ nok_func()
28
+
19
29
 
20
30
  def nok_func():
21
31
  raise Exception('test_error')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ParUtils
3
- Version: 1.2.5
3
+ Version: 1.2.6
4
4
  Summary: This package contains a bunch of Python utilities developed for Support, Test and Automation IT Engineers
5
5
  Author-email: Paul ARNAUD <paularnaud2@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/paularnaud2/ParUtils
@@ -1,12 +1,12 @@
1
- parutils/__init__.py,sha256=EaFtUmU0kYgnjvAFwPmoKt7I5zn9bxY02R7TUtcE6M4,1434
2
- parutils/changelog.py,sha256=-zSqn-8tI_VdDjCEenmTdpBN9br5-meNPj-lY8l0AW4,1920
1
+ parutils/__init__.py,sha256=-TvW6Rx9DMsbIqj7USEasNmR1n7oAp6r80Y48mbN7BE,1461
2
+ parutils/changelog.py,sha256=ZJS3qHv4kiwmEp92b7_HzBD05TqFSe5BE3y1FRR1BzA,2026
3
3
  parutils/csvl.py,sha256=JgJPnN8IPrdMD8OOlPtDSEhJULMkPkqnDnB-D4z9F-E,2871
4
4
  parutils/dq.py,sha256=kdvzOo5FLCumXagY05kGSseYlbR-zvjjmsMtGVliVc8,2302
5
5
  parutils/file.py,sha256=prENNneiQmKKRS5BxGH7tN23x5e6XSfyrhpO0lOLs0g,2739
6
6
  parutils/g.py,sha256=n99gQbLs2rmszBYw_wy43P4iQo3lqpBHz3-Q7sm9n_U,11
7
7
  parutils/msc.py,sha256=6Yx-VJss0xRqQAiuVURu0L4oDHkcsF7T5EK6eXrm9TQ,745
8
- parutils/strg.py,sha256=g4FjVWlUBsQO3xFoMe-ZYskCjVEQVyUCdDGliS_kbz4,5564
9
- parutils/testing.py,sha256=kXrMz8Kze4mZejaePmV_OIca4iuNcG_dhGVHCgVuF-k,610
8
+ parutils/strg.py,sha256=feFJON6qpiR8LV1954poO8i20-3wWdDNlpT_KtqIEAk,5879
9
+ parutils/testing.py,sha256=fC9wbJSSQXqW9RGPaQpp67VQKRFLoncS3s1bXL7qkuY,1227
10
10
  parutils/wrap.py,sha256=PqMyKodgEjWDXoIVZZXRaBSdkGFL5OWmVJttl2Crrg8,421
11
11
  parutils/logging/__init__.py,sha256=rSNpgjuYer-Hhn6zKzKwKSn_KfcajEXlk6cJnPC9eJU,461
12
12
  parutils/logging/cl.py,sha256=NCLuxLHvqRTypZlAgwnegkByLTnTirKntnwguJHBelA,2086
@@ -20,13 +20,13 @@ parutils/tests/conftest.py,sha256=iIyQvgVV8GzUwJ0tlN2KUJHX5ZO7lp8bKFK3VmRx4DU,48
20
20
  parutils/tests/test_csv.py,sha256=vHs_CT1oLWAGkRvKdF-Ilz62MczEDKqQfmmQe-nt-Wg,671
21
21
  parutils/tests/test_dq.py,sha256=Qb5lldyg-UAOvNbViNLnchkG93v_-DQ96XkIPgOIXWo,967
22
22
  parutils/tests/test_file.py,sha256=iYaSm0YU7qQIq9p7Sea4KPdoKRpqWcbgbkZG4u0DR_s,1031
23
- parutils/tests/test_msc.py,sha256=C2Q_88i2sIbz52KhvdkY0-3Aa9Yk2FSHFxVYUqoQ_Fs,696
23
+ parutils/tests/test_msc.py,sha256=swmidUNkCAH1WobJxX-6pXdJ5PwAzCTZp9wFV_-YlY4,1036
24
24
  parutils/tests/logging/check_log.py,sha256=Se-EuWuwxlcksjIkLZU4d77-o3eyFdppJCxGJ-GcorY,2332
25
25
  parutils/tests/logging/test_logging.py,sha256=bceIEO7W7rhLm_YrqRcXSA0NaQIAU1x6XZMWU3uNeFk,5260
26
26
  parutils/tests/string/check_log.py,sha256=m2RRJIorA6jg7uV_8nxWfKHUFZ98YPDn-DqzcTw3cQ0,211
27
- parutils/tests/string/test_string.py,sha256=jhfGkrHENUERIG2UAVIlGYDpeecQS-_-JtmMUR7qDMA,2023
28
- parutils-1.2.5.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
29
- parutils-1.2.5.dist-info/METADATA,sha256=EMs4o4amP6SV9U0Uhj15UpTte2ETmkAVke9hYCpzwgo,6868
30
- parutils-1.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- parutils-1.2.5.dist-info/top_level.txt,sha256=1MDobUcroeYEvdupZCAFvA5hJjm7LSDUV5A4jHySNis,9
32
- parutils-1.2.5.dist-info/RECORD,,
27
+ parutils/tests/string/test_string.py,sha256=9709GQ8iw4MnRHgBuGK9Ed_uuk9rL8EDVXdK0_la9zQ,2140
28
+ parutils-1.2.6.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
29
+ parutils-1.2.6.dist-info/METADATA,sha256=UV6ct-37viTm6FMvb0Q2BT8VRiaBdWrc9ydROgYZJAw,6868
30
+ parutils-1.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
+ parutils-1.2.6.dist-info/top_level.txt,sha256=1MDobUcroeYEvdupZCAFvA5hJjm7LSDUV5A4jHySNis,9
32
+ parutils-1.2.6.dist-info/RECORD,,