$61 GRAYBYTE WORDPRESS FILE MANAGER $23

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/dill/tests/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/dill/tests//test_recursive.py
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2019-2023 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/dill/blob/master/LICENSE

import dill
from functools import partial
import warnings


def copy(obj, byref=False, recurse=False):
    if byref:
        try:
            return dill.copy(obj, byref=byref, recurse=recurse)
        except Exception:
            pass
        else:
            raise AssertionError('Copy of %s with byref=True should have given a warning!' % (obj,))

        warnings.simplefilter('ignore')
        val = dill.copy(obj, byref=byref, recurse=recurse)
        warnings.simplefilter('error')
        return val
    else:
        return dill.copy(obj, byref=byref, recurse=recurse)


class obj1(object):
    def __init__(self):
        super(obj1, self).__init__()

class obj2(object):
    def __init__(self):
        super(obj2, self).__init__()

class obj3(object):
    super_ = super
    def __init__(self):
        obj3.super_(obj3, self).__init__()


def test_super():
    assert copy(obj1(), byref=True)
    assert copy(obj1(), byref=True, recurse=True)
    assert copy(obj1(), recurse=True)
    assert copy(obj1())

    assert copy(obj2(), byref=True)
    assert copy(obj2(), byref=True, recurse=True)
    assert copy(obj2(), recurse=True)
    assert copy(obj2())

    assert copy(obj3(), byref=True)
    assert copy(obj3(), byref=True, recurse=True)
    assert copy(obj3(), recurse=True)
    assert copy(obj3())


def get_trigger(model):
    pass

class Machine(object):
    def __init__(self):
        self.child = Model()
        self.trigger = partial(get_trigger, self)
        self.child.trigger = partial(get_trigger, self.child)

class Model(object):
    pass



def test_partial():
    assert copy(Machine(), byref=True)
    assert copy(Machine(), byref=True, recurse=True)
    assert copy(Machine(), recurse=True)
    assert copy(Machine())


class Machine2(object):
    def __init__(self):
        self.go = partial(self.member, self)
    def member(self, model):
        pass


class SubMachine(Machine2):
    def __init__(self):
        super(SubMachine, self).__init__()


def test_partials():
    assert copy(SubMachine(), byref=True)
    assert copy(SubMachine(), byref=True, recurse=True)
    assert copy(SubMachine(), recurse=True)
    assert copy(SubMachine())


class obj4(object):
    def __init__(self):
        super(obj4, self).__init__()
        a = self
        class obj5(object):
            def __init__(self):
                super(obj5, self).__init__()
                self.a = a
        self.b = obj5()


def test_circular_reference():
    assert copy(obj4())
    obj4_copy = dill.loads(dill.dumps(obj4()))
    assert type(obj4_copy) is type(obj4_copy).__init__.__closure__[0].cell_contents
    assert type(obj4_copy.b) is type(obj4_copy.b).__init__.__closure__[0].cell_contents


def f():
    def g():
       return g
    return g


def test_function_cells():
    assert copy(f())


def fib(n):
    assert n >= 0
    if n <= 1:
        return n
    else:
        return fib(n-1) + fib(n-2)


def test_recursive_function():
    global fib
    fib2 = copy(fib, recurse=True)
    fib3 = copy(fib)
    fib4 = fib
    del fib
    assert fib2(5) == 5
    for _fib in (fib3, fib4):
        try:
            _fib(5)
        except Exception:
            # This is expected to fail because fib no longer exists
            pass
        else:
            raise AssertionError("Function fib shouldn't have been found")
    fib = fib4


def collection_function_recursion():
    d = {}
    def g():
        return d
    d['g'] = g
    return g


def test_collection_function_recursion():
    g = copy(collection_function_recursion())
    assert g()['g'] is g


if __name__ == '__main__':
    with warnings.catch_warnings():
        warnings.simplefilter('error')
        test_super()
        test_partial()
        test_partials()
        test_circular_reference()
        test_function_cells()
        test_recursive_function()
        test_collection_function_recursion()

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
14 Aug 2025 9.24 PM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
0.489 KB
17 Apr 2025 8.10 PM
root / root
0644
__main__.py
0.878 KB
17 Apr 2025 8.10 PM
root / root
0644
test_abc.py
3.748 KB
17 Apr 2025 8.10 PM
root / root
0644
test_check.py
1.363 KB
17 Apr 2025 8.10 PM
root / root
0644
test_classdef.py
6.992 KB
17 Apr 2025 8.10 PM
root / root
0644
test_dataclasses.py
0.869 KB
17 Apr 2025 8.10 PM
root / root
0644
test_detect.py
3.987 KB
17 Apr 2025 8.10 PM
root / root
0644
test_dictviews.py
1.306 KB
17 Apr 2025 8.10 PM
root / root
0644
test_diff.py
2.604 KB
17 Apr 2025 8.10 PM
root / root
0644
test_extendpickle.py
1.284 KB
17 Apr 2025 8.10 PM
root / root
0644
test_fglobals.py
1.637 KB
17 Apr 2025 8.10 PM
root / root
0644
test_file.py
13.26 KB
17 Apr 2025 8.10 PM
root / root
0644
test_functions.py
4.167 KB
17 Apr 2025 8.10 PM
root / root
0644
test_functors.py
0.908 KB
17 Apr 2025 8.10 PM
root / root
0644
test_logger.py
2.329 KB
17 Apr 2025 8.10 PM
root / root
0644
test_mixins.py
3.913 KB
17 Apr 2025 8.10 PM
root / root
0644
test_module.py
1.897 KB
17 Apr 2025 8.10 PM
root / root
0644
test_moduledict.py
1.154 KB
17 Apr 2025 8.10 PM
root / root
0644
test_nested.py
3.072 KB
17 Apr 2025 8.10 PM
root / root
0644
test_objects.py
1.791 KB
17 Apr 2025 8.10 PM
root / root
0644
test_properties.py
1.314 KB
17 Apr 2025 8.10 PM
root / root
0644
test_pycapsule.py
1.384 KB
17 Apr 2025 8.10 PM
root / root
0644
test_recursive.py
4.084 KB
17 Apr 2025 8.10 PM
root / root
0644
test_registered.py
1.536 KB
17 Apr 2025 8.10 PM
root / root
0644
test_restricted.py
0.765 KB
17 Apr 2025 8.10 PM
root / root
0644
test_selected.py
3.143 KB
17 Apr 2025 8.10 PM
root / root
0644
test_session.py
9.923 KB
17 Apr 2025 8.10 PM
root / root
0644
test_source.py
5.895 KB
17 Apr 2025 8.10 PM
root / root
0644
test_temp.py
2.558 KB
17 Apr 2025 8.10 PM
root / root
0644
test_weakref.py
1.564 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF