Exemple #1
0
    def fun(test_instance):

        # If certain files are not found, we dont want to continue the test.
        # "infile" came from "glob" so we don't need to test that.
        # We could also skip the attachment of the unit-test alltogether,
        # but calling ``skipTest`` instead makes it more visible that
        # something was not exeuted and test-runners like pytest can report
        # on this.
        if not exists(outfile):
            test_instance.skipTest(
                'Expected output file %r not found!' % outfile)

        # "infile" is to "storable" file which we want to decode.
        data = deserializer(infile)
        assertion_function = test_instance.assertEqual
        try:
            with open(outfile) as fp:
                code = fp.read()
                compiled = compile(code, outfile, 'exec')
                expected_scope = {}
                exec(compiled, expected_scope)
                result_we_need = expected_scope['result']
                if 'is_equal' in expected_scope:
                    assertion_function = expected_scope['is_equal']
        except KeyError as exc:
            test_instance.skipTest(
                'File %r should define the variable "result"!' % outfile)
        except Exception as exc:
            test_instance.skipTest(
                'Unable to compile %r (%s)' % (outfile, exc))

        # Now we have proper data which we can compare in detail.
        assertion_function(
            data, result_we_need,
            'Deserialisation of %r did not equal the data '
            'given in %r' % (infile, outfile))
        try:
            serialized_data = storable.output.serialize(data)
            reserialized_data = storable.thaw(serialized_data)
            if isinstance(data, dict):
                storable.thaw(storable.output.modify_hash(serialized_data, 'fooobar_keyy', 'xy'))
                storable.thaw(storable.output.modify_hash(serialized_data, 'abc', 45.12))
        except RuntimeError as err:
            if 'recursion' in err.args[0].lower()\
               or repr(err).startswith('Recursion'):  # for python3.5+
                reserialized_data = None
            else:
                raise
        if reserialized_data is not None:
            assertion_function(
                data, reserialized_data,
                'Serialization of %r did not equal the data '
                'given in %r' % (data, reserialized_data))
def run():
    with open("tests/resources/x86_64-linux/2.18/025_complex06_2.18_x86_64-linux_nfreeze.storable", "rb") as fh:
        small_data_nfreeze = fh.read()

    with open("tests/resources/x86_64-linux/2.18/025_complex06_2.18_x86_64-linux_freeze.storable", "rb") as fh:
        small_data_freeze = fh.read()

    with open("tests/large_simple01_nfreeze.storable", "rb") as fh:
        large_data_nfreeze = fh.read()

    with open("tests/large_simple01_freeze.storable", "rb") as fh:
        large_data_freeze = fh.read()

    timethese(100, {
        'small_nfreeze': lambda: storable.thaw(small_data_nfreeze),
        'small_freeze': lambda: storable.thaw(small_data_freeze),
        'large_nfreeze': lambda: storable.thaw(large_data_nfreeze),
        'large_freeze': lambda: storable.thaw(large_data_freeze)
    })
Exemple #3
0
def mythaw(infile):
    #print('reading from infile:'+infile)
    infh = open(infile, 'rb')
    data = infh.read()
    infh.close()

    # thaw() it
    try:
        data = storable.thaw(data)
    except Exception,e:
        traceback.print_exc(e)
def run():
    fh = open("t/resources/x86_64-linux/2.18/050_complex06_2.18_x86_64-linux_nfreeze.storable", "rb")
    small_data_nfreeze = fh.read()
    fh.close()

    fh = open("t/resources/x86_64-linux/2.18/049_complex06_2.18_x86_64-linux_freeze.storable", "rb")
    small_data_freeze = fh.read()
    fh.close()

    fh = open("t/large_simple01_nfreeze.storable", "rb")
    large_data_nfreeze = fh.read()
    fh.close()

    fh = open("t/large_simple01_freeze.storable", "rb")
    large_data_freeze = fh.read()
    fh.close()

    timethese(100, {
        'small_nfreeze' : lambda :storable.thaw(small_data_nfreeze),
        'small_freeze'  : lambda :storable.thaw(small_data_freeze ),
        'large_nfreeze' : lambda :storable.thaw(large_data_nfreeze),
        'large_freeze'  : lambda :storable.thaw(large_data_freeze )
    })
def run():
    with open(
            "tests/resources/x86_64-linux/2.18/025_complex06_2.18_x86_64-linux_nfreeze.storable",
            "rb") as fh:
        small_data_nfreeze = fh.read()

    with open(
            "tests/resources/x86_64-linux/2.18/025_complex06_2.18_x86_64-linux_freeze.storable",
            "rb") as fh:
        small_data_freeze = fh.read()

    with open("tests/large_simple01_nfreeze.storable", "rb") as fh:
        large_data_nfreeze = fh.read()

    with open("tests/large_simple01_freeze.storable", "rb") as fh:
        large_data_freeze = fh.read()

    timethese(
        100, {
            'small_nfreeze': lambda: storable.thaw(small_data_nfreeze),
            'small_freeze': lambda: storable.thaw(small_data_freeze),
            'large_nfreeze': lambda: storable.thaw(large_data_nfreeze),
            'large_freeze': lambda: storable.thaw(large_data_freeze)
        })
Exemple #6
0
 def loads(data):
     return storable.thaw(data)
Exemple #7
0
def mythaw(infile):
    infh = open(infile, 'rb')
    data = infh.read()
    infh.close()
    data = storable.thaw(data)
    return data
Exemple #8
0
 def loads(self, obj):
     return thaw(obj)
Exemple #9
0
 def load(self):
     return thaw(self.fd.read())
Exemple #10
0
    def read(self, key):
        raw_data = self.connection.get(key)

        print(type(raw_data))

        return storable.thaw(raw_data)
Exemple #11
0
 def loads(self, obj):
     return thaw(obj)
Exemple #12
0
 def load(self):
     return thaw(self.fd.read())