cdxcore 0.1.6__py3-none-any.whl → 0.1.9__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.
Potentially problematic release.
This version of cdxcore might be problematic. Click here for more details.
- cdxcore/__init__.py +1 -9
- cdxcore/config.py +1188 -521
- cdxcore/crman.py +95 -25
- cdxcore/err.py +371 -0
- cdxcore/pretty.py +468 -0
- cdxcore/pretty.py_bak.py +750 -0
- cdxcore/subdir.py +2225 -1334
- cdxcore/uniquehash.py +515 -363
- cdxcore/util.py +358 -417
- cdxcore/verbose.py +683 -248
- cdxcore/version.py +398 -139
- cdxcore-0.1.9.dist-info/METADATA +27 -0
- cdxcore-0.1.9.dist-info/RECORD +36 -0
- {cdxcore-0.1.6.dist-info → cdxcore-0.1.9.dist-info}/top_level.txt +3 -1
- docs/source/conf.py +123 -0
- docs2/source/conf.py +35 -0
- tests/test_config.py +502 -0
- tests/test_crman.py +54 -0
- tests/test_err.py +86 -0
- tests/test_pretty.py +404 -0
- tests/test_subdir.py +289 -0
- tests/test_uniquehash.py +159 -144
- tests/test_util.py +122 -83
- tests/test_verbose.py +119 -0
- tests/test_version.py +153 -0
- up/git_message.py +2 -2
- cdxcore/logger.py +0 -319
- cdxcore/prettydict.py +0 -388
- cdxcore/prettyobject.py +0 -64
- cdxcore-0.1.6.dist-info/METADATA +0 -1418
- cdxcore-0.1.6.dist-info/RECORD +0 -30
- conda/conda_exists.py +0 -10
- conda/conda_modify_yaml.py +0 -42
- tests/_cdxbasics.py +0 -1086
- {cdxcore-0.1.6.dist-info → cdxcore-0.1.9.dist-info}/WHEEL +0 -0
- {cdxcore-0.1.6.dist-info → cdxcore-0.1.9.dist-info}/licenses/LICENSE +0 -0
- {cdxcore → tmp}/deferred.py +0 -0
- {cdxcore → tmp}/dynaplot.py +0 -0
- {cdxcore → tmp}/filelock.py +0 -0
- {cdxcore → tmp}/jcpool.py +0 -0
- {cdxcore → tmp}/np.py +0 -0
- {cdxcore → tmp}/npio.py +0 -0
- {cdxcore → tmp}/sharedarray.py +0 -0
tests/test_uniquehash.py
CHANGED
|
@@ -9,33 +9,47 @@ import numpy as np
|
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import datetime as datetime
|
|
11
11
|
from zoneinfo import ZoneInfo
|
|
12
|
-
import hashlib as hashlib
|
|
13
12
|
|
|
13
|
+
def import_local():
|
|
14
|
+
"""
|
|
15
|
+
In order to be able to run our tests manually from the 'tests' directory
|
|
16
|
+
we force import from the local package.
|
|
17
|
+
We also force reloading all modules to make sure we are not running old code.
|
|
18
|
+
"""
|
|
19
|
+
me = "cdxcore"
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
cwd = os.getcwd()
|
|
23
|
+
if cwd[-len(me):] == me:
|
|
24
|
+
return
|
|
25
|
+
assert cwd[-5:] == "tests",("Expected current working directory to be in a 'tests' directory", cwd[-5:], "from", cwd)
|
|
26
|
+
assert cwd[-6] in ['/', '\\'],("Expected current working directory 'tests' to be lead by a '\\' or '/'", cwd[-6:], "from", cwd)
|
|
27
|
+
sys.path.insert( 0, cwd[:-6] )
|
|
28
|
+
|
|
29
|
+
# reload modules
|
|
30
|
+
import importlib as imp
|
|
31
|
+
modules = sys.modules.copy()
|
|
32
|
+
for name, mdata in modules.items():
|
|
33
|
+
if name[:len(me)] == me:
|
|
34
|
+
imp.reload(mdata)
|
|
35
|
+
import_local()
|
|
36
|
+
|
|
14
37
|
"""
|
|
15
|
-
|
|
16
|
-
import source.util as _
|
|
17
|
-
imp.reload(_)
|
|
18
|
-
import source.prettydict as _
|
|
19
|
-
imp.reload(_)
|
|
20
|
-
import source.prettyobject as _
|
|
21
|
-
imp.reload(_)
|
|
22
|
-
import source.uniquehash as _
|
|
23
|
-
imp.reload(_)
|
|
38
|
+
Imports
|
|
24
39
|
"""
|
|
25
|
-
from cdxcore.uniquehash import UniqueHash,
|
|
26
|
-
from cdxcore.
|
|
27
|
-
|
|
40
|
+
from cdxcore.uniquehash import UniqueHash, NamedUniqueHash, UniqueLabel, unique_hash32 as unique_hash, unique_hash8, unique_hash16, unique_hash32, unique_hash48, unique_hash64, DEF_FILE_NAME_MAP, DebugTraceCollect, DebugTraceVerbose
|
|
41
|
+
from cdxcore.pretty import PrettyObject
|
|
42
|
+
|
|
43
|
+
PrettyOrderedDict = PrettyObject
|
|
28
44
|
|
|
29
45
|
uniqueHashProtected = UniqueHash(32,parse_underscore="protected")
|
|
30
46
|
uniqueHashPrivate = UniqueHash(32,parse_underscore="private")
|
|
31
47
|
uniqueHashF = UniqueHash(32,parse_functions=True)
|
|
32
48
|
|
|
33
|
-
namedUniqueHash32_8 =
|
|
34
|
-
uniqueLabel32_8 =
|
|
35
|
-
|
|
36
|
-
uniqueLabelExt
|
|
49
|
+
namedUniqueHash32_8 = NamedUniqueHash( max_length=32, id_length=8, parse_underscore="protected" )
|
|
50
|
+
uniqueLabel32_8 = UniqueLabel( max_length=32, id_length=8 )
|
|
37
51
|
|
|
38
|
-
class
|
|
52
|
+
class Test(unittest.TestCase):
|
|
39
53
|
|
|
40
54
|
def __init__(self, *args, **kwargs):
|
|
41
55
|
self.maxDiff = 2000
|
|
@@ -43,48 +57,48 @@ class UtilTest(unittest.TestCase):
|
|
|
43
57
|
|
|
44
58
|
def test_uniqueHash(self):
|
|
45
59
|
|
|
46
|
-
self.assertEqual(
|
|
47
|
-
self.assertEqual(
|
|
48
|
-
self.assertEqual(
|
|
49
|
-
self.assertEqual(
|
|
50
|
-
self.assertEqual(
|
|
51
|
-
self.assertEqual(
|
|
52
|
-
self.assertEqual(
|
|
53
|
-
self.assertEqual(
|
|
54
|
-
self.assertEqual(
|
|
60
|
+
self.assertEqual( unique_hash( 1==1 ), "c8814ea06a53a108a02015477d9ea347" )
|
|
61
|
+
self.assertEqual( unique_hash( "test" ), "e9ddd9926b9dcb382e09be39ba403d2c" )
|
|
62
|
+
self.assertEqual( unique_hash( "test".encode("utf-8") ), "e9ddd9926b9dcb382e09be39ba403d2c" )
|
|
63
|
+
self.assertEqual( unique_hash( 0 ), "d566dfb39f20d549d1c0684e94949c71" )
|
|
64
|
+
self.assertEqual( unique_hash( -1 ), "265e3aae841649db057419ac7d85d399" )
|
|
65
|
+
self.assertEqual( unique_hash( 0x7fff ), "1770301688382dac9c6d87284d5a3111" )
|
|
66
|
+
self.assertEqual( unique_hash( 0.1 ), "f45961d9b7e8673e7c758bcfd8af7cb9" )
|
|
67
|
+
self.assertEqual( unique_hash( 1E-10), "9102ac1dc2adb0aa013cd897a69f74d2" )
|
|
68
|
+
self.assertEqual( unique_hash( np.nan ), "a22bbc77f337db5e2445bd5c0235812e" )
|
|
55
69
|
|
|
56
|
-
self.assertEqual(
|
|
57
|
-
self.assertEqual(
|
|
58
|
-
self.assertEqual(
|
|
59
|
-
self.assertEqual(
|
|
60
|
-
self.assertEqual(
|
|
61
|
-
self.assertEqual(
|
|
62
|
-
self.assertEqual(
|
|
63
|
-
self.assertEqual(
|
|
64
|
-
self.assertEqual(
|
|
65
|
-
self.assertEqual(
|
|
66
|
-
self.assertEqual(
|
|
70
|
+
self.assertEqual( unique_hash( np.float16(0) ), "ff1bed336aae497f15a0d3f534609380" )
|
|
71
|
+
self.assertEqual( unique_hash( np.float32(0) ), "c566588ea757dd31297b78f8c62a4b05" )
|
|
72
|
+
self.assertEqual( unique_hash( np.float64(0) ), "d566dfb39f20d549d1c0684e94949c71" )
|
|
73
|
+
self.assertEqual( unique_hash( np.int8(0) ), "9f31f3ec588c6064a8e1f9051aeab90a" )
|
|
74
|
+
self.assertEqual( unique_hash( np.int8(-1) ), "df09d795132a032676a7ca47bcc2db61" )
|
|
75
|
+
self.assertEqual( unique_hash( np.uint8(250) ), "5067455d73d452a04850bf2f20ee3c61" )
|
|
76
|
+
self.assertEqual( unique_hash( np.int16(0) ), "ff1bed336aae497f15a0d3f534609380" )
|
|
77
|
+
self.assertEqual( unique_hash( np.uint16(0xFFFF) ), "f1118c91662ef7ccc0e2f45922d41d90" )
|
|
78
|
+
self.assertEqual( unique_hash( np.int32(0) ), "c566588ea757dd31297b78f8c62a4b05" )
|
|
79
|
+
self.assertEqual( unique_hash( np.int64(0) ), "d566dfb39f20d549d1c0684e94949c71" )
|
|
80
|
+
self.assertEqual( unique_hash( np.int64(-1) ), "265e3aae841649db057419ac7d85d399" )
|
|
67
81
|
|
|
68
|
-
self.assertEqual(
|
|
69
|
-
self.assertEqual(
|
|
70
|
-
self.assertEqual(
|
|
71
|
-
self.assertEqual(
|
|
82
|
+
self.assertEqual( unique_hash( [1,2,np.float16(3),4] ), "0922f2f0d1df45dac328582df43888f2" )
|
|
83
|
+
self.assertEqual( unique_hash( [2,1,np.float16(3),4] ), "a33b2ce355ea93a0153d53806e5b692b" )
|
|
84
|
+
self.assertEqual( unique_hash( set([1,2,np.float16(3),4]) ), "0922f2f0d1df45dac328582df43888f2" )
|
|
85
|
+
self.assertEqual( unique_hash( x for x in [1,2,np.float16(3),4] ), "64550d6ffe2c0a01a14aba1eade0200c" )
|
|
72
86
|
|
|
73
87
|
# dicts
|
|
74
|
-
self.assertEqual(
|
|
75
|
-
self.assertEqual(
|
|
88
|
+
self.assertEqual( unique_hash( {'a':"mix"} ), "cfd3448192fa25895e52426f69d550b1" )
|
|
89
|
+
self.assertEqual( unique_hash( {'a':"mix", 'b':1} ), "3c85e8c0142b9b3d9c78b10106e27fdc" )
|
|
76
90
|
|
|
77
91
|
r = PrettyOrderedDict()
|
|
78
92
|
r.x = 1
|
|
79
|
-
self.assertEqual(
|
|
93
|
+
self.assertEqual( unique_hash( r ), "5bdac013107a78ea9ca53a6df858cfa8" )
|
|
80
94
|
r.x = 2
|
|
81
|
-
hashr =
|
|
95
|
+
hashr = unique_hash( r )
|
|
82
96
|
self.assertEqual( hashr, "e6b10cf5d15f3ec798eb9daa516606cf" ) # (1)
|
|
83
97
|
r._x = 1
|
|
84
98
|
# elements with '_' are ignored by default
|
|
85
|
-
self.assertEqual(
|
|
86
|
-
self.assertEqual(
|
|
87
|
-
self.assertEqual(
|
|
99
|
+
self.assertEqual( unique_hash( r ), hashr ) # same as above (1)
|
|
100
|
+
self.assertEqual( unique_hash( PrettyOrderedDict(_y=100,x=2 ) ), hashr ) # same as above (1)
|
|
101
|
+
self.assertEqual( unique_hash( PrettyOrderedDict(__y=100,x=2 ) ), hashr ) # same as above (1)
|
|
88
102
|
# protected
|
|
89
103
|
self.assertEqual( uniqueHashProtected( PrettyOrderedDict(x=2 )), hashr ) # same as (1)
|
|
90
104
|
hashprot = uniqueHashProtected( PrettyOrderedDict(_y=100,x=2 ) )
|
|
@@ -96,7 +110,7 @@ class UtilTest(unittest.TestCase):
|
|
|
96
110
|
self.assertEqual( uniqueHashPrivate( PrettyOrderedDict(_y=100,x=2 ) ), hashprot ) # same as (2)
|
|
97
111
|
hash3 = uniqueHashPrivate( PrettyOrderedDict(_y=100,__z=100,x=2 ) )
|
|
98
112
|
hash4 = uniqueHashPrivate( PrettyOrderedDict(__z=100,x=2 ) )
|
|
99
|
-
self.assertEqual( hash3, "
|
|
113
|
+
self.assertEqual( hash3, "baa7e5c21a9b5bbfbe783ad92bd5e38b" ) # (3)
|
|
100
114
|
self.assertNotEqual( hash3, hashprot )
|
|
101
115
|
self.assertEqual( hash4, "9cc69ec4c0e9f3f820ca63531e7ba0a2" ) # (4)
|
|
102
116
|
self.assertNotEqual( hash4, hashprot )
|
|
@@ -105,7 +119,7 @@ class UtilTest(unittest.TestCase):
|
|
|
105
119
|
def __init__(self_):
|
|
106
120
|
self_.x = [ 1,2,3. ]
|
|
107
121
|
self_.y = { 'a':1, 'b':2 }
|
|
108
|
-
self_.z =
|
|
122
|
+
self_.z = PrettyObject(c=3,d=4)
|
|
109
123
|
self_.r = set([65,6234,1231,123123,12312])
|
|
110
124
|
self_.t = (1,2,"test")
|
|
111
125
|
self_.s = {1,3,4,2,5}
|
|
@@ -120,9 +134,9 @@ class UtilTest(unittest.TestCase):
|
|
|
120
134
|
self_.b = np.zeros((3,4,2))
|
|
121
135
|
self_.c = pd.DataFrame({'a':np.array([1,2,3]),'b':np.array([10,20,30]),'c':np.array([100,200,300]), })
|
|
122
136
|
|
|
123
|
-
u =
|
|
137
|
+
u = unique_hash(self_.b) # numpy
|
|
124
138
|
self.assertEqual( u, "de8bc8a3a92214d15e50f137565ed6a7" )
|
|
125
|
-
u =
|
|
139
|
+
u = unique_hash(self_.c) # panda frame
|
|
126
140
|
self.assertEqual( u, "6825de2c38cab22de057211b1ad01ce8" )
|
|
127
141
|
|
|
128
142
|
def f(self_):
|
|
@@ -137,26 +151,26 @@ class UtilTest(unittest.TestCase):
|
|
|
137
151
|
return self_.x
|
|
138
152
|
|
|
139
153
|
x = np.array([1,2,3,4.])
|
|
140
|
-
u =
|
|
154
|
+
u = unique_hash(x)
|
|
141
155
|
self.assertEqual( u, "b45b735c27fa083d3ea50021251d178f" )
|
|
142
156
|
|
|
143
157
|
o2 = [ np.float32(0), np.float64(0), np.int32(0), np.int64(0) ]
|
|
144
|
-
u =
|
|
158
|
+
u = unique_hash(o2)
|
|
145
159
|
self.assertEqual( u, "8bae89164e1da1371c9beacc007db340" )
|
|
146
160
|
|
|
147
161
|
o = Object()
|
|
148
|
-
u =
|
|
149
|
-
self.assertEqual( u, "
|
|
150
|
-
u =
|
|
151
|
-
self.assertEqual( u, "
|
|
152
|
-
u =
|
|
153
|
-
self.assertEqual( u, "
|
|
154
|
-
u =
|
|
155
|
-
self.assertEqual( u, "
|
|
156
|
-
u =
|
|
157
|
-
self.assertEqual( u, "
|
|
158
|
-
u =
|
|
159
|
-
self.assertEqual( u, "
|
|
162
|
+
u = unique_hash(o)
|
|
163
|
+
self.assertEqual( u, "7b0ce60d5a922b47c2e73a9604060510" )
|
|
164
|
+
u = unique_hash8(o)
|
|
165
|
+
self.assertEqual( u, "305c3163" )
|
|
166
|
+
u = unique_hash16(o)
|
|
167
|
+
self.assertEqual( u, "ea0c4db7b20fbbe4" )
|
|
168
|
+
u = unique_hash32(o)
|
|
169
|
+
self.assertEqual( u, "7b0ce60d5a922b47c2e73a9604060510" )
|
|
170
|
+
u = unique_hash48(o)
|
|
171
|
+
self.assertEqual( u, "2187ac6fbd548e81343bfb4c3ef08dd6d1264729a7f04b82" )
|
|
172
|
+
u = unique_hash64(o)
|
|
173
|
+
self.assertEqual( u, "840c6d1d9d6e3cc49dc6ed0ded1020674ed371588255a5230e44b4e872f57358" )
|
|
160
174
|
|
|
161
175
|
class X(object):
|
|
162
176
|
__slots__ = ['x', 'y']
|
|
@@ -179,36 +193,36 @@ class UtilTest(unittest.TestCase):
|
|
|
179
193
|
a2 = A(1,3)
|
|
180
194
|
b = B(1,2)
|
|
181
195
|
debug_trace = DebugTraceCollect()
|
|
182
|
-
hash1 =
|
|
196
|
+
hash1 = unique_hash(a1, debug_trace=debug_trace)
|
|
183
197
|
trace1 = repr(debug_trace)
|
|
184
198
|
|
|
185
199
|
debug_trace = DebugTraceCollect()
|
|
186
|
-
hash2 =
|
|
200
|
+
hash2 = unique_hash(a2, debug_trace=debug_trace)
|
|
187
201
|
trace2 = repr(debug_trace)
|
|
188
202
|
|
|
189
203
|
debug_trace = DebugTraceCollect()
|
|
190
|
-
hash3 =
|
|
204
|
+
hash3 = unique_hash(b,debug_trace=debug_trace)
|
|
191
205
|
trace3 = repr(debug_trace)
|
|
192
206
|
|
|
193
|
-
self.assertEqual( hash1, "
|
|
194
|
-
self.assertEqual( hash2, "
|
|
207
|
+
self.assertEqual( hash1, "610eac1fa7e30fb1f9e20a29e3f5e527" ) # (1)
|
|
208
|
+
self.assertEqual( hash2, "4864ea1d65079c41841d145716ee47ff" ) # (2) != (1)
|
|
195
209
|
self.assertNotEqual( hash1, hash2 ) # (1) != (2)
|
|
196
|
-
self.assertEqual( hash3, "
|
|
210
|
+
self.assertEqual( hash3, "610eac1fa7e30fb1f9e20a29e3f5e527" ) # (3) == (1)
|
|
197
211
|
self.assertEqual( hash3, hash1 ) # (3) == (1)
|
|
198
212
|
self.assertEqual( uniqueHashProtected(a1), hash1 ) # == (1)
|
|
199
213
|
self.assertEqual( uniqueHashProtected(a2), hash2 ) # == (2)
|
|
200
214
|
debug_trace = DebugTraceCollect()
|
|
201
215
|
hash3p = uniqueHashProtected(b,debug_trace=debug_trace)
|
|
202
216
|
trace3p = repr(debug_trace)
|
|
203
|
-
self.assertEqual( hash3p, "
|
|
217
|
+
self.assertEqual( hash3p, "8e62d262da492b3f96fbc0be1e21fcfb" ) # != (1)
|
|
204
218
|
|
|
205
|
-
r = "DebugTraceCollect([PrettyObject({'x': (X(x=1,y=2),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': X(x=1,y=2), 'msg': 'object with __slots__', 'child': DebugTraceCollect([PrettyObject({'x': '
|
|
219
|
+
r = "DebugTraceCollect([PrettyObject({'x': (X(x=1,y=2),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': X(x=1,y=2), 'msg': 'object with __slots__', 'child': DebugTraceCollect([PrettyObject({'x': 'Test.test_uniqueHash.<locals>.X', 'msg': None, 'child': None}), PrettyObject({'x': 'x', 'msg': None, 'child': None}), PrettyObject({'x': 1, 'msg': None, 'child': None}), PrettyObject({'x': 'y', 'msg': None, 'child': None}), PrettyObject({'x': 2, 'msg': None, 'child': None})])})])})])"
|
|
206
220
|
self.assertEqual(trace1,r)
|
|
207
|
-
r = "DebugTraceCollect([PrettyObject({'x': (X(x=1,y=3),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': X(x=1,y=3), 'msg': 'object with __slots__', 'child': DebugTraceCollect([PrettyObject({'x': '
|
|
221
|
+
r = "DebugTraceCollect([PrettyObject({'x': (X(x=1,y=3),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': X(x=1,y=3), 'msg': 'object with __slots__', 'child': DebugTraceCollect([PrettyObject({'x': 'Test.test_uniqueHash.<locals>.X', 'msg': None, 'child': None}), PrettyObject({'x': 'x', 'msg': None, 'child': None}), PrettyObject({'x': 1, 'msg': None, 'child': None}), PrettyObject({'x': 'y', 'msg': None, 'child': None}), PrettyObject({'x': 3, 'msg': None, 'child': None})])})])})])"
|
|
208
222
|
self.assertEqual(trace2,r)
|
|
209
|
-
r = "DebugTraceCollect([PrettyObject({'x': (X(x=1,y=2,_z=2),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': X(x=1,y=2,_z=2), 'msg': 'object with __slots__', 'child': DebugTraceCollect([PrettyObject({'x': '
|
|
223
|
+
r = "DebugTraceCollect([PrettyObject({'x': (X(x=1,y=2,_z=2),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': X(x=1,y=2,_z=2), 'msg': 'object with __slots__', 'child': DebugTraceCollect([PrettyObject({'x': 'Test.test_uniqueHash.<locals>.X', 'msg': None, 'child': None}), PrettyObject({'x': 'x', 'msg': None, 'child': None}), PrettyObject({'x': 1, 'msg': None, 'child': None}), PrettyObject({'x': 'y', 'msg': None, 'child': None}), PrettyObject({'x': 2, 'msg': None, 'child': None})])})])})])"
|
|
210
224
|
self.assertEqual(trace3,r)
|
|
211
|
-
r = "DebugTraceCollect([PrettyObject({'x': (X(x=1,y=2,_z=2),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': X(x=1,y=2,_z=2), 'msg': 'object with __slots__', 'child': DebugTraceCollect([PrettyObject({'x': '
|
|
225
|
+
r = "DebugTraceCollect([PrettyObject({'x': (X(x=1,y=2,_z=2),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': X(x=1,y=2,_z=2), 'msg': 'object with __slots__', 'child': DebugTraceCollect([PrettyObject({'x': 'Test.test_uniqueHash.<locals>.X', 'msg': None, 'child': None}), PrettyObject({'x': 'x', 'msg': None, 'child': None}), PrettyObject({'x': 1, 'msg': None, 'child': None}), PrettyObject({'x': 'y', 'msg': None, 'child': None}), PrettyObject({'x': 2, 'msg': None, 'child': None}), PrettyObject({'x': '_z', 'msg': None, 'child': None}), PrettyObject({'x': 2, 'msg': None, 'child': None})])})])})])"
|
|
212
226
|
self.assertEqual(trace3p,r)
|
|
213
227
|
|
|
214
228
|
o1 = PrettyObject(x=1)#, y=Object())
|
|
@@ -221,20 +235,20 @@ class UtilTest(unittest.TestCase):
|
|
|
221
235
|
self.assertTrue( not hasattr(o3, "_test" ) )
|
|
222
236
|
self.assertTrue( not hasattr(o3, "__test" ) )
|
|
223
237
|
|
|
224
|
-
hashbase =
|
|
238
|
+
hashbase = unique_hash( o1 )
|
|
225
239
|
hashprot = uniqueHashProtected( o1 )
|
|
226
240
|
hashpriv = uniqueHashPrivate( o1 )
|
|
227
241
|
|
|
228
|
-
self.assertEqual(
|
|
229
|
-
self.assertEqual(
|
|
242
|
+
self.assertEqual( unique_hash( o2 ) , hashbase )
|
|
243
|
+
self.assertEqual( unique_hash( o3 ) , hashbase )
|
|
230
244
|
self.assertEqual( uniqueHashProtected( o2 ) , hashprot )
|
|
231
245
|
self.assertNotEqual( uniqueHashProtected( o3 ) , hashprot )
|
|
232
246
|
self.assertNotEqual( uniqueHashPrivate( o2 ) , hashpriv )
|
|
233
247
|
self.assertNotEqual( uniqueHashPrivate( o3 ) , hashpriv )
|
|
234
248
|
|
|
235
249
|
debug_trace = DebugTraceCollect()
|
|
236
|
-
u1 =
|
|
237
|
-
r = "[PrettyObject({'x': (PrettyObject({'x': 1, '_test': 2, '
|
|
250
|
+
u1 = unique_hash( o1, debug_trace=debug_trace )
|
|
251
|
+
r = "[PrettyObject({'x': (PrettyObject({'x': 1, '_test': 2, '_Test__test': 3}),), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': PrettyObject({'x': 1, '_test': 2, '_Test__test': 3}), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': ('x', 1), 'msg': None, 'child': DebugTraceCollect([PrettyObject({'x': 'x', 'msg': None, 'child': None}), PrettyObject({'x': 1, 'msg': None, 'child': None})])})])})])})]"
|
|
238
252
|
self.assertEqual( str(debug_trace), r)
|
|
239
253
|
|
|
240
254
|
# test functions
|
|
@@ -247,24 +261,23 @@ class UtilTest(unittest.TestCase):
|
|
|
247
261
|
u2 = uniqueHashF(f2)
|
|
248
262
|
u3 = uniqueHashF(f3)
|
|
249
263
|
self.assertEqual(u0,"64550d6ffe2c0a01a14aba1eade0200c")
|
|
250
|
-
self.assertEqual(u1,"
|
|
251
|
-
self.assertEqual(u2,"4d85d642c797206fabc75eb34b491fa6")
|
|
264
|
+
self.assertEqual(u1,"a0c25a23de91678dc6d606b4bc68797d")
|
|
252
265
|
self.assertEqual(u2,u1)
|
|
253
|
-
self.assertEqual(u3,"
|
|
266
|
+
self.assertEqual(u3,"f3050eec75ca604eaeb175b6bde2a8bb")
|
|
254
267
|
self.assertNotEqual(u3,u1)
|
|
255
268
|
|
|
256
|
-
u1 =
|
|
257
|
-
u2 =
|
|
258
|
-
u3 =
|
|
269
|
+
u1 = unique_hash(f1)
|
|
270
|
+
u2 = unique_hash(f2)
|
|
271
|
+
u3 = unique_hash(f3)
|
|
259
272
|
self.assertEqual(u1,u0)
|
|
260
273
|
self.assertEqual(u2,u0)
|
|
261
274
|
self.assertEqual(u3,u0)
|
|
262
275
|
|
|
263
276
|
# test ignore warning
|
|
264
277
|
debug_trace = DebugTraceCollect()
|
|
265
|
-
u1 =
|
|
278
|
+
u1 = unique_hash( f1, debug_trace=debug_trace )
|
|
266
279
|
ignore = debug_trace[0].child[0].msg
|
|
267
|
-
self.assertEqual( ignore, "Ignored function:
|
|
280
|
+
self.assertEqual( ignore, "Ignored function: Test.test_uniqueHash.<locals>.<lambda>")
|
|
268
281
|
|
|
269
282
|
# globals, defaults
|
|
270
283
|
def test1():
|
|
@@ -295,9 +308,9 @@ class UtilTest(unittest.TestCase):
|
|
|
295
308
|
|
|
296
309
|
u5 = uniqueHashF( f4 )
|
|
297
310
|
|
|
298
|
-
self.assertEqual( u1, "
|
|
299
|
-
self.assertEqual( u2, "
|
|
300
|
-
self.assertEqual( u3, "
|
|
311
|
+
self.assertEqual( u1, "6285055ea7e60e9860c04f9b56a76368")
|
|
312
|
+
self.assertEqual( u2, "322825a47fd43cf42cb6bf313758dcb4")
|
|
313
|
+
self.assertEqual( u3, "5c17e071c9e3b46471fa5f73a7aa54a5" )
|
|
301
314
|
self.assertEqual( u4, u2 ) #
|
|
302
315
|
self.assertNotEqual( u5, u3 ) # global 'z' different !
|
|
303
316
|
test1()
|
|
@@ -314,7 +327,7 @@ class UtilTest(unittest.TestCase):
|
|
|
314
327
|
u2 = uniqueHashF( f2 )
|
|
315
328
|
u3 = uniqueHashF( f3 )
|
|
316
329
|
|
|
317
|
-
self.assertEqual( u1, "
|
|
330
|
+
self.assertEqual( u1, "cc3d356d1e7f84f1e3aacd8d8346c6ef" )
|
|
318
331
|
self.assertEqual( u2, u1 )
|
|
319
332
|
self.assertNotEqual( u3, u1 )
|
|
320
333
|
|
|
@@ -329,78 +342,78 @@ class UtilTest(unittest.TestCase):
|
|
|
329
342
|
lots2 = datetime.datetime( year=1974, month=3, day=17, hour=16, minute=2, second=3, microsecond=0, tzinfo=tz2 )
|
|
330
343
|
lots3 = datetime.datetime( year=1974, month=3, day=17, hour=16, minute=2, second=3, microsecond=0, tzinfo=tz3 )
|
|
331
344
|
|
|
332
|
-
plainhash =
|
|
345
|
+
plainhash = unique_hash(plain)
|
|
333
346
|
self.assertEqual( plainhash, "9142b8ffd5f12e83f94c261da5935674") # (1)
|
|
334
|
-
self.assertEqual(
|
|
335
|
-
self.assertEqual(
|
|
336
|
-
self.assertEqual(
|
|
337
|
-
self.assertEqual(
|
|
338
|
-
self.assertEqual(
|
|
347
|
+
self.assertEqual( unique_hash(timz), "82b58ccbe7a14a31d86aaa4ff5148ddb")
|
|
348
|
+
self.assertEqual( unique_hash(micro), "89c16cd9eb05f2bc92ddab0a9cce96bc")
|
|
349
|
+
self.assertEqual( unique_hash(lots), "8ad007ff97156db6ab709cead44ca5c0")
|
|
350
|
+
self.assertEqual( unique_hash(lots2), "045730565f1ae4f07e28f2d80a4b98c9")
|
|
351
|
+
self.assertEqual( unique_hash(lots3), plainhash) # same as (1)
|
|
339
352
|
|
|
340
|
-
hash1 =
|
|
353
|
+
hash1 = unique_hash(datetime.date( year=1974, month=3, day=17 ))
|
|
341
354
|
self.assertEqual( hash1, "5ea7ea54a4a5e16b41be046d62092e3d") # (1)
|
|
342
|
-
self.assertEqual(
|
|
343
|
-
self.assertEqual(
|
|
344
|
-
self.assertEqual(
|
|
345
|
-
self.assertEqual(
|
|
346
|
-
self.assertEqual(
|
|
355
|
+
self.assertEqual( unique_hash(plain.date()),hash1 ) # same as (1)
|
|
356
|
+
self.assertEqual( unique_hash(datetime.date( year=1974, month=3, day=2 )), "21c4c10490cb41431c6c444c4d49c287")
|
|
357
|
+
self.assertEqual( unique_hash(datetime.date( year=2074, month=3, day=2 )), "5498e6f3519c815393f2da1d42dda196")
|
|
358
|
+
self.assertEqual( unique_hash(datetime.time( hour=16, minute=2, second=3, microsecond=0 )), "e10f649dae2851b77f63b196b63c01c5")
|
|
359
|
+
self.assertEqual( unique_hash(datetime.time( hour=16, minute=2, second=3 )), "e10f649dae2851b77f63b196b63c01c5")
|
|
347
360
|
|
|
348
|
-
empty =
|
|
361
|
+
empty = unique_hash(datetime.timedelta())
|
|
349
362
|
self.assertEqual( empty, "d566dfb39f20d549d1c0684e94949c71")
|
|
350
|
-
self.assertEqual(
|
|
351
|
-
self.assertEqual(
|
|
352
|
-
self.assertEqual(
|
|
353
|
-
self.assertEqual(
|
|
363
|
+
self.assertEqual( unique_hash(datetime.timedelta( seconds=0 ) ), empty)
|
|
364
|
+
self.assertEqual( unique_hash(datetime.timedelta( days=0, seconds=0 ) ), empty)
|
|
365
|
+
self.assertEqual( unique_hash(datetime.timedelta( days=0, seconds=0, microseconds=0 ) ), empty)
|
|
366
|
+
self.assertEqual( unique_hash(datetime.timedelta( days=0 ) ), empty)
|
|
354
367
|
|
|
355
368
|
|
|
356
|
-
hash1 =
|
|
369
|
+
hash1 = unique_hash(datetime.timedelta( days=2, seconds=2+60*3+60*60*4, microseconds=1 ))
|
|
357
370
|
self.assertEqual( hash1, "8fd3e750ef3e59c2526070d6ccdc3e56") # (1)
|
|
358
|
-
self.assertEqual(
|
|
359
|
-
hash2 =
|
|
371
|
+
self.assertEqual( unique_hash(datetime.timedelta( days=0, seconds=2+60*3+60*60*4+2*24*60*60, microseconds=1 )), hash1 )
|
|
372
|
+
hash2 = unique_hash(datetime.timedelta( days=2, seconds=2+60*3+60*60*4, microseconds=0 ))
|
|
360
373
|
self.assertEqual( hash2, "35fcb34c6f2e3ff5f0c58e6912916990") # !=(1)
|
|
361
374
|
self.assertNotEqual( hash2, hash1 )
|
|
362
375
|
|
|
363
|
-
hash1 =
|
|
364
|
-
hash2 =
|
|
376
|
+
hash1 = unique_hash(datetime.timedelta( seconds=0, microseconds=1 ))
|
|
377
|
+
hash2 = unique_hash(datetime.timedelta( seconds=0, microseconds=-1 ))
|
|
365
378
|
self.assertEqual( hash1, "8b56e0808aad40a2722eadd13279e619")
|
|
366
379
|
self.assertEqual( hash2, "5a7f33307048636c4071967f95c40a85")
|
|
367
380
|
self.assertNotEqual( hash2, hash1 )
|
|
368
381
|
|
|
369
|
-
self.assertEqual(
|
|
370
|
-
self.assertEqual(
|
|
371
|
-
hash1 =
|
|
382
|
+
self.assertEqual( unique_hash( pd.DataFrame({'a':[1,2,3],'b':[10,20,30],'c':[100,200,300]}) ), "6825de2c38cab22de057211b1ad01ce8")
|
|
383
|
+
self.assertEqual( unique_hash( pd.DataFrame({'a':[1,2,3],'b':[10,20,30],'c':[100,200,300]}, index=[1,2,3]) ), "d8f7b3a49efe9c2961e54b8feb8f1eae")
|
|
384
|
+
hash1 = unique_hash( pd.DataFrame({'a':[1.,2.,3.],'b':[10.,20.,30.],'c':[100.,200.,300.]}, index=[1,2,3]) )
|
|
372
385
|
self.assertEqual( hash1, "13c5e3d147fcca03fcb1de6b6b1bcef0") # (1)
|
|
373
386
|
|
|
374
387
|
df = pd.DataFrame({'a':[1,2,3],'b':[10,20,30],'c':[100,200,300]}, index=[1,2,3], dtype=np.float64)
|
|
375
|
-
hash2 =
|
|
388
|
+
hash2 = unique_hash( df )
|
|
376
389
|
self.assertEqual(hash2, hash1)
|
|
377
390
|
df.attrs["test"] = 1
|
|
378
|
-
hash2 =
|
|
391
|
+
hash2 = unique_hash( df )
|
|
379
392
|
self.assertEqual( hash2, "c038dd30487f158bd8ff638941883e8b") # != (1)
|
|
380
393
|
self.assertNotEqual( hash2, hash1 )
|
|
381
394
|
del df.attrs["test"]
|
|
382
|
-
hash2 =
|
|
395
|
+
hash2 = unique_hash( df )
|
|
383
396
|
self.assertEqual( hash2, hash1) # == (1)
|
|
384
397
|
|
|
385
398
|
np.random.seed( 12312 )
|
|
386
399
|
a = np.exp( np.random.normal( size=(20,10) ).astype( np.float64 ) )
|
|
387
400
|
b = a.astype(np.float32, copy=True)
|
|
388
401
|
c = a.astype(np.float16, copy=True)
|
|
389
|
-
self.assertEqual(
|
|
390
|
-
flat =
|
|
402
|
+
self.assertEqual( unique_hash( a ), "1bac6e6c06b9ed1603670cb6895c1aaa")
|
|
403
|
+
flat = unique_hash( a.flatten() )
|
|
391
404
|
self.assertEqual( flat, "a002ff5a0d035f6dc30c8a366b5cdff3") # (1)
|
|
392
|
-
self.assertEqual(
|
|
393
|
-
self.assertEqual(
|
|
405
|
+
self.assertEqual( unique_hash( b ), "4dcc1a611fd718e957ef8e6bcff7a326")
|
|
406
|
+
self.assertEqual( unique_hash( c ), "e5a2889b6aafe33389890259e73407a5")
|
|
394
407
|
|
|
395
408
|
np.random.seed( 12312 )
|
|
396
409
|
a2 = np.exp( np.random.normal( size=(20*10,) ).astype( np.float64 ) )
|
|
397
|
-
self.assertEqual(
|
|
410
|
+
self.assertEqual( unique_hash( a2 ), flat ) # == (1)
|
|
398
411
|
|
|
399
412
|
# named
|
|
400
413
|
# -----
|
|
401
414
|
|
|
402
|
-
namedUniqueHash32_8 =
|
|
403
|
-
filenamedUniqueHash32_8_1 =
|
|
415
|
+
namedUniqueHash32_8 = NamedUniqueHash( max_length=32, id_length=8, parse_underscore="protected" )
|
|
416
|
+
filenamedUniqueHash32_8_1 = NamedUniqueHash( max_length=32, id_length=8, parse_underscore="protected", filename_by=DEF_FILE_NAME_MAP )
|
|
404
417
|
|
|
405
418
|
o1 = Object()
|
|
406
419
|
o2 = Object()
|
|
@@ -411,22 +424,22 @@ class UtilTest(unittest.TestCase):
|
|
|
411
424
|
|
|
412
425
|
hash1 = namedUniqueHash32_8( "object:", o1 )
|
|
413
426
|
hash1f1 = filenamedUniqueHash32_8_1( "object:", o1 )
|
|
414
|
-
self.assertEqual( hash1, "object:
|
|
427
|
+
self.assertEqual( hash1, "object: 70a87aad" )
|
|
415
428
|
self.assertNotEqual( namedUniqueHash32_8( "object;", o1 ), hash1 ) # <-- no filename translation
|
|
416
429
|
|
|
417
|
-
self.assertEqual( hash1f1, "object;
|
|
430
|
+
self.assertEqual( hash1f1, "object; 77c68e92" )
|
|
418
431
|
self.assertEqual( namedUniqueHash32_8( "object;", o1 ), hash1f1 ) # <-- with filename translation: ':' --> ';'
|
|
419
432
|
self.assertNotEqual( namedUniqueHash32_8( "object;", o1 ), hash1 ) # <-- filename translation
|
|
420
433
|
|
|
421
434
|
hashprot = namedUniqueHash32_8( "object:", o2 )
|
|
422
|
-
self.assertEqual( hashprot, "object:
|
|
435
|
+
self.assertEqual( hashprot, "object: fd1f4e66" )
|
|
423
436
|
self.assertEqual( namedUniqueHash32_8( "object:", o3 ), hashprot )
|
|
424
437
|
|
|
425
438
|
# __unique_hash__
|
|
426
439
|
# ----------------
|
|
427
440
|
|
|
428
441
|
class A(object):
|
|
429
|
-
""" No ID. Because members are protected
|
|
442
|
+
""" No ID. Because members are protected by default this object is hashed as "empty" """
|
|
430
443
|
def __init__(self, seed = 12312, size = (10,) ):
|
|
431
444
|
np.random.seed( seed )
|
|
432
445
|
self._seed = seed
|
|
@@ -440,23 +453,25 @@ class UtilTest(unittest.TestCase):
|
|
|
440
453
|
""" Compute unique ID at construction time """
|
|
441
454
|
def __init__(self, seed = 12312, size = (100,) ):
|
|
442
455
|
super().__init__(seed, size)
|
|
443
|
-
self.__unique_hash__ =
|
|
456
|
+
self.__unique_hash__ = unique_hash( self._seed, self._size )
|
|
444
457
|
|
|
445
458
|
class C(A):
|
|
446
|
-
""" Use the
|
|
447
|
-
def __unique_hash__( self,
|
|
448
|
-
return
|
|
459
|
+
""" Use the unique_hash object passed to this function to compute the hash """
|
|
460
|
+
def __unique_hash__( self, unique_hash, debug_trace ):
|
|
461
|
+
return unique_hash( self._seed, self._size, debug_trace=debug_trace )
|
|
449
462
|
|
|
450
463
|
class D(A):
|
|
451
464
|
""" Just return the members we care about """
|
|
452
|
-
def __unique_hash__( self,
|
|
465
|
+
def __unique_hash__( self, unique_hash, debug_trace ):
|
|
453
466
|
return ( self._seed, self._size )
|
|
454
467
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
468
|
+
empty = unique_hash( ('Test.test_uniqueHash.<locals>.A') )
|
|
469
|
+
hash1 = unique_hash( A() )
|
|
470
|
+
hash2 = unique_hash( B() )
|
|
471
|
+
hash3 = unique_hash( C() )
|
|
472
|
+
hash4 = unique_hash( D() )
|
|
473
|
+
self.assertEqual( empty, "653a05ac14649dbceebbd7f3d4a0b89f" )
|
|
474
|
+
self.assertEqual( hash1, empty )
|
|
460
475
|
self.assertEqual( hash2, "ae7cc6d56596eaa20dcd6aedc6e89d85" )
|
|
461
476
|
self.assertEqual( hash3, "5e387f9e86426319577d2121a4e1437b" )
|
|
462
477
|
self.assertEqual( hash4, "c9b449e95339458df155752acadbebb1" )
|