Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfda3285

Browse files
committed
warnings fixes
1 parent1af4b42 commitfda3285

File tree

3 files changed

+68
-57
lines changed

3 files changed

+68
-57
lines changed

‎setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@
5252
"Programming Language :: Python :: 3.4",
5353
],
5454
long_description=long_description,
55+
tests_require=('nose','nosexcover'),
56+
test_suite='nose.collector'
5557
)

‎smmap/test/test_buf.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__importwith_statement,print_function
2+
13
from .libimportTestBase,FileCreator
24

35
fromsmmap.mmanimportSlidingWindowMapManager,StaticWindowMapManager
@@ -17,65 +19,66 @@
1719
static_man=StaticWindowMapManager()
1820

1921
classTestBuf(TestBase):
20-
22+
2123
deftest_basics(self):
2224
fc=FileCreator(self.k_window_test_size,"buffer_test")
23-
25+
2426
# invalid paths fail upon construction
2527
c=man_optimal.make_cursor(fc.path)
2628
self.assertRaises(ValueError,SlidingWindowMapBuffer,type(c)())# invalid cursor
2729
self.assertRaises(ValueError,SlidingWindowMapBuffer,c,fc.size)# offset too large
28-
30+
2931
buf=SlidingWindowMapBuffer()# can create uninitailized buffers
3032
assertbuf.cursor()isNone
31-
33+
3234
# can call end access any time
3335
buf.end_access()
3436
buf.end_access()
3537
assertlen(buf)==0
36-
38+
3739
# begin access can revive it, if the offset is suitable
3840
offset=100
3941
assertbuf.begin_access(c,fc.size)==False
4042
assertbuf.begin_access(c,offset)==True
4143
assertlen(buf)==fc.size-offset
4244
assertbuf.cursor().is_valid()
43-
45+
4446
# empty begin access keeps it valid on the same path, but alters the offset
4547
assertbuf.begin_access()==True
4648
assertlen(buf)==fc.size
4749
assertbuf.cursor().is_valid()
48-
50+
4951
# simple access
50-
data=open(fc.path,'rb').read()
52+
withopen(fc.path,'rb')asfp:
53+
data=fp.read()
5154
assertdata[offset]==buf[0]
5255
assertdata[offset:offset*2]==buf[0:offset]
53-
56+
5457
# negative indices, partial slices
5558
assertbuf[-1]==buf[len(buf)-1]
5659
assertbuf[-10:]==buf[len(buf)-10:len(buf)]
57-
60+
5861
# end access makes its cursor invalid
5962
buf.end_access()
6063
assertnotbuf.cursor().is_valid()
6164
assertbuf.cursor().is_associated()# but it remains associated
62-
65+
6366
# an empty begin access fixes it up again
6467
assertbuf.begin_access()==Trueandbuf.cursor().is_valid()
6568
del(buf)# ends access automatically
6669
del(c)
67-
70+
6871
assertman_optimal.num_file_handles()==1
69-
72+
7073
# PERFORMANCE
71-
# blast away with rnadom access and a full mapping - we don't want to
74+
# blast away with rnadom access and a full mapping - we don't want to
7275
# exagerate the manager's overhead, but measure the buffer overhead
73-
# We do it once with an optimal setting, and with a worse manager which
76+
# We do it once with an optimal setting, and with a worse manager which
7477
# will produce small mappings only !
7578
max_num_accesses=100
7679
fd=os.open(fc.path,os.O_RDONLY)
7780
foritemin (fc.path,fd):
78-
formanager,man_idin ( (man_optimal,'optimal'),
81+
formanager,man_idin ( (man_optimal,'optimal'),
7982
(man_worst_case,'worst case'),
8083
(static_man,'static optimal')):
8184
buf=SlidingWindowMapBuffer(manager.make_cursor(item))
@@ -84,7 +87,7 @@ def test_basics(self):
8487
num_accesses_left=max_num_accesses
8588
num_bytes=0
8689
fsize=fc.size
87-
90+
8891
st=time()
8992
buf.begin_access()
9093
whilenum_accesses_left:
@@ -102,16 +105,17 @@ def test_basics(self):
102105
num_bytes+=1
103106
#END handle mode
104107
# END handle num accesses
105-
108+
106109
buf.end_access()
107110
assertmanager.num_file_handles()
108111
assertmanager.collect()
109112
assertmanager.num_file_handles()==0
110113
elapsed=max(time()-st,0.001)# prevent zero division errors on windows
111114
mb=float(1000*1000)
112115
mode_str= (access_modeand"slice")or"single byte"
113-
sys.stderr.write("%s: Made %i random %s accesses to buffer created from %s reading a total of %f mb in %f s (%f mb/s)\n"
114-
% (man_id,max_num_accesses,mode_str,type(item),num_bytes/mb,elapsed, (num_bytes/mb)/elapsed))
116+
print("%s: Made %i random %s accesses to buffer created from %s reading a total of %f mb in %f s (%f mb/s)"
117+
% (man_id,max_num_accesses,mode_str,type(item),num_bytes/mb,elapsed, (num_bytes/mb)/elapsed),
118+
file=sys.stderr)
115119
# END handle access mode
116120
# END for each manager
117121
# END for each input

‎smmap/test/test_mman.py

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__importwith_statement,print_function
2+
13
from .libimportTestBase,FileCreator
24

35
fromsmmap.mmanimport*
@@ -12,43 +14,43 @@
1214
fromcopyimportcopy
1315

1416
classTestMMan(TestBase):
15-
17+
1618
deftest_cursor(self):
1719
fc=FileCreator(self.k_window_test_size,"cursor_test")
18-
20+
1921
man=SlidingWindowMapManager()
2022
ci=WindowCursor(man)# invalid cursor
2123
assertnotci.is_valid()
2224
assertnotci.is_associated()
2325
assertci.size()==0# this is cached, so we can query it in invalid state
24-
26+
2527
cv=man.make_cursor(fc.path)
2628
assertnotcv.is_valid()# no region mapped yet
2729
assertcv.is_associated()# but it know where to map it from
2830
assertcv.file_size()==fc.size
2931
assertcv.path()==fc.path
30-
32+
3133
# copy module
3234
cio=copy(cv)
3335
assertnotcio.is_valid()andcio.is_associated()
34-
36+
3537
# assign method
3638
assertnotci.is_associated()
3739
ci.assign(cv)
3840
assertnotci.is_valid()andci.is_associated()
39-
41+
4042
# unuse non-existing region is fine
4143
cv.unuse_region()
4244
cv.unuse_region()
43-
45+
4446
# destruction is fine (even multiple times)
4547
cv._destroy()
4648
WindowCursor(man)._destroy()
47-
49+
4850
deftest_memory_manager(self):
4951
slide_man=SlidingWindowMapManager()
5052
static_man=StaticWindowMapManager()
51-
53+
5254
formanin (static_man,slide_man):
5355
assertman.num_file_handles()==0
5456
assertman.num_open_files()==0
@@ -59,15 +61,15 @@ def test_memory_manager(self):
5961
assertman.window_size()>winsize_cmp_val
6062
assertman.mapped_memory_size()==0
6163
assertman.max_mapped_memory_size()>0
62-
64+
6365
# collection doesn't raise in 'any' mode
6466
man._collect_lru_region(0)
6567
# doesn't raise if we are within the limit
6668
man._collect_lru_region(10)
67-
68-
# doesn't fail if we overallocate
69+
70+
# doesn't fail if we overallocate
6971
assertman._collect_lru_region(sys.maxsize)==0
70-
72+
7173
# use a region, verify most basic functionality
7274
fc=FileCreator(self.k_window_test_size,"manager_test")
7375
fd=os.open(fc.path,os.O_RDONLY)
@@ -77,8 +79,9 @@ def test_memory_manager(self):
7779
assertc.use_region(10,10).is_valid()
7880
assertc.ofs_begin()==10
7981
assertc.size()==10
80-
assertc.buffer()[:]==open(fc.path,'rb').read(20)[10:]
81-
82+
withopen(fc.path,'rb')asfp:
83+
assertc.buffer()[:]==fp.read(20)[10:]
84+
8285
ifisinstance(item,int):
8386
self.assertRaises(ValueError,c.path)
8487
else:
@@ -87,38 +90,39 @@ def test_memory_manager(self):
8790
#END for each input
8891
os.close(fd)
8992
# END for each manager type
90-
93+
9194
deftest_memman_operation(self):
9295
# test more access, force it to actually unmap regions
9396
fc=FileCreator(self.k_window_test_size,"manager_operation_test")
94-
data=open(fc.path,'rb').read()
97+
withopen(fc.path,'rb')asfp:
98+
data=fp.read()
9599
fd=os.open(fc.path,os.O_RDONLY)
96100
max_num_handles=15
97-
#small_size =
101+
#small_size =
98102
formtype,argsin ( (StaticWindowMapManager, (0,fc.size//3,max_num_handles)),
99103
(SlidingWindowMapManager, (fc.size//100,fc.size//3,max_num_handles)),):
100104
foritemin (fc.path,fd):
101105
assertlen(data)==fc.size
102-
106+
103107
# small windows, a reasonable max memory. Not too many regions at once
104108
man=mtype(window_size=args[0],max_memory_size=args[1],max_open_handles=args[2])
105109
c=man.make_cursor(item)
106-
110+
107111
# still empty (more about that is tested in test_memory_manager()
108112
assertman.num_open_files()==0
109113
assertman.mapped_memory_size()==0
110-
114+
111115
base_offset=5000
112116
# window size is 0 for static managers, hence size will be 0. We take that into consideration
113117
size=man.window_size()//2
114118
assertc.use_region(base_offset,size).is_valid()
115119
rr=c.region_ref()
116120
assertrr().client_count()==2# the manager and the cursor and us
117-
121+
118122
assertman.num_open_files()==1
119123
assertman.num_file_handles()==1
120124
assertman.mapped_memory_size()==rr().size()
121-
125+
122126
#assert c.size() == size # the cursor may overallocate in its static version
123127
assertc.ofs_begin()==base_offset
124128
assertrr().ofs_begin()==0# it was aligned and expanded
@@ -127,9 +131,9 @@ def test_memman_operation(self):
127131
else:
128132
assertrr().size()==fc.size
129133
#END ignore static managers which dont use windows and are aligned to file boundaries
130-
131-
assertc.buffer()[:]==data[base_offset:base_offset+(sizeorc.size())]
132-
134+
135+
assertc.buffer()[:]==data[base_offset:base_offset+(sizeorc.size())]
136+
133137
# obtain second window, which spans the first part of the file - it is a still the same window
134138
nsize= (sizeorfc.size)-10
135139
assertc.use_region(0,nsize).is_valid()
@@ -138,7 +142,7 @@ def test_memman_operation(self):
138142
assertc.size()==nsize
139143
assertc.ofs_begin()==0
140144
assertc.buffer()[:]==data[:nsize]
141-
145+
142146
# map some part at the end, our requested size cannot be kept
143147
overshoot=4000
144148
base_offset=fc.size- (sizeorc.size())+overshoot
@@ -156,23 +160,23 @@ def test_memman_operation(self):
156160
assertrr().ofs_begin()<c.ofs_begin()# it should have extended itself to the left
157161
assertrr().ofs_end()<=fc.size# it cannot be larger than the file
158162
assertc.buffer()[:]==data[base_offset:base_offset+(sizeorc.size())]
159-
163+
160164
# unising a region makes the cursor invalid
161165
c.unuse_region()
162166
assertnotc.is_valid()
163167
ifman.window_size():
164-
# but doesn't change anything regarding the handle count - we cache it and only
168+
# but doesn't change anything regarding the handle count - we cache it and only
165169
# remove mapped regions if we have to
166170
assertman.num_file_handles()==2
167171
#END ignore this for static managers
168-
172+
169173
# iterate through the windows, verify data contents
170174
# this will trigger map collection after a while
171175
max_random_accesses=5000
172176
num_random_accesses=max_random_accesses
173177
memory_read=0
174178
st=time()
175-
179+
176180
# cache everything to get some more performance
177181
includes_ofs=c.includes_ofs
178182
max_mapped_memory_size=man.max_mapped_memory_size()
@@ -182,7 +186,7 @@ def test_memman_operation(self):
182186
whilenum_random_accesses:
183187
num_random_accesses-=1
184188
base_offset=randint(0,fc.size-1)
185-
189+
186190
# precondition
187191
ifman.window_size():
188192
assertmax_mapped_memory_size>=mapped_memory_size()
@@ -192,19 +196,20 @@ def test_memman_operation(self):
192196
csize=c.size()
193197
assertc.buffer()[:]==data[base_offset:base_offset+csize]
194198
memory_read+=csize
195-
199+
196200
assertincludes_ofs(base_offset)
197201
assertincludes_ofs(base_offset+csize-1)
198202
assertnotincludes_ofs(base_offset+csize)
199203
# END while we should do an access
200204
elapsed=max(time()-st,0.001)# prevent zero divison errors on windows
201205
mb=float(1000*1000)
202-
sys.stderr.write("%s: Read %i mb of memory with %i random on cursor initialized with %s accesses in %fs (%f mb/s)\n"
203-
% (mtype,memory_read/mb,max_random_accesses,type(item),elapsed, (memory_read/mb)/elapsed))
204-
206+
print("%s: Read %i mb of memory with %i random on cursor initialized with %s accesses in %fs (%f mb/s)\n"
207+
% (mtype,memory_read/mb,max_random_accesses,type(item),elapsed, (memory_read/mb)/elapsed),
208+
file=sys.stderr)
209+
205210
# an offset as large as the size doesn't work !
206211
assertnotc.use_region(fc.size,size).is_valid()
207-
212+
208213
# collection - it should be able to collect all
209214
assertman.num_file_handles()
210215
assertman.collect()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp