Changeset 0b6b4b6 in trunk


Ignore:
Timestamp:
2020-09-22T12:36:39Z (4 years ago)
Author:
Chad Whitacre <chad@…>
Branches:
master
Children:
de48dff
Parents:
58c99d0
Message:

Port test_immutable to Python 3

Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/test/common.py

    r58c99d0 r0b6b4b6  
    782782
    783783
    784 TEST_DATA="\x02"*(Uploader.URI_LIT_SIZE_THRESHOLD+1)
     784TEST_DATA=b"\x02"*(Uploader.URI_LIT_SIZE_THRESHOLD+1)
    785785
    786786
     
    959959    if sharevernum == 1:
    960960        curval = struct.unpack(">L", data[0x0c+0x18:0x0c+0x18+4])[0]
    961         newval = random.randrange(0, max(1, (curval/hashutil.CRYPTO_VAL_SIZE)/2))*hashutil.CRYPTO_VAL_SIZE
     961        newval = random.randrange(0, max(1, (curval/hashutil.CRYPTO_VAL_SIZE)//2))*hashutil.CRYPTO_VAL_SIZE
    962962        newvalstr = struct.pack(">L", newval)
    963963        return data[:0x0c+0x18]+newvalstr+data[0x0c+0x18+4:]
    964964    else:
    965965        curval = struct.unpack(">Q", data[0x0c+0x2c:0x0c+0x2c+8])[0]
    966         newval = random.randrange(0, max(1, (curval/hashutil.CRYPTO_VAL_SIZE)/2))*hashutil.CRYPTO_VAL_SIZE
     966        newval = random.randrange(0, max(1, (curval/hashutil.CRYPTO_VAL_SIZE)//2))*hashutil.CRYPTO_VAL_SIZE
    967967        newvalstr = struct.pack(">Q", newval)
    968968        return data[:0x0c+0x2c]+newvalstr+data[0x0c+0x2c+8:]
  • TabularUnified src/allmydata/test/common_util.py

    r58c99d0 r0b6b4b6  
     1from __future__ import absolute_import
     2from __future__ import division
    13from __future__ import print_function
     4from __future__ import unicode_literals
     5
     6from future.utils import PY2, bord, bchr, binary_type
     7if PY2:
     8    from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min  # noqa: F401
     9
     10    # XXX this is a hack that makes some tests pass on Python3, remove in the future
     11    from ..scripts import runner
    212
    313import os
     
    1020from ..util.assertutil import precondition
    1121from allmydata.util.encodingutil import get_io_encoding
    12 from future.utils import PY2
    13 if PY2: # XXX this is a hack that makes some tests pass on Python3, remove
    14         # in the future
    15     from ..scripts import runner
    1622# Imported for backwards compatibility:
    1723from .common_py3 import (
     
    5864
    5965def insecurerandstr(n):
    60     return ''.join(map(chr, map(randrange, [0]*n, [256]*n)))
     66    return b''.join(map(bchr, map(randrange, [0]*n, [256]*n)))
    6167
    6268def flip_bit(good, which):
     69    # TODO Probs need to update with bchr/bord as with flip_one_bit, below.
    6370    # flip the low-order bit of good[which]
    6471    if which == -1:
     
    7178    """ flip one random bit of the string s, in a byte greater than or equal to offset and less
    7279    than offset+size. """
     80    assert isinstance(s, binary_type)
    7381    if size is None:
    7482        size=len(s)-offset
    7583    i = randrange(offset, offset+size)
    76     result = s[:i] + chr(ord(s[i])^(0x01<<randrange(0, 8))) + s[i+1:]
     84    result = s[:i] + bchr(bord(s[i])^(0x01<<randrange(0, 8))) + s[i+1:]
    7785    assert result != s, "Internal error -- flip_one_bit() produced the same string as its input: %s == %s" % (result, s)
    7886    return result
  • TabularUnified src/allmydata/test/test_immutable.py

    r58c99d0 r0b6b4b6  
     1"""
     2This module has been ported to Python 3.
     3"""
     4from __future__ import absolute_import
     5from __future__ import division
     6from __future__ import print_function
     7from __future__ import unicode_literals
     8
     9from future.utils import PY2
     10if PY2:
     11    from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min  # noqa: F401
    112
    213import random
     
    8091        # another share", then you lose.
    8192
    82         rcap = uri.CHKFileURI('a'*32, 'a'*32, 3, 99, 100)
     93        rcap = uri.CHKFileURI(b'a'*32, b'a'*32, 3, 99, 100)
    8394        vcap = rcap.get_verify_cap()
    8495
     
    89100            def __init__(self, buckets):
    90101                self.version = {
    91                     'http://allmydata.org/tahoe/protocols/storage/v1': {
    92                         "tolerates-immutable-read-overrun": True
     102                    b'http://allmydata.org/tahoe/protocols/storage/v1': {
     103                        b"tolerates-immutable-read-overrun": True
    93104                        }
    94105                    }
     
    127138        mockserver2 = MockServer({})
    128139        mockserver3 = MockServer({3: MockBuckets()})
    129         servers = [ NoNetworkServer("ms1", mockserver1),
    130                     NoNetworkServer("ms2", mockserver2),
    131                     NoNetworkServer("ms3", mockserver3), ]
     140        servers = [ NoNetworkServer(b"ms1", mockserver1),
     141                    NoNetworkServer(b"ms2", mockserver2),
     142                    NoNetworkServer(b"ms3", mockserver3), ]
    132143        mockstoragebroker = MockStorageBroker(servers)
    133144        mockdownloadstatus = MockDownloadStatus()
     
    156167        # set their own value for happy -- the default (7) breaks stuff.
    157168        c1.encoding_params['happy'] = 1
    158         d = c1.upload(Data(TEST_DATA, convergence=""))
     169        d = c1.upload(Data(TEST_DATA, convergence=b""))
    159170        def _after_upload(ur):
    160171            self.uri = ur.get_uri()
     
    177188
    178189    def _shuffled(self, num_shnums):
    179         shnums = range(10)
     190        shnums = list(range(10))
    180191        random.shuffle(shnums)
    181192        return shnums[:num_shnums]
  • TabularUnified src/allmydata/util/_python3.py

    r58c99d0 r0b6b4b6  
    8080    "allmydata.test.test_base62",
    8181    "allmydata.test.test_codec",
     82    "allmydata.test.test_common_util",
    8283    "allmydata.test.test_configutil",
    8384    "allmydata.test.test_connection_status",
     
    9293    "allmydata.test.test_hashutil",
    9394    "allmydata.test.test_humanreadable",
     95    "allmydata.test.test_immutable",
    9496    "allmydata.test.test_iputil",
    9597    "allmydata.test.test_log",
Note: See TracChangeset for help on using the changeset viewer.