@@ -24,13 +24,13 @@ def test_cursor(self):
24
24
ci = WindowCursor (man ) # invalid cursor
25
25
assert not ci .is_valid ()
26
26
assert not ci .is_associated ()
27
- assert ci .size () == 0 # this is cached, so we can query it in invalid state
27
+ self . assertEqual ( ci .size (), 0 ) # this is cached, so we can query it in invalid state
28
28
29
29
cv = man .make_cursor (fc .path )
30
30
assert not cv .is_valid () # no region mapped yet
31
31
assert cv .is_associated () # but it know where to map it from
32
- assert cv .file_size () == fc .size
33
- assert cv .path () == fc .path
32
+ self . assertEqual ( cv .file_size (), fc .size )
33
+ self . assertEqual ( cv .path (), fc .path )
34
34
35
35
# copy module
36
36
cio = copy (cv )
@@ -55,14 +55,14 @@ def test_memory_manager(self):
55
55
56
56
for man in (static_man , slide_man ):
57
57
with man :
58
- assert man .num_file_handles () == 0
59
- assert man .num_open_files () == 0
58
+ self . assertEqual ( man .num_file_handles (), 0 )
59
+ self . assertEqual ( man .num_open_files (), 0 )
60
60
winsize_cmp_val = 0
61
61
if isinstance (man , StaticWindowMapManager ):
62
62
winsize_cmp_val = - 1
63
63
# END handle window size
64
64
assert man .window_size () > winsize_cmp_val
65
- assert man .mapped_memory_size () == 0
65
+ self . assertEqual ( man .mapped_memory_size (), 0 )
66
66
assert man .max_mapped_memory_size () > 0
67
67
68
68
# collection doesn't raise in 'any' mode
@@ -71,7 +71,7 @@ def test_memory_manager(self):
71
71
man ._collect_lru_region (10 )
72
72
73
73
# doesn't fail if we over-allocate
74
- assert man ._collect_lru_region (sys .maxsize ) == 0
74
+ self . assertEqual ( man ._collect_lru_region (sys .maxsize ), 0 )
75
75
76
76
# use a region, verify most basic functionality
77
77
with FileCreator (self .k_window_test_size , "manager_test" ) as fc :
@@ -81,10 +81,10 @@ def test_memory_manager(self):
81
81
c = man .make_cursor (item )
82
82
assert c .path_or_fd () is item
83
83
assert c .use_region (10 , 10 ).is_valid ()
84
- assert c .ofs_begin () == 10
85
- assert c .size () == 10
84
+ self . assertEqual ( c .ofs_begin (), 10 )
85
+ self . assertEqual ( c .size (), 10 )
86
86
with open (fc .path , 'rb' ) as fp :
87
- assert c .buffer ()[:] == fp .read (20 )[10 :]
87
+ self . assertEqual ( c .buffer ()[:], fp .read (20 )[10 :])
88
88
89
89
if isinstance (item , int ):
90
90
self .assertRaises (ValueError , c .path )
@@ -108,73 +108,73 @@ def test_memman_operation(self):
108
108
for mtype , args in ((StaticWindowMapManager , (0 , fc .size // 3 , max_num_handles )),
109
109
(SlidingWindowMapManager , (fc .size // 100 , fc .size // 3 , max_num_handles )),):
110
110
for item in (fc .path , fd ):
111
- assert len (data ) == fc .size
111
+ self . assertEqual ( len (data ), fc .size )
112
112
113
113
# small windows, a reasonable max memory. Not too many regions at once
114
114
with mtype (window_size = args [0 ], max_memory_size = args [1 ], max_open_handles = args [2 ]) as man :
115
115
c = man .make_cursor (item )
116
116
117
117
# still empty (more about that is tested in test_memory_manager()
118
- assert man .num_open_files () == 0
119
- assert man .mapped_memory_size () == 0
118
+ self . assertEqual ( man .num_open_files (), 0 )
119
+ self . assertEqual ( man .mapped_memory_size (), 0 )
120
120
121
121
base_offset = 5000
122
122
# window size is 0 for static managers, hence size will be 0. We take that into consideration
123
123
size = man .window_size () // 2
124
124
assert c .use_region (base_offset , size ).is_valid ()
125
125
rr = c .region ()
126
- assert rr .client_count () == 2 # the manager and the cursor and us
126
+ self . assertEqual ( rr .client_count (), 2 ) # the manager and the cursor and us
127
127
128
- assert man .num_open_files () == 1
129
- assert man .num_file_handles () == 1
130
- assert man .mapped_memory_size () == rr .size ()
128
+ self . assertEqual ( man .num_open_files (), 1 )
129
+ self . assertEqual ( man .num_file_handles (), 1 )
130
+ self . assertEqual ( man .mapped_memory_size (), rr .size () )
131
131
132
- # assert c.size() == size # the cursor may overallocate in its static version
133
- assert c .ofs_begin () == base_offset
134
- assert rr .ofs_begin () == 0 # it was aligned and expanded
132
+ # self.assertEqual( c.size(), size # the cursor may overallocate in its static version)
133
+ self . assertEqual ( c .ofs_begin (), base_offset )
134
+ self . assertEqual ( rr .ofs_begin (), 0 ) # it was aligned and expanded
135
135
if man .window_size ():
136
136
# but isn't larger than the max window (aligned)
137
- assert rr .size () == align_to_mmap (man .window_size (), True )
137
+ self . assertEqual ( rr .size (), align_to_mmap (man .window_size (), True ) )
138
138
else :
139
- assert rr .size () == fc .size
139
+ self . assertEqual ( rr .size (), fc .size )
140
140
# END ignore static managers which dont use windows and are aligned to file boundaries
141
141
142
- assert c .buffer ()[:] == data [base_offset :base_offset + (size or c .size ())]
142
+ self . assertEqual ( c .buffer ()[:], data [base_offset :base_offset + (size or c .size ())])
143
143
144
144
# obtain second window, which spans the first part of the file - it is a still the same window
145
145
nsize = (size or fc .size ) - 10
146
146
assert c .use_region (0 , nsize ).is_valid ()
147
- assert c .region () == rr
148
- assert man .num_file_handles () == 1
149
- assert c .size () == nsize
150
- assert c .ofs_begin () == 0
151
- assert c .buffer ()[:] == data [:nsize ]
147
+ self . assertEqual ( c .region (), rr )
148
+ self . assertEqual ( man .num_file_handles (), 1 )
149
+ self . assertEqual ( c .size (), nsize )
150
+ self . assertEqual ( c .ofs_begin (), 0 )
151
+ self . assertEqual ( c .buffer ()[:], data [:nsize ])
152
152
153
153
# map some part at the end, our requested size cannot be kept
154
154
overshoot = 4000
155
155
base_offset = fc .size - (size or c .size ()) + overshoot
156
156
assert c .use_region (base_offset , size ).is_valid ()
157
157
if man .window_size ():
158
- assert man .num_file_handles () == 2
158
+ self . assertEqual ( man .num_file_handles (), 2 )
159
159
assert c .size () < size
160
160
assert c .region () is not rr # old region is still available, but has not curser ref anymore
161
- assert rr .client_count () == 1 # only held by manager
161
+ self . assertEqual ( rr .client_count (), 1 ) # only held by manager
162
162
else :
163
163
assert c .size () < fc .size
164
164
# END ignore static managers which only have one handle per file
165
165
rr = c .region ()
166
- assert rr .client_count () == 2 # manager + cursor
166
+ self . assertEqual ( rr .client_count (), 2 ) # manager + cursor
167
167
assert rr .ofs_begin () < c .ofs_begin () # it should have extended itself to the left
168
168
assert rr .ofs_end () <= fc .size # it cannot be larger than the file
169
- assert c .buffer ()[:] == data [base_offset :base_offset + (size or c .size ())]
169
+ self . assertEqual ( c .buffer ()[:], data [base_offset :base_offset + (size or c .size ())])
170
170
171
171
# unising a region makes the cursor invalid
172
172
c .unuse_region ()
173
173
assert not c .is_valid ()
174
174
if man .window_size ():
175
175
# but doesn't change anything regarding the handle count - we cache it and only
176
176
# remove mapped regions if we have to
177
- assert man .num_file_handles () == 2
177
+ self . assertEqual ( man .num_file_handles (), 2 )
178
178
# END ignore this for static managers
179
179
180
180
# iterate through the windows, verify data contents
@@ -201,7 +201,7 @@ def test_memman_operation(self):
201
201
assert max_file_handles >= num_file_handles ()
202
202
assert c .use_region (base_offset , (size or c .size ())).is_valid ()
203
203
csize = c .size ()
204
- assert c .buffer ()[:] == data [base_offset :base_offset + csize ]
204
+ self . assertEqual ( c .buffer ()[:], data [base_offset :base_offset + csize ])
205
205
memory_read += csize
206
206
207
207
assert includes_ofs (base_offset )
@@ -222,7 +222,7 @@ def test_memman_operation(self):
222
222
# collection - it should be able to collect all
223
223
assert man .num_file_handles ()
224
224
assert man .collect ()
225
- assert man .num_file_handles () == 0
225
+ self . assertEqual ( man .num_file_handles (), 0 )
226
226
# END for each item
227
227
# END for each manager type
228
228
finally :
0 commit comments