def test_region(self): fc = FileCreator(self.k_window_test_size, "window_test") half_size = fc.size // 2 rofs = align_to_mmap(4200, False) rfull = MapRegion(fc.path, 0, fc.size) rhalfofs = MapRegion(fc.path, rofs, fc.size) rhalfsize = MapRegion(fc.path, 0, half_size) # offsets assert rfull.ofs_begin() == 0 and rfull.size() == fc.size assert rfull.ofs_end() == fc.size # if this method works, it works always assert rhalfofs.ofs_begin() == rofs and rhalfofs.size() == fc.size - rofs assert rhalfsize.ofs_begin() == 0 and rhalfsize.size() == half_size assert rfull.includes_ofs(0) and rfull.includes_ofs(fc.size - 1) and rfull.includes_ofs(half_size) assert not rfull.includes_ofs(-1) and not rfull.includes_ofs(sys.maxsize) # with the values we have, this test only works on windows where an alignment # size of 4096 is assumed. # We only test on linux as it is inconsitent between the python versions # as they use different mapping techniques to circumvent the missing offset # argument of mmap. if sys.platform != 'win32': assert rhalfofs.includes_ofs(rofs) and not rhalfofs.includes_ofs(0) # END handle platforms # auto-refcount assert rfull.client_count() == 1 rfull2 = rfull assert rfull.client_count() == 1, "no auto-counting" # window constructor w = MapWindow.from_region(rfull) assert w.ofs == rfull.ofs_begin() and w.ofs_end() == rfull.ofs_end()
def test_region(self): fc = FileCreator(self.k_window_test_size, "window_test") half_size = fc.size // 2 rofs = align_to_mmap(4200, False) rfull = MapRegion(fc.path, 0, fc.size) rhalfofs = MapRegion(fc.path, rofs, fc.size) rhalfsize = MapRegion(fc.path, 0, half_size) # offsets assert rfull.ofs_begin() == 0 and rfull.size() == fc.size assert rfull.ofs_end() == fc.size # if this method works, it works always assert rhalfofs.ofs_begin() == rofs and rhalfofs.size() == fc.size - rofs assert rhalfsize.ofs_begin() == 0 and rhalfsize.size() == half_size assert rfull.includes_ofs(0) and rfull.includes_ofs(fc.size - 1) and rfull.includes_ofs(half_size) assert not rfull.includes_ofs(-1) and not rfull.includes_ofs(sys.maxsize) # auto-refcount assert rfull.client_count() == 1 rfull2 = rfull assert rfull.client_count() == 1, "no auto-counting" # window constructor w = MapWindow.from_region(rfull) assert w.ofs == rfull.ofs_begin() and w.ofs_end() == rfull.ofs_end()
def test_region(self): fc = FileCreator(self.k_window_test_size, "window_test") half_size = fc.size // 2 rofs = align_to_mmap(4200, False) rfull = MapRegion(fc.path, 0, fc.size) rhalfofs = MapRegion(fc.path, rofs, fc.size) rhalfsize = MapRegion(fc.path, 0, half_size) # offsets assert rfull.ofs_begin() == 0 and rfull.size() == fc.size assert rfull.ofs_end( ) == fc.size # if this method works, it works always assert rhalfofs.ofs_begin() == rofs and rhalfofs.size( ) == fc.size - rofs assert rhalfsize.ofs_begin() == 0 and rhalfsize.size() == half_size assert rfull.includes_ofs(0) and rfull.includes_ofs( fc.size - 1) and rfull.includes_ofs(half_size) assert not rfull.includes_ofs(-1) and not rfull.includes_ofs( sys.maxsize) # with the values we have, this test only works on windows where an alignment # size of 4096 is assumed. # We only test on linux as it is inconsitent between the python versions # as they use different mapping techniques to circumvent the missing offset # argument of mmap. if sys.platform != 'win32': assert rhalfofs.includes_ofs(rofs) and not rhalfofs.includes_ofs(0) # END handle platforms # auto-refcount assert rfull.client_count() == 1 rfull2 = rfull assert rfull.client_count() == 1, "no auto-counting" # window constructor w = MapWindow.from_region(rfull) assert w.ofs == rfull.ofs_begin() and w.ofs_end() == rfull.ofs_end()