Esempio n. 1
0
def test_setting():
    class Obj():
        pass
    obj = Obj()
    obj.myattr = 'old'
    with setting(obj, 'myattr', 'mid'):
        assert obj.myattr == 'mid'
        with setting(obj, 'myattr', 'new'):
            assert obj.myattr == 'new'
        assert obj.myattr == 'mid'
    assert obj.myattr == 'old'

    with setting(obj, 'otherattr', 'mid'):
        assert obj.otherattr == 'mid'
        with setting(obj, 'otherattr', 'new'):
            assert obj.otherattr == 'new'
            with setting(obj, 'anotherattr', 'value'):
                assert obj.anotherattr == 'value'
            assert not hasattr(obj, 'anotherattr')
        assert obj.otherattr == 'mid'
    assert not hasattr(obj, 'otherattr')
Esempio n. 2
0
def test_collection():
    with setting(config, 'GC_NBYTES_THRESHOLD', 8000):
        memory.garbage_collect()
        counter = 0
        for i in range(10):
            data = np.arange(100)
            counter += data.nbytes
            op = DiagonalOperator(data)
            op.delete()
            if i < 9:
                assert memory._gc_nbytes_counter == counter
        assert memory._gc_nbytes_counter == 0
Esempio n. 3
0
def test_setting():
    class Obj:
        pass

    obj = Obj()
    obj.myattr = "old"
    with setting(obj, "myattr", "mid"):
        assert obj.myattr == "mid"
        with setting(obj, "myattr", "new"):
            assert obj.myattr == "new"
        assert obj.myattr == "mid"
    assert obj.myattr == "old"

    with setting(obj, "otherattr", "mid"):
        assert obj.otherattr == "mid"
        with setting(obj, "otherattr", "new"):
            assert obj.otherattr == "new"
            with setting(obj, "anotherattr", "value"):
                assert obj.anotherattr == "value"
            assert not hasattr(obj, "anotherattr")
        assert obj.otherattr == "mid"
    assert not hasattr(obj, "otherattr")